Class: Arbetsformedlingen::API::Client
- Inherits:
-
Object
- Object
- Arbetsformedlingen::API::Client
- Defined in:
- lib/arbetsformedlingen/api/client.rb
Overview
Main API client
Constant Summary collapse
- BASE_URL =
Base URL for platsannonser
'http://api.arbetsformedlingen.se/af/v0/platsannonser/'.freeze
Instance Attribute Summary collapse
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#ad(id:) ⇒ Values::Ad
Fetch ad from API (ad => annons).
-
#ads(**args) ⇒ Values::MatchningPage
Fetch ads from API (areas => landområde/värdsdel).
-
#areas ⇒ Values::SoklistaPage
Fetch areas from API (areas => landområde/värdsdel).
-
#counties ⇒ Values::SoklistaPage
Fetch counties from API (county => län).
-
#counties2 ⇒ Values::SoklistaPage
Fetch counties2 from API (county2 => län2).
-
#countries(area_id:) ⇒ Values::SoklistaPage
Fetch counties from API (countries => land).
-
#create_ad(packet) ⇒ Values::CreateAdPage
Post ad to API (ad => annons).
-
#initialize(locale: 'sv') ⇒ Client
constructor
Initialize client.
-
#municipalities(county_id: nil) ⇒ Values::SoklistaPage
Fetch municipalities from API (municipality => kommun).
-
#occupation(name:) ⇒ Values::SoklistaPage
Fetch occupation from API (occupation => yrkesnamn).
-
#occupational_fields ⇒ Values::SoklistaPage
Fetch occupational fields from API (occupational_fields => yrkesområde).
-
#occupational_group(occupational_field_id: nil) ⇒ Values::SoklistaPage
Fetch occupational group from API (occupational_group => yrkesgrupp).
-
#occupations(occupational_group_id: nil) ⇒ Values::SoklistaPage
Fetch occupations from API (occupation => yrkesnamn).
-
#version ⇒ String
Get version of API.
Constructor Details
Instance Attribute Details
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
23 24 25 |
# File 'lib/arbetsformedlingen/api/client.rb', line 23 def locale @locale end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
23 24 25 |
# File 'lib/arbetsformedlingen/api/client.rb', line 23 def request @request end |
Instance Method Details
#ad(id:) ⇒ Values::Ad
Fetch ad from API (ad => annons)
55 56 57 58 59 |
# File 'lib/arbetsformedlingen/api/client.rb', line 55 def ad(id:) response = request.get(id) AdResult.build(response) end |
#ads(**args) ⇒ Values::MatchningPage
Fetch ads from API (areas => landområde/värdsdel)
64 65 66 67 |
# File 'lib/arbetsformedlingen/api/client.rb', line 64 def ads(**args) client = MatchningClient.new(request: request) client.ads(**args) end |
#areas ⇒ Values::SoklistaPage
Fetch areas from API (areas => landområde/värdsdel)
74 75 76 77 78 |
# File 'lib/arbetsformedlingen/api/client.rb', line 74 def areas response = request.get('soklista/omrade') SoklistaResult.build(response, list_name: 'omrade') end |
#counties ⇒ Values::SoklistaPage
Fetch counties from API (county => län)
113 114 115 116 117 |
# File 'lib/arbetsformedlingen/api/client.rb', line 113 def counties response = request.get('soklista/lan') SoklistaResult.build(response, list_name: 'lan') end |
#counties2 ⇒ Values::SoklistaPage
Fetch counties2 from API (county2 => län2)
124 125 126 127 128 |
# File 'lib/arbetsformedlingen/api/client.rb', line 124 def counties2 response = request.get('soklista/lan2') SoklistaResult.build(response, list_name: 'lan2') end |
#countries(area_id:) ⇒ Values::SoklistaPage
Fetch counties from API (countries => land)
86 87 88 89 90 91 |
# File 'lib/arbetsformedlingen/api/client.rb', line 86 def countries(area_id:) query = { omradeid: area_id } response = request.get('soklista/land', query: query) SoklistaResult.build(response, list_name: 'land') end |
#create_ad(packet) ⇒ Values::CreateAdPage
Post ad to API (ad => annons)
44 45 46 47 |
# File 'lib/arbetsformedlingen/api/client.rb', line 44 def create_ad(packet) client = LedigtarbeteClient.new client.create_ad(packet) end |
#municipalities(county_id: nil) ⇒ Values::SoklistaPage
Fetch municipalities from API (municipality => kommun)
99 100 101 102 103 104 105 106 |
# File 'lib/arbetsformedlingen/api/client.rb', line 99 def municipalities(county_id: nil) # NOTE: Due to a quirck in the API the lanid-param # *must* be present though it *can* be nil query = { lanid: county_id } response = request.get('soklista/kommuner', query: query) SoklistaResult.build(response, list_name: 'kommuner') end |
#occupation(name:) ⇒ Values::SoklistaPage
Fetch occupation from API (occupation => yrkesnamn)
164 165 166 167 168 |
# File 'lib/arbetsformedlingen/api/client.rb', line 164 def occupation(name:) response = request.get("soklista/yrken/#{uri_escape(name)}") SoklistaResult.build(response, list_name: 'Yrken') end |
#occupational_fields ⇒ Values::SoklistaPage
Fetch occupational fields from API (occupational_fields => yrkesområde)
135 136 137 138 139 |
# File 'lib/arbetsformedlingen/api/client.rb', line 135 def occupational_fields response = request.get('soklista/yrkesomraden') SoklistaResult.build(response, list_name: 'yrkesomraden') end |
#occupational_group(occupational_field_id: nil) ⇒ Values::SoklistaPage
Fetch occupational group from API (occupational_group => yrkesgrupp)
149 150 151 152 153 154 155 156 |
# File 'lib/arbetsformedlingen/api/client.rb', line 149 def occupational_group(occupational_field_id: nil) # NOTE: Due to a quirck in the API the yrkesomradeid-param # *must* be present though it *can* be nil query = { yrkesomradeid: occupational_field_id } response = request.get('soklista/yrkesgrupper', query: query) SoklistaResult.build(response, list_name: 'yrkesgrupper') end |
#occupations(occupational_group_id: nil) ⇒ Values::SoklistaPage
Fetch occupations from API (occupation => yrkesnamn)
178 179 180 181 182 183 184 185 |
# File 'lib/arbetsformedlingen/api/client.rb', line 178 def occupations(occupational_group_id: nil) # NOTE: Due to a quirck in the API the yrkesgruppid-param # *must* be present though it *can* be nil query = { yrkesgruppid: occupational_group_id } response = request.get('soklista/yrken', query: query) SoklistaResult.build(response, list_name: 'yrken') end |
#version ⇒ String
Get version of API
35 36 37 |
# File 'lib/arbetsformedlingen/api/client.rb', line 35 def version request.get('version').body end |