class Estated::Client
Public Class Methods
get_property(params, skip_cache: false)
click to toggle source
# File lib/estated/client.rb, line 9 def self.get_property(params, skip_cache: false) with_cache('/property', params, skip_cache: skip_cache) do query = params.merge(token: Estated.config.api_key) response = self.get('/property', query: query) if response.parsed_response.is_a?(Hash) json = response.parsed_response # Don't cache if there's no data [json, !!json['data']] else [{ 'response' => response }, false] end end end
with_cache(path, params, skip_cache:) { || ... }
click to toggle source
# File lib/estated/client.rb, line 25 def self.with_cache(path, params, skip_cache:) if !skip_cache && Estated.config.cache_enabled? json = RequestCache.read(path, params) return json if json end result, result_is_cacheable = yield if Estated.config.cache_enabled? && result_is_cacheable # Cache original request RequestCache.write(path, params, result) # Also cache fips/apn request format fips = result.dig('data', 'parcel', 'fips_code') apn = result.dig('data', 'parcel', 'apn_unformatted') if fips && apn RequestCache.write(path, { fips: fips, apn: apn }, result) end end result end