Class: ChargePoint::API
- Inherits:
-
Object
- Object
- ChargePoint::API
- Defined in:
- lib/chargepoint/api.rb
Constant Summary collapse
- AUTHENTICATED_METHODS =
TODO: automatically wrap these methods with authentication guard condition
[:get_charge_spots]
- @@authenticated =
nil
- @@agent =
Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' }
Class Method Summary collapse
- .agent ⇒ Object
-
.authenticate(params) ⇒ Object
TODO: automatically auth when needed and credentials available TODO: add method to see if authentication is still valid.
- .authenticated? ⇒ Boolean
- .get_charge_spots(latitude, longitude, search_radius = 0.25, options = {}) ⇒ Object
Class Method Details
.agent ⇒ Object
15 16 17 |
# File 'lib/chargepoint/api.rb', line 15 def self.agent @@agent end |
.authenticate(params) ⇒ Object
TODO: automatically auth when needed and credentials available TODO: add method to see if authentication is still valid
25 26 27 28 29 |
# File 'lib/chargepoint/api.rb', line 25 def self.authenticate(params) response = JSON[agent.post('https://na.chargepoint.com/users/validate', params).content] @@authenticated = response['auth'] end |
.authenticated? ⇒ Boolean
19 20 21 |
# File 'lib/chargepoint/api.rb', line 19 def self.authenticated? !!@@authenticated end |
.get_charge_spots(latitude, longitude, search_radius = 0.25, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chargepoint/api.rb', line 31 def self.get_charge_spots(latitude, longitude, search_radius=0.25, ={}) raise 'method requires authentication' unless authenticated? params = params_with_filters() params.merge!(search_box_for(latitude, longitude, search_radius)) uri = dashboard_uri_for_method uri.query = URI.encode_www_form(params) JSON[agent.get(uri.to_s).content] end |