Class: Lazada::API::Response
- Inherits:
-
Object
- Object
- Lazada::API::Response
- Defined in:
- lib/lazada_dino/api/response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #body_error_messages ⇒ Object
- #error? ⇒ Boolean
- #error_code ⇒ Object
- #error_message ⇒ Object
- #error_type ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #request_id ⇒ Object
- #success? ⇒ Boolean
- #warning? ⇒ Boolean
- #warning_messages ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
6 7 8 |
# File 'lib/lazada_dino/api/response.rb', line 6 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/lazada_dino/api/response.rb', line 4 def response @response end |
Instance Method Details
#body_error_messages ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lazada_dino/api/response.rb', line 47 def return if response.dig('ErrorResponse').nil? # Parent error coming in the header hash = { error: } # Error coming in the body response.dig('ErrorResponse', 'Body', 'Errors')&.each do |error| hash[error['Field'].dup] = error['Message'] end hash end |
#error? ⇒ Boolean
18 19 20 |
# File 'lib/lazada_dino/api/response.rb', line 18 def error? response['ErrorResponse'].present? end |
#error_code ⇒ Object
43 44 45 |
# File 'lib/lazada_dino/api/response.rb', line 43 def error_code response.dig('ErrorResponse', 'Head', 'ErrorCode') end |
#error_message ⇒ Object
35 36 37 |
# File 'lib/lazada_dino/api/response.rb', line 35 def response.dig('ErrorResponse', 'Head', 'ErrorMessage') end |
#error_type ⇒ Object
39 40 41 |
# File 'lib/lazada_dino/api/response.rb', line 39 def error_type response.dig('ErrorResponse', 'Head', 'ErrorType') end |
#request_id ⇒ Object
10 11 12 |
# File 'lib/lazada_dino/api/response.rb', line 10 def request_id response.dig('SuccessResponse', 'Head', 'RequestId') end |
#success? ⇒ Boolean
14 15 16 |
# File 'lib/lazada_dino/api/response.rb', line 14 def success? response['SuccessResponse'].present? end |
#warning? ⇒ Boolean
22 23 24 |
# File 'lib/lazada_dino/api/response.rb', line 22 def warning? response.dig('SuccessResponse', 'Body', 'Warnings').present? end |
#warning_messages ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/lazada_dino/api/response.rb', line 26 def hash = {} response.dig('SuccessResponse', 'Body', 'Warnings').each do |warning| hash[warning['Field'].dup] = warning['Message'] end hash end |