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