Class: WhosGotDirt::Responses::Entity::OpenDuka

Inherits:
WhosGotDirt::Response show all
Defined in:
lib/whos_got_dirt/responses/entity/open_duka.rb

Overview

Converts entities from the OpenDuka API to Popolo format.

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from WhosGotDirt::Response

Instance Method Details

#countFixnum

Returns the total number of matching results.

Returns:

  • (Fixnum)

    the total number of matching results



27
28
29
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 27

def count
  parsed_body.size
end

#error_messageObject



53
54
55
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 53

def error_message
  parsed_body['error']
end

#item_url(result) ⇒ String

Returns an entity's URL.

Parameters:

  • result (Hash)

    the rendered result

Returns:

  • (String)

    the entity's URL



44
45
46
47
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 44

def item_url(result)
  query = CGI.parse(env.url.query.to_s)
  "#{env.url.scheme}://#{env.url.host}/index.php/api/entity?id=#{CGI.escape(result['identifiers'][0]['identifier'].to_s)}&key=#{CGI.escape(query['key'][0].to_s)}"
end

#parse_bodyArray<Hash>

Parses the response body.

Returns:

  • (Array<Hash>)

    the parsed response body



20
21
22
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 20

def parse_body
  JSON.load(body)
end

#success?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 49

def success?
  super && Array === parsed_body
end

#to_aArray<Hash>

Transforms the parsed response body into results.

Returns:

  • (Array<Hash>)

    the results



34
35
36
37
38
# File 'lib/whos_got_dirt/responses/entity/open_duka.rb', line 34

def to_a
  parsed_body.map do |data|
    Result.new('Entity', renderer.result(data), self).finalize!
  end
end