Class: WhosGotDirt::Requests::Entity::OpenCorporates
- Inherits:
-
WhosGotDirt::Request
- Object
- WhosGotDirt::Request
- WhosGotDirt::Requests::Entity::OpenCorporates
- 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.
Instance Method Summary collapse
-
#and_operator ⇒ String
Returns the "AND" operator's serialization.
-
#convert ⇒ Hash
Converts the MQL parameters to API-specific parameters.
-
#or_operator ⇒ String
Returns the "OR" operator's serialization.
-
#to_s ⇒ String
Returns the URL to request.
Constructor Details
This class inherits a constructor from WhosGotDirt::Request
Instance Method Details
#and_operator ⇒ String
Returns the "AND" operator's serialization.
60 61 62 |
# File 'lib/whos_got_dirt/requests/entity/open_corporates.rb', line 60 def and_operator ',' end |
#convert ⇒ Hash
Converts the MQL parameters to API-specific parameters.
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_operator ⇒ String
Returns 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_s ⇒ String
Returns 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 |