class SgPostcode::Proxy

Attributes

cache_adapter[R]
service[R]

Public Class Methods

new(service, postcode, cache: true) click to toggle source
# File lib/sg_postcode/services/proxy.rb, line 5
def initialize(service, postcode, cache: true)
  @postcode = postcode

  case service
  when :Google
    @service = Google.new(postcode)
  end

  @cache_adapter = CacheAdapter.new(postcode) if cache
end

Public Instance Methods

request() click to toggle source
# File lib/sg_postcode/services/proxy.rb, line 16
def request
  return nil unless service

  if cache_adapter
    cache_adapter.fetch || cache_adapter.store(@postcode, service.request)
  else
    service.request
  end
end