Class: WhosGotDirt::Responses::Entity::CorpWatch
- Inherits:
-
WhosGotDirt::Response
- Object
- SimpleDelegator
- WhosGotDirt::Response
- WhosGotDirt::Responses::Entity::CorpWatch
- Defined in:
- lib/whos_got_dirt/responses/entity/corp_watch.rb
Overview
Converts entities from the CorpWatch API to Popolo format.
Instance Method Summary collapse
-
#count ⇒ Fixnum
Returns the total number of matching results.
-
#index ⇒ Fixnum
Returns the current index.
-
#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.
50 51 52 |
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 50 def count Integer(parsed_body['meta']['total_results']) end |
#index ⇒ Fixnum
Returns the current index.
57 58 59 |
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 57 def index parsed_body['meta']['parameters']['index'] end |
#item_url(result) ⇒ String
Returns an entity's URL.
78 79 80 81 82 83 84 85 |
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 78 def item_url(result) query = CGI.parse(env.url.query.to_s) url = "#{env.url.scheme}://#{env.url.host}#{env.url.path.sub(/\.json\z/, '')}/#{result['identifiers'][0]['identifier']}.json" if query['key'].any? url += "?key=#{CGI.escape(query['key'][0].to_s)}" end url end |
#parse_body ⇒ Array<Hash>
Parses the response body.
43 44 45 |
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 43 def parse_body JSON.load(body) end |
#to_a ⇒ Array<Hash>
Transforms the parsed response body into results.
64 65 66 67 68 69 70 71 72 |
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 64 def to_a if parsed_body['result']['companies'] parsed_body['result']['companies'].map do |_,data| Result.new('Entity', renderer.result(data), self).finalize! end else [] end end |