Class: WhosGotDirt::Responses::Relation::OpenOil
- Inherits:
-
WhosGotDirt::Response
- Object
- SimpleDelegator
- WhosGotDirt::Response
- WhosGotDirt::Responses::Relation::OpenOil
- Defined in:
- lib/whos_got_dirt/responses/relation/open_oil.rb
Overview
Converts concessions from the OpenOil API to Popolo format.
Class Method Summary collapse
Instance Method Summary collapse
-
#count ⇒ Fixnum
Returns the total number of matching results.
-
#item_url(result) ⇒ String
Returns a relation's URL.
-
#page ⇒ Fixnum
Returns the current page number.
-
#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
Class Method Details
.date_formatter(property, path) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/whos_got_dirt/responses/relation/open_oil.rb', line 10 def date_formatter(property, path) return lambda{|data| v = JsonPointer.new(data, path).value [property, v.empty? ? nil : v + 'T00:00:00Z'] } end |
Instance Method Details
#count ⇒ Fixnum
Returns the total number of matching results.
58 59 60 |
# File 'lib/whos_got_dirt/responses/relation/open_oil.rb', line 58 def count parsed_body['result_count'] end |
#item_url(result) ⇒ String
Returns a relation's URL.
82 83 84 85 |
# File 'lib/whos_got_dirt/responses/relation/open_oil.rb', line 82 def item_url(result) query = CGI.parse(env.url.query.to_s) "#{env.url.scheme}://#{env.url.host}/concession/#{result['identifiers'][0]['identifier']}?apikey=#{CGI.escape(query['apikey'][0].to_s)}" end |
#page ⇒ Fixnum
Returns the current page number.
65 66 67 |
# File 'lib/whos_got_dirt/responses/relation/open_oil.rb', line 65 def page parsed_body['page'] end |
#parse_body ⇒ Array<Hash>
Parses the response body.
51 52 53 |
# File 'lib/whos_got_dirt/responses/relation/open_oil.rb', line 51 def parse_body JSON.load(body) end |