Sha256: bfbdc538b16e2fc668edc720b74be1de7e22dd7231321b9c200eaa50f68e7a9c

Contents?: true

Size: 1.3 KB

Versions: 3

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 'Person'
              'persona'
            when 'Organization'
              'organizacion'
            end
          })

          output
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
whos_got_dirt-0.0.5 lib/whos_got_dirt/requests/entity/poderopedia.rb
whos_got_dirt-0.0.4 lib/whos_got_dirt/requests/entity/poderopedia.rb
whos_got_dirt-0.0.3 lib/whos_got_dirt/requests/entity/poderopedia.rb