Module: Arbetsformedlingen::API::SoklistaResult

Defined in:
lib/arbetsformedlingen/api/results/soklista_result.rb

Class Method Summary collapse

Class Method Details

.build(response, list_name: nil) ⇒ Values::SoklistaPage

Build API result object for “soklista”

Parameters:

  • response (API::Response)
  • list_name (String) (defaults to: nil)

    result list name

Returns:



12
13
14
# File 'lib/arbetsformedlingen/api/results/soklista_result.rb', line 12

def self.build(response, list_name: nil)
  build_page(response, list_name)
end

.build_page(response, list_name) ⇒ Object

private



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/arbetsformedlingen/api/results/soklista_result.rb', line 18

def self.build_page(response, list_name)
  response_data = response.json
  data = response_data.fetch('soklista', {})

  Values::SoklistaPage.new(
    list_name: data.fetch('listnamn', list_name),
    total_ads: data.fetch('totalt_antal_platsannonser', 0),
    total_vacancies: data.fetch('totalt_antal_ledigajobb', 0),
    raw_data: response_data,
    data: data.fetch('sokdata', []).map do |result|
      build_search_result(result)
    end,
    response: response
  )
end

.build_search_result(result) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/arbetsformedlingen/api/results/soklista_result.rb', line 34

def self.build_search_result(result)
  Values::SoklistaResult.new(
    id: result.fetch('id'),
    name: result.fetch('namn'),
    total_ads: result.fetch('antal_platsannonser'),
    total_vacancies: result.fetch('antal_ledigajobb')
  )
end