Class: Dibuk::Response::Base
- Inherits:
-
Object
- Object
- Dibuk::Response::Base
- Extended by:
- Dry::Initializer::Mixin
- Defined in:
- lib/dibuk/response/base.rb
Constant Summary collapse
- SUCCESS_HTTP_STATUSES =
[200].freeze
- SUCCESS_STATUSES =
['SUCCESS'].freeze
Instance Method Summary collapse
- #body ⇒ Object
- #error? ⇒ Boolean
- #error_code ⇒ Object
- #error_data ⇒ Object
- #http_status_ok ⇒ Object
- #limit_exceeded? ⇒ Boolean
- #not_buyed? ⇒ Boolean
- #success? ⇒ Boolean
Instance Method Details
#body ⇒ Object
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. end end |
#error? ⇒ Boolean
14 15 16 |
# File 'lib/dibuk/response/base.rb', line 14 def error? !success? end |
#error_code ⇒ Object
18 19 20 21 |
# File 'lib/dibuk/response/base.rb', line 18 def error_code return unless error? body[:eNum].to_s end |
#error_data ⇒ Object
23 24 25 26 |
# File 'lib/dibuk/response/base.rb', line 23 def error_data return unless error? body[:eData] end |
#http_status_ok ⇒ Object
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
28 29 30 |
# File 'lib/dibuk/response/base.rb', line 28 def limit_exceeded? error_code == '2015' end |
#not_buyed? ⇒ Boolean
32 33 34 |
# File 'lib/dibuk/response/base.rb', line 32 def not_buyed? error_code == '2004' end |
#success? ⇒ Boolean
10 11 12 |
# File 'lib/dibuk/response/base.rb', line 10 def success? http_success? && status_success? end |