Class: WhosGotDirt::Responses::Entity::OpenCorporates
- Inherits:
-
Helpers::OpenCorporatesHelper
- Object
- SimpleDelegator
- WhosGotDirt::Response
- Helpers::OpenCorporatesHelper
- WhosGotDirt::Responses::Entity::OpenCorporates
- Defined in:
- lib/whos_got_dirt/responses/entity/open_corporates.rb
Overview
Converts companies from the OpenCorporates API to Popolo format.
Instance Method Summary collapse
-
#item_url(result) ⇒ String
Returns an entity’s URL.
-
#to_a ⇒ Array<Hash>
Transforms the parsed response body into results.
Constructor Details
This class inherits a constructor from WhosGotDirt::Response
Instance Method Details
#item_url(result) ⇒ String
Returns an entity’s URL.
64 65 66 67 68 69 70 71 |
# File 'lib/whos_got_dirt/responses/entity/open_corporates.rb', line 64 def item_url(result) query = CGI.parse(env.url.query.to_s) url = "#{env.url.scheme}://#{env.url.host}/companies/#{result['jurisdiction_code']}/#{result['identifiers'][0]['identifier']}" if query['api_token'].any? url += "?api_token=#{CGI.escape(query['api_token'][0].to_s)}" end url end |
#to_a ⇒ Array<Hash>
Transforms the parsed response body into results.
54 55 56 57 58 |
# File 'lib/whos_got_dirt/responses/entity/open_corporates.rb', line 54 def to_a parsed_body['companies'].map do |data| Result.new('Entity', renderer.result(data['company']), self).finalize! end end |