class AltaBikes::City
Attributes
json_url[RW]
station_list[RW]
stations_root[RW]
updated_at[RW]
Public Class Methods
new(configuration = AltaBikes.configuration)
click to toggle source
# File lib/alta_bikes/city.rb, line 12 def initialize(configuration = AltaBikes.configuration) raise JsonURLRequired if configuration.json_url.nil? @json_url = configuration.json_url @stations_root = configuration.stations_root @station_list = [] end
Public Instance Methods
refresh_stations()
click to toggle source
# File lib/alta_bikes/city.rb, line 26 def refresh_stations @station_list = [] stations end
stations(id = nil)
click to toggle source
# File lib/alta_bikes/city.rb, line 19 def stations(id = nil) get_stations if station_list.empty? return station_list.select { |station| station.details[:id] == id }[0] if !id.nil? station_list end
Private Instance Methods
get_stations()
click to toggle source
# File lib/alta_bikes/city.rb, line 31 def get_stations @updated_at = Time.new parse_stations(rest_client.get.body) rescue SocketError raise StationListUnavailable end
parse_stations(raw)
click to toggle source
# File lib/alta_bikes/city.rb, line 39 def parse_stations(raw) station_hash = JSON.parse(raw)[stations_root] station_hash.each do |raw_station| @station_list << AltaBikes::Station.new(raw_station) end end
rest_client()
click to toggle source
# File lib/alta_bikes/city.rb, line 48 def rest_client return nil if json_url.nil? RestClient::Resource.new(json_url) end