Sha256: e001db7af55e254aff5aa40594ab73f5defc8a7ec7e530e93f832b75f32353bc

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module WhosGotDirt
  module Requests
    module Entity
      # Requests for entities from the Poderopedia API.
      #
      # The Poderopedia API returns 10 results only, without pagination.
      #
      # The `entity` filter is required.
      #
      # @example Supply an API key.
      #   "poderopedia_api_key": "..."
      #
      # @example Find entities of the class `Person` or `Organization`.
      #   "entity": "Person"
      class Poderopedia < Request
        @base_url = 'http://api.poderopedia.org/visualizacion/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://api.poderopedia.org/search
        def convert
          match('alias', 'name')

          # API-specific parameters.
          equal('user_key', 'poderopedia_api_key')
          equal('entity', 'type', valid: ['Person', 'Organization'], transform: lambda{|v|
            case v
            when 'persona'
              'Person'
            when 'organizacion'
              'Organization'
            end
          })

          output
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whos_got_dirt-0.0.2 lib/whos_got_dirt/requests/entity/poderopedia.rb