Class: RubyRides::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ruby_rides/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
	if options[:client_id].nil? || options[:client_api_key].nil?
		raise ArgumentError.new ("A client_username and client_api_key must be present in the options hash.")
	end
	@options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/ruby_rides/client.rb', line 8

def options
  @options
end

Instance Method Details

#client_api_keyObject



21
22
23
# File 'lib/ruby_rides/client.rb', line 21

def client_api_key
	@options[:client_api_key]
end

#client_idObject



17
18
19
# File 'lib/ruby_rides/client.rb', line 17

def client_id
	@options[:client_id]
end

#station_dataObject



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_locationsObject



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