Sha256: 9d5defe5cff38623d4b60074abedc5fbfcaa68f8549b800185b4df9e4e6a98b1

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

module WhosGotDirt
  module Requests
    module Relation
      # Requests for concessions from the OpenOil API.
      #
      # @example Supply an API key.
      #   "open_oil_api_key": "..."
      #
      # @example Find concessions by country code.
      #   "country_code": "BR"
      #
      # @example Find concessions with a "licensed" or "unlicensed" status.
      #   "status": "licensed"
      #
      # @example Find concessions with an "offshore" or "onshore" type.
      #   "type": "offshore"
      class OpenOil < Request
        @base_url = 'https://api.openoil.net/concession/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 http://openoil.net/openoil-api/
        def convert
          equal('per_page', 'limit') # default 100, no maximum
          equal('page', 'page')

          input['subject'] && input['subject'].each do |subject|
            equal('licensee', 'name', input: subject) # doesn't work, upstream bug
          end

          # API-specific parameters.
          equal('apikey', 'open_oil_api_key')
          equal('country', 'country_code', transform: lambda{|v| v.upcase})
          equal('status', 'status', valid: ['licensed', 'unlicensed'])
          equal('type', 'type', valid: ['offshore', 'onshore'])

          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/relation/open_oil.rb