Class: WhosGotDirt::Responses::Relation::OpenCorporates

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

Overview

Converts corporate officerships 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 relation's URL.

Parameters:

  • result (Hash)

    the rendered result

Returns:

  • (String)

    the relation's URL



68
69
70
71
72
73
74
75
# File 'lib/whos_got_dirt/responses/relation/open_corporates.rb', line 68

def item_url(result)
  query = CGI.parse(env.url.query.to_s)
  url = "#{env.url.scheme}://#{env.url.host}/officers/#{result['identifiers'][0]['identifier']}"
  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.

Returns:

  • (Array<Hash>)

    the results



58
59
60
61
62
# File 'lib/whos_got_dirt/responses/relation/open_corporates.rb', line 58

def to_a
  parsed_body['officers'].map do |data|
    Result.new('Relation', renderer.result(data['officer']), self).finalize!
  end
end