Sha256: e20e73b26e966f6e2a1624af4f2700cdb6489aae9bdbdea18e6a6d52b0c7e2b5

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module WhosGotDirt
  module Responses
    module Entity
      # Converts entities from the Poderopedia API to Popolo format.
      #
      # @see http://api.poderopedia.org/search
      class Poderopedia < Response
        @template = {
          '@type' => 'Entity',
          'name' => '/alias',
          'description' => '/shortBio',
          'identifiers' => [{
            'identifier' => '/id',
            'scheme' => 'Poderopedia',
          }],
        }

        # Parses the response body.
        #
        # @return [Array<Hash>] the parsed response body
        def parse_body
          parsed = JSON.load(body)
          parsed['organization'] || parsed['person']
        end

        # Returns the total number of matching results.
        #
        # @return [Fixnum] the total number of matching results
        def count
          parsed_body.size
        end

        # Transforms the parsed response body into results.
        #
        # @return [Array<Hash>] the results
        def to_a
          parsed_body.map do |data|
            Result.new('Entity', renderer.result(data), self).finalize!
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whos_got_dirt-0.0.3 lib/whos_got_dirt/responses/entity/poderopedia.rb