Class: Dibuk::Response::Base

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer::Mixin
Defined in:
lib/dibuk/response/base.rb

Direct Known Subclasses

Licensed, Linked, Sent

Constant Summary collapse

SUCCESS_HTTP_STATUSES =
[200].freeze
SUCCESS_STATUSES =
['SUCCESS'].freeze

Instance Method Summary collapse

Instance Method Details

#bodyObject



36
37
38
39
40
41
42
43
44
# File 'lib/dibuk/response/base.rb', line 36

def body
  return unless raw_body
  @body ||=
      begin
        JSON.parse(raw_body, symbolize_names: true)
      rescue => e
        raise InvalidResponseError, e.message
      end
end

#error?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/dibuk/response/base.rb', line 14

def error?
  !success?
end

#error_codeObject



18
19
20
21
# File 'lib/dibuk/response/base.rb', line 18

def error_code
  return unless error?
  body[:eNum].to_s
end

#error_dataObject



23
24
25
26
# File 'lib/dibuk/response/base.rb', line 23

def error_data
  return unless error?
  body[:eData]
end

#http_status_okObject



46
47
48
# File 'lib/dibuk/response/base.rb', line 46

def http_status_ok
  @http_status_ok ||= http_response.instance_of? Net::HTTPOK
end

#limit_exceeded?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dibuk/response/base.rb', line 28

def limit_exceeded?
  error_code == '2015'
end

#not_buyed?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/dibuk/response/base.rb', line 32

def not_buyed?
  error_code == '2004'
end

#success?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/dibuk/response/base.rb', line 10

def success?
  http_success? && status_success?
end