Module: BookingLocations
- Defined in:
- lib/booking_locations.rb,
lib/booking_locations/api.rb,
lib/booking_locations/version.rb,
lib/booking_locations/location.rb,
lib/booking_locations/stub_api.rb
Defined Under Namespace
Classes: Api, Location, StubApi
Constant Summary
collapse
- DEFAULT_PREFIX =
'booking_locations:'.freeze
- DEFAULT_TTL =
2 * 60 * 60
- VERSION =
'0.23.0'.freeze
- KNOWN_LOCATION_IDS =
%w(
ac7112c3-e3cf-45cd-a8ff-9ba827b8e7ef
1a1ad00f-d967-448a-a4a6-772369fa5087
183080c6-642b-4b8f-96fd-891f5cd9f9c7
c165d25e-f27b-4ce9-b3d3-e7415ebaa93c
a77a031a-8037-4510-b1f7-63d4aab7b103
7f916cf6-d2bd-4bcc-90dc-594207c8b1f4
43fcab23-b01f-4805-a34d-e7edb77b65ce
fdf2fa41-b0b7-44ae-a992-4409490dc9fb
05dbf9e9-662b-4b10-ad85-70c38bd08d6d
13e12f95-f709-4536-b6ee-8d7a735ddf9f
ca857ea1-e51a-442d-937d-b7c720d91ecf
90bebb70-c4bb-4572-afb2-e4ede5ca38c9
b5920e4c-ac91-49c3-8923-3efd10292db2
).freeze
Class Method Summary
collapse
Class Method Details
.all ⇒ Object
31
32
33
34
35
|
# File 'lib/booking_locations.rb', line 31
def self.all
api.all.map do |location|
Location.new(location)
end
end
|
.api ⇒ Object
15
16
17
|
# File 'lib/booking_locations.rb', line 15
def self.api
@@api ||= BookingLocations::Api.new
end
|
.cache ⇒ Object
19
20
21
|
# File 'lib/booking_locations.rb', line 19
def self.cache
@@cache ||= ActiveSupport::Cache::NullStore.new
end
|
.cache_prefix(key) ⇒ Object
41
42
43
|
# File 'lib/booking_locations.rb', line 41
def self.cache_prefix(key)
DEFAULT_PREFIX.dup.concat(key)
end
|
.clear_cache ⇒ Object
37
38
39
|
# File 'lib/booking_locations.rb', line 37
def self.clear_cache
cache.delete_matched(cache_prefix('*'))
end
|
.find(id, expires = DEFAULT_TTL) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/booking_locations.rb', line 23
def self.find(id, expires = DEFAULT_TTL)
cache.fetch(cache_prefix(id), expires_in: expires) do
api.get(id) do |response_hash|
Location.new(response_hash)
end
end
end
|