Class: RubyRides::Client
- Inherits:
-
Object
- Object
- RubyRides::Client
- Includes:
- HTTParty
- Defined in:
- lib/ruby_rides/client.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #client_api_key ⇒ Object
- #client_id ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #station_data ⇒ Object
- #station_geo_locations ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 |
# File 'lib/ruby_rides/client.rb', line 10 def initialize(={}) if [:client_id].nil? || [:client_api_key].nil? raise ArgumentError.new ("A client_username and client_api_key must be present in the options hash.") end @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/ruby_rides/client.rb', line 8 def @options end |
Instance Method Details
#client_api_key ⇒ Object
21 22 23 |
# File 'lib/ruby_rides/client.rb', line 21 def client_api_key @options[:client_api_key] end |
#client_id ⇒ Object
17 18 19 |
# File 'lib/ruby_rides/client.rb', line 17 def client_id @options[:client_id] end |
#station_data ⇒ Object
25 26 27 |
# File 'lib/ruby_rides/client.rb', line 25 def station_data JSON.parse self.class.get("/station/?format=json&username=#{@options[:client_id]}&api_key=#{@options[:client_api_key]}").body end |
#station_geo_locations ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_rides/client.rb', line 29 def station_geo_locations json = JSON.parse self.class.get("/station/?format=json&username=#{@options[:client_id]}&api_key=#{@options[:client_api_key]}").body data = json['objects'] station_coordinates = {} data.each do |d| h = Hash["#{d['name']}", d['point']['coordinates']] station_coordinates.merge!(h) end station_coordinates end |