Module: Arbetsformedlingen::API::AdResult
- Defined in:
- lib/arbetsformedlingen/api/results/ad_result.rb
Class Method Summary collapse
-
.build(response) ⇒ Values::Ad
Build API result object for ad result.
-
.build_application(data) ⇒ Object
:nodoc:.
-
.build_empty(response) ⇒ Object
:nodoc:.
-
.build_page(response) ⇒ Object
:nodoc:.
-
.build_postal(data) ⇒ Object
:nodoc:.
-
.build_requirements(data) ⇒ Object
:nodoc:.
-
.build_terms(data) ⇒ Object
:nodoc:.
-
.build_workplace(data) ⇒ Object
:nodoc:.
-
.build_workplace_contacts(data) ⇒ Object
:nodoc:.
Class Method Details
.build(response) ⇒ Values::Ad
Build API result object for ad result
11 12 13 14 15 |
# File 'lib/arbetsformedlingen/api/results/ad_result.rb', line 11 def self.build(response) return build_empty(response) unless response.success? build_page(response) end |
.build_application(data) ⇒ Object
:nodoc:
63 64 65 66 67 68 69 70 71 |
# File 'lib/arbetsformedlingen/api/results/ad_result.rb', line 63 def self.build_application(data) Values::Application.new( reference: data['referens'], application_url: data.fetch('webbplats', nil), email: data['epostadress'], last_application_at: data.fetch('sista_ansokningsdag', nil), application_comment: data.fetch('ovrigt_om_ansokan', nil) ) end |
.build_empty(response) ⇒ Object
:nodoc:
47 48 49 |
# File 'lib/arbetsformedlingen/api/results/ad_result.rb', line 47 def self.build_empty(response) Values::Ad.new(response: response) end |
.build_page(response) ⇒ Object
:nodoc:
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/arbetsformedlingen/api/results/ad_result.rb', line 20 def self.build_page(response) response_data = response.json data = response_data.fetch('platsannons') ad_data = data.fetch('annons') Values::Ad.new( id: ad_data.fetch('annonsid'), url: ad_data.fetch('platsannonsUrl'), title: ad_data.fetch('annonsrubrik'), body: ad_data.fetch('annonstext'), occupation: ad_data.fetch('yrkesbenamning'), occupation_id: ad_data.fetch('yrkesid'), published_at: ad_data.fetch('publiceraddatum'), total_vacancies: ad_data.fetch('antal_platser'), municipalities: ad_data.fetch('kommunnamn'), municipality_id: ad_data.fetch('kommunkod'), total_vacancies_with_visa: ad_data.fetch('antalplatserVisa', nil), employment_type: ad_data.fetch('anstallningstyp'), terms: build_terms(data.fetch('villkor')), application: build_application(data.fetch('ansokan')), workplace: build_workplace(data.fetch('arbetsplats')), requirements: build_requirements(data.fetch('krav')), response: response ) end |
.build_postal(data) ⇒ Object
:nodoc:
91 92 93 94 95 96 97 98 |
# File 'lib/arbetsformedlingen/api/results/ad_result.rb', line 91 def self.build_postal(data) Values::Postal.new( code: data.fetch('postnummer', nil), address: data.fetch('postadress', nil), city: data.fetch('postort', nil), country: data.fetch('postland', nil) ) end |
.build_requirements(data) ⇒ Object
:nodoc:
110 111 112 113 114 |
# File 'lib/arbetsformedlingen/api/results/ad_result.rb', line 110 def self.build_requirements(data) Values::Requirements.new( own_car: data.fetch('egenbil') ) end |
.build_terms(data) ⇒ Object
:nodoc:
52 53 54 55 56 57 58 59 60 |
# File 'lib/arbetsformedlingen/api/results/ad_result.rb', line 52 def self.build_terms(data) Values::Terms.new( duration: data.fetch('varaktighet', nil), working_hours: data.fetch('arbetstid', nil), working_hours_description: data.fetch('arbetstidvaraktighet', nil), salary_type: data.fetch('lonetyp'), salary_form: data.fetch('loneform', nil) ) end |
.build_workplace(data) ⇒ Object
:nodoc:
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/arbetsformedlingen/api/results/ad_result.rb', line 74 def self.build_workplace(data) Values::Workplace.new( name: data.fetch('arbetsplatsnamn'), postal: build_postal(data), country: data.fetch('land'), visit_address: data.fetch('besoksadress', nil), logotype_url: data.fetch('logotypurl', nil), website: data.fetch('hemsida', nil), contacts: ( data.dig('kontaktpersonlista', 'kontaktpersondata') || [] ).map do |contact_data| build_workplace_contacts(contact_data) end ) end |