Class: ShareNotify::SearchResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/share_notify/search_response.rb

Defined Under Namespace

Classes: Document

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ SearchResponse

Returns a new instance of SearchResponse.

Parameters:

  • response (HTTParty::Response)

    returned from ShareNotify::API



7
8
9
10
11
# File 'lib/share_notify/search_response.rb', line 7

def initialize(response)
  fail ArgumentError, 'API response is nil' if response.nil?
  @status = response.code
  @response = response.parsed_response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/share_notify/search_response.rb', line 4

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/share_notify/search_response.rb', line 4

def status
  @status
end

Instance Method Details

#countObject



13
14
15
# File 'lib/share_notify/search_response.rb', line 13

def count
  response.fetch('count', 0)
end

#docsObject



17
18
19
# File 'lib/share_notify/search_response.rb', line 17

def docs
  @docs ||= response.fetch('results', []).map { |d| Document.new(d) }
end