class Citibikenyc::Api

Attributes

client[R]
feeds[R]
response[R]
station_information[R]
station_status[R]
system_alerts[R]
system_information[R]
system_regions[R]

Public Class Methods

new() click to toggle source
# File lib/citibikenyc/api.rb, line 14
def initialize()
  @client = Faraday.new(url: Constants[:service_name])
  @lang = "en"
  get_feeds
end

Public Instance Methods

get_feeds() click to toggle source
# File lib/citibikenyc/api.rb, line 20
def get_feeds
  @feeds = response_to_json("/gbfs/gbfs.json")[@lang]["feeds"].map { |feed| Feed.new( feed["name"], feed["url"] ) }
end
get_station_information() click to toggle source
# File lib/citibikenyc/api.rb, line 29
def get_station_information
  feed = @feeds.find{ |f| f.name == "station_information"}
  @station_information = response_to_json(feed.url)["stations"].map { |station_information| StationInformation.new(station_information)  }
end
get_station_status() click to toggle source
# File lib/citibikenyc/api.rb, line 24
def get_station_status
  feed = @feeds.find{ |f| f.name == "station_status"}
  @station_status = response_to_json(feed.url)["stations"].map { |station_status| StationStatus.new(station_status)  }
end
get_system_alerts() click to toggle source
# File lib/citibikenyc/api.rb, line 44
def get_system_alerts
  feed = @feeds.find{ |f| f.name == "system_alerts"}
  @system_alerts = response_to_json(feed.url)["alertsa"]
end
get_system_information() click to toggle source
# File lib/citibikenyc/api.rb, line 39
def get_system_information
  feed = @feeds.find{ |f| f.name == "station_information"}
  @system_information = response_to_json(feed.url)
end
get_system_regions() click to toggle source
# File lib/citibikenyc/api.rb, line 34
def get_system_regions
  feed = @feeds.find{ |f| f.name == "system_regions"}
  @system_regions = response_to_json(feed.url)["regions"].map { |station_status| Region.new(station_status)  }
end

Private Instance Methods

response_to_json(url) click to toggle source
# File lib/citibikenyc/api.rb, line 51
def response_to_json(url)
  @response = @client.get(url).body
  JSON.parse(@response)["data"]
end