Sha256: d17984dfd238e29c6ab5699a8f66f97ff4a433d5f3d37c77630f26da9a16c0ef

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module WhosGotDirt
  module Requests
    module List
      # Requests for corporate groupings from the OpenCorporates API.
      #
      # OpenCorporates' `q` filter performs a prefix search.
      #
      # @example Supply an API key.
      #   "open_corporates_api_key": "..."
      class OpenCorporates < Request
        @base_url = 'https://api.opencorporates.com/corporate_groupings/search'

        # Returns the URL to request.
        #
        # @return [String] the URL to request
        def to_s
          "#{base_url}?#{to_query(convert)}"
        end

        # Converts the MQL parameters to API-specific parameters.
        #
        # @return [Hash] API-specific parameters
        # @see https://api.opencorporates.com/documentation/API-Reference
        def convert
          match('q', 'name')
          equal('per_page', 'limit', default: input['open_corporates_api_key'] && 100) # default 30, maximum 100
          equal('page', 'page')

          # API-specific parameters.
          equal('api_token', 'open_corporates_api_key')

          output
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whos_got_dirt-0.0.5 lib/whos_got_dirt/requests/list/open_corporates.rb