class Wegift::Response
Constants
- STATUS
Attributes
error_code[RW]
global shared body
error_details[RW]
global shared body
error_string[RW]
global shared body
payload[RW]
global shared body
status[RW]
global shared body
Public Instance Methods
is_successful?()
click to toggle source
# File lib/wegift/models/response.rb, line 20 def is_successful? @status&.eql?(STATUS[:success]) end
parse(response = {})
click to toggle source
# File lib/wegift/models/response.rb, line 24 def parse(response = {}) # TODO: JSON responses, when requested? # let's fix that with a simpel catch all if response.success? && response['content-type'].eql?('application/json') @payload = JSON.parse(response.body) # TODO: @payload['status'] is only returned for orders! (products etc are plain objects) @status = @payload['status'] || STATUS[:success] @error_code = @payload['error_code'] @error_string = @payload['error_string'] @error_details = @payload['error_details'] else @payload = {} @status = STATUS[:error] @error_code = response.status @error_string = response.reason_phrase @error_details = response.reason_phrase end end