Class: WhosGotDirt::Responses::Entity::OpenDuka
- Inherits:
-
WhosGotDirt::Response
- Object
- SimpleDelegator
- WhosGotDirt::Response
- WhosGotDirt::Responses::Entity::OpenDuka
- Defined in:
- lib/whos_got_dirt/responses/entity/open_duka.rb
Overview
Converts entities from the OpenDuka API to Popolo format.
Instance Method Summary collapse
-
#count ⇒ Fixnum
Returns the total number of matching results.
- #error_message ⇒ Object
-
#item_url(result) ⇒ String
Returns an entity's URL.
-
#parse_body ⇒ Array<Hash>
Parses the response body.
- #success? ⇒ Boolean
-
#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.
27 28 29 |
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 27 def count parsed_body.size end |
#error_message ⇒ Object
53 54 55 |
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 53 def parsed_body['error'] end |
#item_url(result) ⇒ String
Returns an entity's URL.
44 45 46 47 |
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 44 def item_url(result) query = CGI.parse(env.url.query.to_s) "#{env.url.scheme}://#{env.url.host}/index.php/api/entity?id=#{CGI.escape(result['identifiers'][0]['identifier'].to_s)}&key=#{CGI.escape(query['key'][0].to_s)}" end |
#parse_body ⇒ Array<Hash>
Parses the response body.
20 21 22 |
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 20 def parse_body JSON.load(body) end |
#success? ⇒ Boolean
49 50 51 |
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 49 def success? super && Array === parsed_body end |
#to_a ⇒ Array<Hash>
Transforms the parsed response body into results.
34 35 36 37 38 |
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 34 def to_a parsed_body.map do |data| Result.new('Entity', renderer.result(data), self).finalize! end end |