Class: Bikes

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/bikes.rb

Constant Summary collapse

STATIONS_URL =
'https://api.jcdecaux.com/vls/v1/stations'
CONTRACTS_URL =
'https://api.jcdecaux.com/vls/v1/contracts'

Instance Method Summary collapse

Constructor Details

#initialize(apikey, scheme) ⇒ Bikes

Returns a new instance of Bikes.



13
14
15
16
17
18
19
20
21
# 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

Instance Method Details

#contractsObject



27
28
29
# File 'lib/bikes.rb', line 27

def contracts
  @contracts_cache.contents
end

#contracts_fetchObject



31
32
33
# File 'lib/bikes.rb', line 31

def contracts_fetch
  invoke(CONTRACTS_URL)
end

#station(num) ⇒ Object



23
24
25
# File 'lib/bikes.rb', line 23

def station(num)
  invoke(STATIONS_URL + '/' + num.to_s, {contract: @scheme})
end

#stationsObject



35
36
37
# File 'lib/bikes.rb', line 35

def stations
  @stations_cache.contents
end

#stations_fetchObject



39
40
41
# File 'lib/bikes.rb', line 39

def stations_fetch
  invoke(STATIONS_URL, { contract: @scheme })
end