Class: EskomSePush::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/eskomsepush/client.rb

Overview

Main class for the EskomSePush API This class is used to interact with the EskomSePush API and provides methods to get the current status of the Eskom Loadshedding, get information about areas and topics, and get the remaining API Quota/Allowance for the day.

Instance Method Summary collapse

Constructor Details

#initialize(token, options = {}) ⇒ Client

Returns a new instance of Client.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/eskomsepush/client.rb', line 30

def initialize(token, options = {})
  raise EskomSePushError::InvalidTokenError, "Invalid token" if token.nil?

  @token = token
  @options = options
  @quota = {}

  begin
    @connection = Faraday.new("https://developer.sepush.co.za")
    @connection.headers["token"] = @token
  rescue Faraday::ConnectionFailed
    raise EskomSePushError::UnexpectedError
  end
end

Instance Method Details

#area_information(area_id = nil, _test = nil) ⇒ Object

Get the area information for a specific area

Parameters:

area_id::String

The areaID of the area you want to get information for

test::String

Whether you would like to use test data or not, valid options
are current and future


91
92
93
94
95
96
97
# File 'lib/eskomsepush/client.rb', line 91

def area_information(area_id = nil, _test = nil)
  raise EskomSePushError::BadRequestError if area_id.nil?

  url = "/business/2.0/area?id=#{area_id}" + (_test.nil? ? "" : "&test=#{_test}")
  response = @connection.get(url)
  handle_response(response)
end

#areas_nearby(lat = nil, long = nil) ⇒ Object

Get a list of all nearby areas

Parameters:

lat::String

The latitude of the area you want to get nearby areas for

long::String

The longitude of the area you want to get nearby areas for

Returns:

Response object from handle_response



109
110
111
112
113
114
# File 'lib/eskomsepush/client.rb', line 109

def areas_nearby(lat = nil, long = nil)
  raise EskomSePushError::BadRequestError if lat.nil? || long.nil?

  response = @connection.get("/business/2.0/areas_nearby?lat=#{lat}&long=#{long}")
  handle_response(response)
end

#areas_search(text = nil) ⇒ Object

Search for the areaID of a specific area

Parameters:

text

The name of the area you want to search for

Returns:

Response object from handle_response



75
76
77
78
79
80
81
# File 'lib/eskomsepush/client.rb', line 75

def areas_search(text = nil)
  raise EskomSePushError::BadRequestError if text.nil?

  response = @connection.get("/business/2.0/areas_search?text=#{text}")
  puts response
  handle_response(response)
end

#check_allowanceObject Also known as: quota

Method to get your remaining API Quota/Allowance

Parameters:

None

Returns:

OpenStruct object with the quota information



53
54
55
56
# File 'lib/eskomsepush/client.rb', line 53

def check_allowance
  response = @connection.get("/business/2.0/api_allowance")
  handle_response(response)
end

#statusObject

Method to get the current status of the Eskom Loadshedding

Parameters:

None



62
63
64
65
# File 'lib/eskomsepush/client.rb', line 62

def status
  response = @connection.get("/business/2.0/status")
  handle_response(response)
end

#topics_nearby(lat = nil, long = nil) ⇒ Object

Get a list of all nearby topics

Parameters:

lat::String

The latitude of the area you want to get nearby topics for

long::String

The longitude of the area you want to get nearby topics for

Returns:

Response object from handle_response



126
127
128
129
130
131
# File 'lib/eskomsepush/client.rb', line 126

def topics_nearby(lat = nil, long = nil)
  raise EskomSePushError::BadRequestError if lat.nil? || long.nil?

  response = @connection.get("/business/2.0/topics_nearby?lat=#{lat}&long=#{long}")
  handle_response(response)
end