Class: Arbetsformedlingen::API::MatchningClient

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

Overview

API client for matchning

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request: Request.new) ⇒ MatchningClient

Initialize client



15
16
17
# File 'lib/arbetsformedlingen/api/matchning_client.rb', line 15

def initialize(request: Request.new)
  @request = request
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



12
13
14
# File 'lib/arbetsformedlingen/api/matchning_client.rb', line 12

def request
  @request
end

Instance Method Details

#ads(county_id: nil, municipality_id: nil, occupation_id: nil, keywords: nil, page: 1, page_size: 30, area_id: nil, occupation_group_id: nil, employment_type: nil, occupation_field_id: nil, published_after: nil, organization_number: nil) ⇒ MatchningResult

rubocop:disable Metrics/LineLength Find matching ads from API rubocop:enable Metrics/LineLength

Examples:

Get ads within county

client.ads(county: id)

Get ads within municipality

client.ads(municipality: id)

Get ads with keyword

client.ads(keywrods: 'ruby')

Get ads with keyword on page 3 and with a page size of 10

client.ads(keywrods: 'ruby', page: 3, page_size: 10)

Get ads with keyword and organsiation numer

client.ads(keywrods: 'ruby', organization_number: org_no)

Parameters:

  • area_id (String) (defaults to: nil)

    Area ID.

  • county_id (String) (defaults to: nil)

    County ID.

  • municipality_id (String) (defaults to: nil)

    Municipality ID.

  • occupation_id (String) (defaults to: nil)

    Occupation ID.

  • keywords (String) (defaults to: nil)

    Keywords.

  • page (Integer) (defaults to: 1)

    Page ID.

  • page_size (Integer) (defaults to: 30)

    Page size ID.

  • occupation_group_id (String) (defaults to: nil)

    Occupation_group ID.

  • employment_type (String) (defaults to: nil)

    Employment type ID.

  • occupation_field_id (String) (defaults to: nil)

    Occupation field ID.

  • published_after (Time, Date, String) (defaults to: nil)

    Published after ID (ISO8601 format: YYYY-MM-DDThh:mm:ssTZD).

  • organization_number (String) (defaults to: nil)

    Organization_number ID.

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/arbetsformedlingen/api/matchning_client.rb', line 45

def ads(
  # one of these must be present
  county_id: nil,
  municipality_id: nil,
  occupation_id: nil,
  keywords: nil,
  # optional
  page: 1,
  page_size: 30,
  area_id: nil,
  occupation_group_id: nil,
  employment_type: nil,
  occupation_field_id: nil,
  published_after: nil,
  organization_number: nil
)

  one_of_required = [county_id, municipality_id, occupation_id, keywords]
  if one_of_required.all?(&:nil?)
    error_message = 'One of: county_id, municipality_id, occupation_id, keywords is required' # rubocop:disable Metrics/LineLength
    raise ArgumentError, error_message
  end

  # TODO: Should we validate the IDs passed? What if they're invalid? Do we crash?
  #
  #       Currently when an invalid value is passed MatchningResult::build returns
  #         => KeyError: key not found: "matchningslista"
  #       which isn't really helpful..

  query = {
    lanid: county_id,
    kommunid: municipality_id,
    yrkesid: occupation_id,
    nyckelord: santize_keywords_query(keywords),
    sida: page,
    antalrader: page_size,
    omradeid: area_id,
    yrkesgruppid: occupation_group_id,
    anstallningstyp: santize_employment_type_query(employment_type),
    yrkesomradeid: occupation_field_id,
    sokdatum: normalize_date_to_iso8601(published_after),
    organisationsnummer: organization_number,
  }

  response = request.get('matchning', query: query)

  MatchningResult.build(response)
end