Class: WhosGotDirt::Responses::Entity::Poderopedia
- Inherits:
-
WhosGotDirt::Response
- Object
- SimpleDelegator
- WhosGotDirt::Response
- WhosGotDirt::Responses::Entity::Poderopedia
- Defined in:
- lib/whos_got_dirt/responses/entity/poderopedia.rb
Overview
Converts entities from the Poderopedia API to Popolo format.
Instance Method Summary collapse
-
#count ⇒ Fixnum
Returns the total number of matching results.
-
#item_url(result) ⇒ String
Returns an entity's URL.
-
#parse_body ⇒ Array<Hash>
Parses the response body.
-
#to_a ⇒ Array<Hash>
Transforms the parsed response body into results.
Constructor Details
This class inherits a constructor from WhosGotDirt::Response
Instance Method Details
#count ⇒ Fixnum
Returns the total number of matching results.
29 30 31 |
# File 'lib/whos_got_dirt/responses/entity/poderopedia.rb', line 29 def count parsed_body.size end |
#item_url(result) ⇒ String
Returns an entity's URL.
46 47 48 49 |
# File 'lib/whos_got_dirt/responses/entity/poderopedia.rb', line 46 def item_url(result) query = CGI.parse(env.url.query.to_s) "#{env.url.scheme}://#{env.url.host}/visualizacion/getEntityById?id=#{CGI.escape(result['identifiers'][0]['identifier'].to_s)}&entity=#{CGI.escape(query['entity'][0].to_s)}&user_key=#{CGI.escape(query['user_key'][0].to_s)}" end |
#parse_body ⇒ Array<Hash>
Parses the response body.
21 22 23 24 |
# File 'lib/whos_got_dirt/responses/entity/poderopedia.rb', line 21 def parse_body parsed = JSON.load(body) parsed['organization'] || parsed['person'] end |