Sha256: 2ce968c0d3ec09d9ab0f42416663a9dad76f5afe133997b6c8df6922c546cdd3

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 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)

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

          output
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
whos_got_dirt-0.0.4 lib/whos_got_dirt/requests/list/open_corporates.rb
whos_got_dirt-0.0.3 lib/whos_got_dirt/requests/list/open_corporates.rb
whos_got_dirt-0.0.2 lib/whos_got_dirt/requests/list/open_corporates.rb