class Bikes
Constants
- CONTRACTS_URL
- STATIONS_URL
Public Class Methods
new(apikey, scheme)
click to toggle source
# File lib/bikes.rb, line 13 def initialize(apikey, scheme) @api = apikey @scheme = scheme # Contracts refresh daily @contracts_cache = Cache.new(self, :contracts_fetch) # Full stations list refresh every 60 seconds @stations_cache = Cache.new(self, :stations_fetch, 60) end
Public Instance Methods
contracts()
click to toggle source
# File lib/bikes.rb, line 27 def contracts @contracts_cache.contents end
contracts_fetch()
click to toggle source
# File lib/bikes.rb, line 31 def contracts_fetch invoke(CONTRACTS_URL) end
station(num)
click to toggle source
# File lib/bikes.rb, line 23 def station(num) invoke(STATIONS_URL + '/' + num.to_s, {contract: @scheme}) end
stations()
click to toggle source
# File lib/bikes.rb, line 35 def stations @stations_cache.contents end
stations_fetch()
click to toggle source
# File lib/bikes.rb, line 39 def stations_fetch invoke(STATIONS_URL, { contract: @scheme }) end
Private Instance Methods
invoke(url, queryx = {})
click to toggle source
# File lib/bikes.rb, line 45 def invoke(url, queryx = {}) response = self.class.get(url, { query: { apiKey: @api}.merge(queryx)}) raise BikesOffline unless response.code == 200 por = JSON.parse(response.body) if (por.is_a? Array) por.map{|ob| Hashie::Mash.new(ob)} else Hashie::Mash.new(por) end end