Class: Rdmm::Responses::BaseResponse
- Inherits:
-
Object
- Object
- Rdmm::Responses::BaseResponse
show all
- Includes:
- Enumerable
- Defined in:
- lib/rdmm/responses/base_response.rb
Instance Method Summary
collapse
Constructor Details
#initialize(faraday_response) ⇒ BaseResponse
Returns a new instance of BaseResponse.
7
8
9
|
# File 'lib/rdmm/responses/base_response.rb', line 7
def initialize(faraday_response)
@faraday_response = faraday_response
end
|
Instance Method Details
#body ⇒ String
12
13
14
|
# File 'lib/rdmm/responses/base_response.rb', line 12
def body
faraday_response.body
end
|
#each(&block) ⇒ Object
Note:
Implementation for Enumerable
17
18
19
|
# File 'lib/rdmm/responses/base_response.rb', line 17
def each(&block)
resources.each(&block)
end
|
#errors ⇒ Hash?
22
23
24
|
# File 'lib/rdmm/responses/base_response.rb', line 22
def errors
body["result"]["errors"]
end
|
#first_position ⇒ Integer
32
33
34
|
# File 'lib/rdmm/responses/base_response.rb', line 32
def first_position
body["result"]["first_position"]
end
|
#has_error? ⇒ Boolean
27
28
29
|
# File 'lib/rdmm/responses/base_response.rb', line 27
def has_error?
status != 200
end
|
#has_next_page? ⇒ Boolean
37
38
39
|
# File 'lib/rdmm/responses/base_response.rb', line 37
def has_next_page?
first_position - 1 + result_count < total_count
end
|
42
43
44
|
# File 'lib/rdmm/responses/base_response.rb', line 42
def
faraday_response.
end
|
#message ⇒ String?
47
48
49
|
# File 'lib/rdmm/responses/base_response.rb', line 47
def message
body["result"]["message"]
end
|
#next_page_offset ⇒ Integer?
52
53
54
55
56
|
# File 'lib/rdmm/responses/base_response.rb', line 52
def next_page_offset
if has_next_page?
first_position + result_count
end
end
|
59
60
61
62
63
|
# File 'lib/rdmm/responses/base_response.rb', line 59
def resources
(sources || []).map do |source|
resource_class.new(source)
end
end
|
#result_count ⇒ Integer
66
67
68
|
# File 'lib/rdmm/responses/base_response.rb', line 66
def result_count
body["result"]["result_count"]
end
|
#status ⇒ Integer
71
72
73
|
# File 'lib/rdmm/responses/base_response.rb', line 71
def status
faraday_response.status
end
|
#total_count ⇒ Integer
76
77
78
|
# File 'lib/rdmm/responses/base_response.rb', line 76
def total_count
body["result"]["total_count"].to_i
end
|