Class: WhosGotDirt::Requests::Entity::OpenCorporates

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

Overview

Requests for companies from the OpenCorporates API.

OpenCorporates' fields and order parameters are not supported.

Examples:

Supply an API key.

"open_corporates_api_key": "..."

Find companies by name prefix.

"name~=" "ACME*"

Find companies by jurisdiction code.

"jurisdiction_code": "gb"

Find companies with one of many jurisdiction codes.

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

Find companies by country code.

"country_code": "gb"

Find companies with one of many country codes.

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

Find companies by status.

"current_status": "Dissolved"

Find companies by industry code.

"industry_code": "be_nace_2008-66191"

Find companies with all the given country codes.

"a:industry_code": "be_nace_2008-66191",
"b:industry_code": "be_nace_2008-66199"

Find companies with one of many country codes.

"industry_code|=": ["be_nace_2008-66191", "be_nace_2008-66199"]

Find active companies (true for inactive).

"inactive": false

Find branch companies (false for non-branch).

"branch": true

Find nonprofit companies (false for others).

"nonprofit": true

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from WhosGotDirt::Request

Instance Method Details

#and_operatorString

Returns the "AND" operator's serialization.

Returns:

  • (String)

    the "AND" operator's serialization



60
61
62
# File 'lib/whos_got_dirt/requests/entity/open_corporates.rb', line 60

def and_operator
  ','
end

#convertHash

Converts the MQL parameters to API-specific parameters.

Returns:

  • (Hash)

    API-specific parameters

See Also:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/whos_got_dirt/requests/entity/open_corporates.rb', line 75

def convert
  match('q', 'name')
  equal('company_type', 'classification')
  equal('created_since', 'created_at>=')
  date_range('incorporation_date', 'founding_date')
  date_range('dissolution_date', 'dissolution_date')
  equal('per_page', 'limit', default: input['open_corporates_api_key'] && 100) # default 30, maximum 100
  equal('page', 'page')

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

  # API-specific parameters.
  equal('api_token', 'open_corporates_api_key')
  one_of('jurisdiction_code', 'jurisdiction_code', transform: lambda{|v| v.downcase})
  one_of('country_code', 'country_code', transform: lambda{|v| v.downcase})
  equal('current_status', 'current_status')
  all_of('industry_codes', 'industry_code', backup: :one_of)
  equal('inactive', 'inactive', valid: [true, false])
  equal('branch', 'branch', valid: [true, false])
  equal('nonprofit', 'nonprofit', valid: [true, false])

  output
end

#or_operatorString

Returns the "OR" operator's serialization.

Returns:

  • (String)

    the "OR" operator's serialization



67
68
69
# File 'lib/whos_got_dirt/requests/entity/open_corporates.rb', line 67

def or_operator
  '|'
end

#to_sString

Returns the URL to request.

Returns:

  • (String)

    the URL to request



53
54
55
# File 'lib/whos_got_dirt/requests/entity/open_corporates.rb', line 53

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