Class: Arbetsformedlingen::API::MatchningClient
- Inherits:
-
Object
- Object
- Arbetsformedlingen::API::MatchningClient
- Defined in:
- lib/arbetsformedlingen/api/matchning_client.rb
Overview
API client for matchning
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#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.
-
#initialize(request: Request.new) ⇒ MatchningClient
constructor
Initialize client.
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
#request ⇒ Object (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
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?) = 'One of: county_id, municipality_id, occupation_id, keywords is required' # rubocop:disable Metrics/LineLength raise ArgumentError, 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 |