Class: Payrix::Http::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/payrix/http/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = {}, status = '', cls) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
# File 'lib/payrix/http/response.rb', line 6

def initialize(response = {}, status = '', cls)
  @response = response
  @status = status
  @cls = cls
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/payrix/http/response.rb', line 4

def status
  @status
end

Instance Method Details

#detailsObject



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

def details
  (@response['response'] && @response['response']['details']) || {}
end

#errorsObject



18
19
20
# File 'lib/payrix/http/response.rb', line 18

def errors
  @response['errors'] || (@response['response'] && @response['response']['errors']) || []
end

#has_errors?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/payrix/http/response.rb', line 22

def has_errors?
  !errors.empty?
end

#has_more?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
# File 'lib/payrix/http/response.rb', line 34

def has_more?
  page = @response['response'] && @response['response']['details'] && @response['response']['details']['page']

  !page.nil? &&
  !page['current'].nil? &&
  !page['last'].nil? &&
  page['current'] < page['last']
end

#responseObject

Return the response as an array



13
14
15
16
# File 'lib/payrix/http/response.rb', line 13

def response
  data = (@response['response'] && @response['response']['data']) || []
  data.map { |v| @cls.new(v) }
end

#totalsObject



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

def totals
  (@response['response'] && @response['response']['details'] && @response['response']['details']['totals']) || {}
end