Class: Rdmm::Responses::BaseResponse

Inherits:
Object
  • Object
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.

Parameters:

  • faraday_response (Faraday::Response)


7
8
9
# File 'lib/rdmm/responses/base_response.rb', line 7

def initialize(faraday_response)
  @faraday_response = faraday_response
end

Instance Method Details

#bodyString

Returns:

  • (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

#errorsHash?

Returns:

  • (Hash, nil)


22
23
24
# File 'lib/rdmm/responses/base_response.rb', line 22

def errors
  body["result"]["errors"]
end

#first_positionInteger

Returns:

  • (Integer)


32
33
34
# File 'lib/rdmm/responses/base_response.rb', line 32

def first_position
  body["result"]["first_position"]
end

#has_error?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rdmm/responses/base_response.rb', line 27

def has_error?
  status != 200
end

#has_next_page?Boolean

Returns:

  • (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

#headersFaraday::Utils::Headers

Returns:

  • (Faraday::Utils::Headers)


42
43
44
# File 'lib/rdmm/responses/base_response.rb', line 42

def headers
  faraday_response.headers
end

#messageString?

Returns:

  • (String, nil)


47
48
49
# File 'lib/rdmm/responses/base_response.rb', line 47

def message
  body["result"]["message"]
end

#next_page_offsetInteger?

Returns:

  • (Integer, nil)


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

#resourcesArray<Rdmm::Resources::BaseResource>

Returns:



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_countInteger

Returns:

  • (Integer)


66
67
68
# File 'lib/rdmm/responses/base_response.rb', line 66

def result_count
  body["result"]["result_count"]
end

#statusInteger

Returns:

  • (Integer)


71
72
73
# File 'lib/rdmm/responses/base_response.rb', line 71

def status
  faraday_response.status
end

#total_countInteger

Returns:

  • (Integer)


76
77
78
# File 'lib/rdmm/responses/base_response.rb', line 76

def total_count
  body["result"]["total_count"].to_i
end