Module: JustimmoClient::V1::EmployeeInterface

Extended by:
Utils, JustimmoInterface
Defined in:
lib/justimmo_client/api/v1/interfaces/employee_interface.rb

Overview

Public employee query interface

Class Method Summary collapse

Methods included from Utils

autoload_dir, translate

Methods included from JustimmoInterface

cache_key, with_cache

Methods included from API

#api, #interface, #model, #representer, #request, #versioned_api

Methods included from Logging

default_logger, #logger, rails_logger

Methods included from Caching

#cache, default_cache

Class Method Details

.detail(id) ⇒ Employee

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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

.idsArray<Integer>

Returns:

  • (Array<Integer>)


46
47
48
49
50
51
52
53
54
55
56
# 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

.listArray<Employee>

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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