Class: Arbetsformedlingen::API::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(locale: 'sv') ⇒ Client

Initialize client



26
27
28
29
# File 'lib/arbetsformedlingen/api/client.rb', line 26

def initialize(locale: 'sv')
  @request = Request.new(base_url: BASE_URL, locale: locale)
  @locale = locale
end

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale.



23
24
25
# File 'lib/arbetsformedlingen/api/client.rb', line 23

def locale
  @locale
end

#requestObject (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)

Examples:

Get ad

client.ad(id: id)

Parameters:

  • id (String)

    Ad ID.

Returns:

See Also:



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)

Returns:

See Also:



64
65
66
67
# File 'lib/arbetsformedlingen/api/client.rb', line 64

def ads(**args)
  client = MatchningClient.new(request: request)
  client.ads(**args)
end

#areasValues::SoklistaPage

Fetch areas from API (areas => landområde/värdsdel)

Examples:

Get areas

client.areas

Returns:

See Also:



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

#countiesValues::SoklistaPage

Fetch counties from API (county => län)

Examples:

Get counties

client.counties

Returns:

See Also:



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

#counties2Values::SoklistaPage

Fetch counties2 from API (county2 => län2)

Examples:

Get counties2

client.counties2

Returns:

See Also:



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)

Examples:

Get countries within area

client.countries(area_id: id)

Parameters:

  • area_id (String)

    Area ID.

Returns:

See Also:



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)

Examples:

Post ad

client.ad(packet)

Parameters:

Returns:



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)

Examples:

Get counties

client.counties

Parameters:

  • county_id (String) (defaults to: nil)

    County ID.

Returns:

See Also:



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)

Examples:

Get occupation

client.occupation(name: 'Marknadskommunikatör')

Parameters:

  • name (String)

    Name of the occupation.

Returns:

See Also:



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_fieldsValues::SoklistaPage

Fetch occupational fields from API (occupational_fields => yrkesområde)

Examples:

Get occupational fields

client.occupational_field

Returns:

See Also:



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)

Examples:

Get all occupational group

client.occupational_group

Get occupational group within occupational field

client.occupational_group(occupational_field_id: id)

Parameters:

  • occupational_field_id (String) (defaults to: nil)

    Occupational field ID.

Returns:

See Also:



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)

Examples:

Get stats of available positions for all occupations

client.occupations

Get stats of available positions for some occupations

client.occupations(occupational_group_id: id)

Parameters:

  • occupational_group_id (String) (defaults to: nil)

    Occupational group ID.

Returns:

See Also:



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

#versionString

Get version of API

Examples:

Get API version

client.version

Returns:

  • (String)

    the version of the API.



35
36
37
# File 'lib/arbetsformedlingen/api/client.rb', line 35

def version
  request.get('version').body
end