Class: Search::ResultsResponse

Inherits:
Common::Base show all
Includes:
Common::Client::Concerns::ServiceStatus
Defined in:
lib/search/response.rb

Constant Summary

Constants included from Common::Client::Concerns::ServiceStatus

Common::Client::Concerns::ServiceStatus::RESPONSE_STATUS

Instance Attribute Summary

Attributes inherited from Common::Base

#errors_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Common::Base

#changed, #changed?, #changes, default_sort, filterable_attributes, max_per_page, per_page, sortable_attributes

Constructor Details

#initialize(status, pagination, attributes = nil) ⇒ ResultsResponse

Returns a new instance of ResultsResponse.



15
16
17
18
19
# File 'lib/search/response.rb', line 15

def initialize(status, pagination, attributes = nil)
  super(attributes) if attributes
  self.pagination = pagination
  self.status = status
end

Class Method Details

.from(response) ⇒ Object



21
22
23
24
# File 'lib/search/response.rb', line 21

def self.from(response)
  pagination = pagination_object(response.body)
  new(response.status, pagination, body: response.body)
end

.pagination_object(body) ⇒ Object



47
48
49
# File 'lib/search/response.rb', line 47

def self.pagination_object(body)
  Search::Pagination.new(body).object
end

Instance Method Details

#cache?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/search/response.rb', line 26

def cache?
  status == 200
end

#metadataObject



30
31
32
# File 'lib/search/response.rb', line 30

def 
  { status: response_status }
end

#response_statusObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/search/response.rb', line 34

def response_status
  case status
  when 200
    RESPONSE_STATUS[:ok]
  when 403
    RESPONSE_STATUS[:not_authorized]
  when 404
    RESPONSE_STATUS[:not_found]
  else
    RESPONSE_STATUS[:server_error]
  end
end