Class: WhosGotDirt::Responses::List::OpenCorporates

Inherits:
Helpers::OpenCorporatesHelper show all
Defined in:
lib/whos_got_dirt/responses/list/open_corporates.rb

Overview

Converts corporate groupings from the OpenCorporates API to Popolo format.

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from WhosGotDirt::Response

Instance Method Details

#item_url(result) ⇒ String

Returns a list's URL.



36
37
38
39
40
41
42
43
# File 'lib/whos_got_dirt/responses/list/open_corporates.rb', line 36

def item_url(result)
  query = CGI.parse(env.url.query.to_s)
  url = "#{env.url.scheme}://#{env.url.host}/corporate_groupings/#{CGI.escape(result['name'].to_s)}"
  if query['api_token'].any?
    url += "?api_token=#{CGI.escape(query['api_token'][0].to_s)}"
  end
  url
end

#to_aArray<Hash>

Transforms the parsed response body into results.



26
27
28
29
30
# File 'lib/whos_got_dirt/responses/list/open_corporates.rb', line 26

def to_a
  parsed_body['corporate_groupings'].map do |data|
    Result.new('List', renderer.result(data['corporate_grouping']), self).finalize!
  end
end