Sha256: 0f4570a3744f16a9254686ee15f2c065fe2a61ebb629be5b93d36c480fd87282

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'httparty'
require 'pry'

module RubyRides
	class Client
		include HTTParty
		base_uri "http://hubwaydatachallenge.org/api/v1"
		attr_accessor :options

		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

		def client_id
			@options[:client_id]
		end

		def client_api_key
			@options[:client_api_key]
		end
    
		def station_data
			JSON.parse self.class.get("/station/?format=json&username=#{@options[:client_id]}&api_key=#{@options[:client_api_key]}").body
		end

		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

	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_rides-0.0.3 lib/ruby_rides/client.rb