module JustimmoClient::V1::EmployeeInterface

Public employee query interface

Public Instance Methods

detail(id) click to toggle source

@return [Employee]

# File lib/justimmo_client/api/v1/interfaces/employee_interface.rb, line 29
def detail(id)
  with_cache cache_key("employee/detail", id: id),
    on_hit: ->(cached) do
      representer(:employee, :json).new(model(:employee).new).from_json(cached)
    end,
    on_miss: -> do
      xml_response = request(:employee).detail(id)
      model = model(:employee).new
      represented = representer(:employee).new(model).from_xml(xml_response)
      new_cache = representer(:employee, :json).new(represented).to_json
      [represented, new_cache]
    end
rescue JustimmoClient::RetrievalFailed
  nil
end
ids() click to toggle source

@return [Array<Integer>]

# File lib/justimmo_client/api/v1/interfaces/employee_interface.rb, line 46
def ids
  with_cache cache_key("employee/ids"),
    on_hit: ->(cached) { ::JSON.parse(cached) },
    on_miss: -> do
      json_response = request(:employee).ids
      json_parsed = ::JSON.parse(json_response).map(&:to_i)
      [json_parsed, ::JSON.generate(json_parsed)]
    end
rescue JustimmoClient::RetrievalFailed
  []
end
list() click to toggle source

@return [Array<Employee>]

# File lib/justimmo_client/api/v1/interfaces/employee_interface.rb, line 12
def list
  with_cache cache_key("employee/list"),
    on_hit: ->(cached) do
      representer(:employee, :json).for_collection.new([]).from_json(cached)
    end,
    on_miss: -> do
      xml_response = request(:employee).list
      model = Struct.new(:employees).new
      represented = representer(:employee_list).new(model).from_xml(xml_response).employees
      new_cache = representer(:employee, :json).for_collection.new(represented).to_json
      [represented, new_cache]
    end
rescue JustimmoClient::RetrievalFailed
  []
end