Class: WhosGotDirt::Requests::Relation::OpenCorporates

Inherits:
WhosGotDirt::Request show all
Defined in:
lib/whos_got_dirt/requests/relation/open_corporates.rb

Overview

Requests for corporate officerships from the OpenCorporates API.

OpenCorporates' date_of_birth and address filters require an API key. Its order parameter is not supported.

Examples:

Supply an API key.

"open_corporates_api_key": "..."

Find officerships by jurisdiction code.

"jurisdiction_code": "gb"

Find officerships with one of many jurisdiction codes.

"jurisdiction_code|=": ["gb", "ie"]

Find officerships by role.

"role": "ceo"

Find active officerships.

"inactive": false

Find inactive officerships.

"inactive": true

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from WhosGotDirt::Request

Instance Method Details

#convertHash

Converts the MQL parameters to API-specific parameters.

Returns:

  • (Hash)

    API-specific parameters

See Also:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/whos_got_dirt/requests/relation/open_corporates.rb', line 47

def convert
  equal('per_page', 'limit', default: input['open_corporates_api_key'] && 100) # default 30, maximum 100
  equal('page', 'page')

  input['subject'] && input['subject'].each do |subject|
    match('q', 'name', input: subject)
    date_range('date_of_birth', 'birth_date', input: subject)

    subject['contact_details'] && subject['contact_details'].each do |contact_detail|
      if contact_detail['type'] == 'address' && (contact_detail['value'] || contact_detail['value~='])
        output['address'] = contact_detail['value'] || contact_detail['value~=']
      end
    end
  end

  # API-specific parameters.
  equal('api_token', 'open_corporates_api_key')
  one_of('jurisdiction_code', 'jurisdiction_code', transform: lambda{|v| v.downcase})
  equal('position', 'role')
  equal('inactive', 'inactive', valid: [true, false])

  output
end

#or_operatorString

Returns the "OR" operator's serialization.

Returns:

  • (String)

    the "OR" operator's serialization



39
40
41
# File 'lib/whos_got_dirt/requests/relation/open_corporates.rb', line 39

def or_operator
  '|'
end

#to_sString

Returns the URL to request.

Returns:

  • (String)

    the URL to request



32
33
34
# File 'lib/whos_got_dirt/requests/relation/open_corporates.rb', line 32

def to_s
  "#{base_url}?#{to_query(convert.merge(order: 'score'))}"
end