Sha256: 0d9f161be2d655073d7cfe0026f7e73b02493f0d7afa0af47603b3dfef780e85

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'httparty'
require 'pry'

module RubyRides
	class Client
		include HTTParty

		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 HTTParty.get("http://hubwaydatachallenge.org/api/v1/station/?format=json&username=#{@options[:client_id]}&api_key=#{@options[:client_api_key]}").body
		end

		def station_geo_locations
			json = JSON.parse HTTParty.get("http://hubwaydatachallenge.org/api/v1/station/?format=json&username=#{@options[:client_id]}&api_key=#{@options[:client_api_key]}")
			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.2 lib/ruby_rides/client.rb