Sha256: 469edaaf26d8bbdd204561129c0b46ae1e564d9d3e72e1a4ad755e2df88a195b

Contents?: true

Size: 675 Bytes

Versions: 2

Compression:

Stored size: 675 Bytes

Contents

require 'booking_locations/version'
require 'booking_locations/api'
require 'booking_locations/slot'
require 'booking_locations/location'

require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/cache/null_store'

module BookingLocations
  DEFAULT_TTL = 2 * 60 * 60 # 2 hours

  mattr_writer :api
  mattr_writer :cache

  def self.api
    @@api ||= BookingLocations::Api.new
  end

  def self.cache
    @@cache ||= ActiveSupport::Cache::NullStore.new
  end

  def self.find(id, expires = DEFAULT_TTL)
    cache.fetch(id, expires_in: expires) do
      api.get(id) do |response_hash|
        Location.new(response_hash)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
booking_locations-0.10.0 lib/booking_locations.rb
booking_locations-0.9.1 lib/booking_locations.rb