class Arbetsformedlingen::API::Client

Main API client

Constants

BASE_URL

Base URL for platsannonser

Attributes

locale[R]
request[R]

Public Class Methods

new(locale: 'sv') click to toggle source

Initialize client

# File lib/arbetsformedlingen/api/client.rb, line 26
def initialize(locale: 'sv')
  @request = Request.new(base_url: BASE_URL, locale: locale)
  @locale = locale
end

Public Instance Methods

ad(id:) click to toggle source

Fetch ad from API (ad => annons) @return [Values::Ad] the result. @param id [String] Ad ID. @example Get ad

client.ad(id: id)

@see Values::Ad

# File lib/arbetsformedlingen/api/client.rb, line 55
def ad(id:)
  response = request.get(id)

  AdResult.build(response)
end
ads(**args) click to toggle source

Fetch ads from API (areas => landområde/värdsdel) @return [Values::MatchningPage] the result. @see Values::MatchningPage

# File lib/arbetsformedlingen/api/client.rb, line 64
def ads(**args)
  client = MatchningClient.new(request: request)
  client.ads(**args)
end
areas() click to toggle source

Fetch areas from API (areas => landområde/värdsdel) @return [Values::SoklistaPage] the result. @example Get areas

client.areas

@see Values::SoklistaPage

# File lib/arbetsformedlingen/api/client.rb, line 74
def areas
  response = request.get('soklista/omrade')

  SoklistaResult.build(response, list_name: 'omrade')
end
counties() click to toggle source

Fetch counties from API (county => län) @return [Values::SoklistaPage] the result. @example Get counties

client.counties

@see Values::SoklistaPage

# File lib/arbetsformedlingen/api/client.rb, line 113
def counties
  response = request.get('soklista/lan')

  SoklistaResult.build(response, list_name: 'lan')
end
counties2() click to toggle source

Fetch counties2 from API (county2 => län2) @return [Values::SoklistaPage] the result. @example Get counties2

client.counties2

@see Values::SoklistaPage

# 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:) click to toggle source

Fetch counties from API (countries => land) @return [Values::SoklistaPage] the result. @param area_id [String] Area ID. @example Get countries within area

client.countries(area_id: id)

@see Values::SoklistaPage

# 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) click to toggle source

Post ad to API (ad => annons) @return [Values::CreateAdPage] the result. @param [Arbetsformedlingen::Packet] packet @example Post ad

client.ad(packet)
# File lib/arbetsformedlingen/api/client.rb, line 44
def create_ad(packet)
  client = LedigtarbeteClient.new
  client.create_ad(packet)
end
municipalities(county_id: nil) click to toggle source

Fetch municipalities from API (municipality => kommun) @return [Values::SoklistaPage] the result. @param county_id [String] County ID. @example Get counties

client.counties

@see Values::SoklistaPage

# 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:) click to toggle source

Fetch occupation from API (occupation => yrkesnamn) @return [Values::SoklistaPage] the result. @param name [String] Name of the occupation. @example Get occupation

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

@see Values::SoklistaPage

# 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() click to toggle source

Fetch occupational fields from API (occupational_fields => yrkesområde) @return [Values::SoklistaPage] the result. @example Get occupational fields

client.occupational_field

@see Values::SoklistaPage

# 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) click to toggle source

Fetch occupational group from API (occupational_group => yrkesgrupp) @return [Values::SoklistaPage] the result. @param occupational_field_id [String] Occupational field ID. @example Get all occupational group

client.occupational_group

@example Get occupational group within occupational field

client.occupational_group(occupational_field_id: id)

@see Values::SoklistaPage

# 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) click to toggle source

Fetch occupations from API (occupation => yrkesnamn) @return [Values::SoklistaPage] the result. @param occupational_group_id [String] Occupational group ID. @example Get stats of available positions for all occupations

client.occupations

@example Get stats of available positions for some occupations

client.occupations(occupational_group_id: id)

@see Values::SoklistaPage

# 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() click to toggle source

Get version of API @return [String] the version of the API. @example Get API version

client.version
# File lib/arbetsformedlingen/api/client.rb, line 35
def version
  request.get('version').body
end

Private Instance Methods

uri_escape(string) click to toggle source
# File lib/arbetsformedlingen/api/client.rb, line 189
def uri_escape(string)
  URI.encode_www_form_component(string)
end