Class: Arbetsformedlingen::API::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/arbetsformedlingen/api/client.rb

Constant Summary collapse

BASE_URL =
'http://api.arbetsformedlingen.se/af/v0/platsannonser/'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale: 'sv') ⇒ Client

Returns a new instance of Client.



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

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.



20
21
22
# File 'lib/arbetsformedlingen/api/client.rb', line 20

def locale
  @locale
end

#requestObject (readonly)

Returns the value of attribute request.



20
21
22
# File 'lib/arbetsformedlingen/api/client.rb', line 20

def request
  @request
end

Instance Method Details

#ad(id:) ⇒ AdResult

Fetch ad from API (ad => annons)

Examples:

Get ad

client.ad(id: id)

Parameters:

  • id (String)

    Ad ID.

Returns:



50
51
52
53
54
# File 'lib/arbetsformedlingen/api/client.rb', line 50

def ad(id:)
  response = request.get(id)

  AdResult.build(response.json)
end

#ads(**args) ⇒ MatchningResult

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

Returns:

See Also:



60
61
62
63
# File 'lib/arbetsformedlingen/api/client.rb', line 60

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

#areasAdResult

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

Examples:

Get areas

client.areas

Returns:



69
70
71
72
73
# File 'lib/arbetsformedlingen/api/client.rb', line 69

def areas
  response = request.get('soklista/omrade')

  SoklistaResult.build(response.json)
end

#countiesAdResult

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

Examples:

Get counties

client.counties

Returns:



105
106
107
108
109
# File 'lib/arbetsformedlingen/api/client.rb', line 105

def counties
  response = request.get('soklista/lan')

  SoklistaResult.build(response.json)
end

#counties2AdResult

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

Examples:

Get counties2

client.counties2

Returns:



115
116
117
118
119
# File 'lib/arbetsformedlingen/api/client.rb', line 115

def counties2
  response = request.get('soklista/lan2')

  SoklistaResult.build(response.json)
end

#countries(area_id:) ⇒ AdResult

Fetch counties from API (countries => land)

Examples:

Get countries within area

client.countries(area_id: id)

Parameters:

  • area_id (String)

    Area ID.

Returns:



80
81
82
83
84
85
# File 'lib/arbetsformedlingen/api/client.rb', line 80

def countries(area_id:)
  query = { omradeid: area_id }
  response = request.get('soklista/land', query: query)

  SoklistaResult.build(response.json)
end

#create_ad(packet) ⇒ AdResult

Post ad to API (ad => annons)

Examples:

Post ad

client.ad(packet)

Parameters:

Returns:



40
41
42
43
# File 'lib/arbetsformedlingen/api/client.rb', line 40

def create_ad(packet)
  client = LedigtarbeteClient.new
  client.create_ad(packet)
end

#municipalities(county_id: nil) ⇒ AdResult

Fetch municipalities from API (municipality => kommun)

Examples:

Get counties

client.counties

Parameters:

  • county_id (String) (defaults to: nil)

    County ID.

Returns:



92
93
94
95
96
97
98
99
# File 'lib/arbetsformedlingen/api/client.rb', line 92

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.json)
end

#occupation(name:) ⇒ AdResult

Fetch occupation from API (occupation => yrkesnamn)

Examples:

Get occupation

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

Parameters:

  • name (String)

    Name of the occupation.

Returns:



152
153
154
155
156
# File 'lib/arbetsformedlingen/api/client.rb', line 152

def occupation(name:)
  response = request.get("soklista/yrken/#{URI.encode(name)}")

  SoklistaResult.build(response.json)
end

#occupational_fieldsAdResult

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

Examples:

Get occupational fields

client.occupational_field

Returns:



125
126
127
128
129
# File 'lib/arbetsformedlingen/api/client.rb', line 125

def occupational_fields
  response = request.get('soklista/yrkesomraden')

  SoklistaResult.build(response.json)
end

#occupational_group(occupational_field_id: nil) ⇒ AdResult

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:



138
139
140
141
142
143
144
145
# File 'lib/arbetsformedlingen/api/client.rb', line 138

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.json)
end

#occupations(occupational_group_id: nil) ⇒ AdResult

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:



165
166
167
168
169
170
171
172
# File 'lib/arbetsformedlingen/api/client.rb', line 165

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.json)
end

#versionString

Get version of API

Examples:

Get API version

client.version

Returns:

  • (String)

    the version of the API.



31
32
33
# File 'lib/arbetsformedlingen/api/client.rb', line 31

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