Module: Arbetsformedlingen::API::MatchningResult
- Defined in:
- lib/arbetsformedlingen/api/results/matchning_result.rb
Class Method Summary collapse
-
.build(response) ⇒ Values::MatchningPage
Build API result object for matchning result.
- .build_ad_result(ad_data) ⇒ Object
-
.build_ad_results(data) ⇒ Object
private.
- .build_matchning_page(response) ⇒ Object
-
.empty_matchning_page(response) ⇒ Object
private.
Class Method Details
.build(response) ⇒ Values::MatchningPage
Build API result object for matchning result
11 12 13 14 15 |
# File 'lib/arbetsformedlingen/api/results/matchning_result.rb', line 11 def self.build(response) return empty_matchning_page(response) unless response.success? build_matchning_page(response) end |
.build_ad_result(ad_data) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/arbetsformedlingen/api/results/matchning_result.rb', line 60 def self.build_ad_result(ad_data) Values::MatchningAd.new( id: ad_data.fetch('annonsid'), title: ad_data.fetch('annonsrubrik'), occupation: ad_data.fetch('yrkesbenamning'), occupation_id: ad_data.fetch('yrkesbenamningId'), company: ad_data.fetch('arbetsplatsnamn'), municipalities: ad_data.fetch('kommunnamn'), municipality_id: ad_data.fetch('kommunkod'), published_at: ad_data.fetch('publiceraddatum'), last_application_at: ad_data.fetch('sista_ansokningsdag', nil), url: ad_data.fetch('annonsurl'), relevance: ad_data.fetch('relevans'), total_vacancies: ad_data.fetch('antalplatser'), total_vacancies_with_visa: ad_data.fetch('antalPlatserVisa', nil), duration_id: ad_data.fetch('varaktighetId', nil), counties: ad_data.fetch('lan'), country_id: ad_data.fetch('lanid'), employment_type: ad_data.fetch('anstallningstyp') ) end |
.build_ad_results(data) ⇒ Object
private
54 55 56 57 58 |
# File 'lib/arbetsformedlingen/api/results/matchning_result.rb', line 54 def self.build_ad_results(data) data.fetch('matchningdata', []).map do |ad_data| build_ad_result(ad_data) end end |
.build_matchning_page(response) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/arbetsformedlingen/api/results/matchning_result.rb', line 35 def self.build_matchning_page(response) response_data = response.json data = response_data.fetch('matchningslista') Values::MatchningPage.new( list_name: 'annonser', total_ads: data.fetch('antal_platsannonser'), total_ads_exact: data.fetch('antal_platsannonser_exakta'), total_ads_nearby: data.fetch('antal_platsannonser_narliggande'), total_vacancies_on_page: data.fetch('antal_platserTotal'), total_pages: data.fetch('antal_sidor'), raw_data: response_data, data: build_ad_results(data), response: response ) end |
.empty_matchning_page(response) ⇒ Object
private
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/arbetsformedlingen/api/results/matchning_result.rb', line 19 def self.empty_matchning_page(response) response_data = response.json Values::MatchningPage.new( list_name: 'annonser', total_ads: 0, total_ads_exact: 0, total_ads_nearby: 0, total_vacancies_on_page: 0, total_pages: 0, raw_data: response_data, data: [], response: response ) end |