Sha256: 42424b7e727d072d32e550d3b09eb393e07b9f6179f10ca32ef38a99ee02e3ce
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
require_relative 'initializable' class Wegift::Response include Initializable STATUS = {:success => 'SUCCESS', :error => 'ERROR'} # Field Name Contents # # status - The status of the transaction. Usually “SUCCESS” or “ERROR” # error_code - The error code, i.e. SE002 # error_string - Description of the error code, i.e. Required field missing from request # error_details - Details of the particular error, i.e. Field "delivery" missing from request # global shared body attr_accessor :payload, :status, :error_code, :error_string, :error_details def is_successful? @status && @status.eql?(STATUS[:success]) end 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wegift-ruby-client-1.7.2 | lib/wegift/models/response.rb |
wegift-ruby-client-1.7.1 | lib/wegift/models/response.rb |