class TNT::Resource
Base endpoint resources class
Constants
- XML_HEADER
- XML_RENDER_OPTIONS
Public Class Methods
credentials()
click to toggle source
Returns a payload with service credentials
@return [Hash]
# File lib/tnt.rb, line 22 def self.credentials { company: ENV['TNT_USERNAME'], password: ENV['TNT_PASSWORD'], appid: :EC, appversion: 3.0 } end
error_response?(response, parsed)
click to toggle source
Validate error response
Looks at the response code by default.
@param response [HTTP::Response] the server response @param parsed [Object] the parsed server response
@return [TrueClass] if status code is not a successful standard value
Calls superclass method
# File lib/tnt.rb, line 47 def self.error_response?(response, parsed) parsed.is_a?(Hash) && ( parsed.dig('parse_error') || parsed.dig('runtime_error') || parsed.dig('document', 'error') ) || super end
extract_error(response, parsed)
click to toggle source
Extracts the error message from the response
@param response [HTTP::Response] the server response @param parsed [Object] the parsed server response
@return [String]
Calls superclass method
# File lib/tnt.rb, line 61 def self.extract_error(response, parsed) parsed&.dig('runtime_error') || parsed&.dig('parse_error') || parsed&.dig('document', 'error')&.first || super end
parse_response(response)
click to toggle source
Parses response (from XML)
@param response [HTTP::Response] object @return [Object]
# File lib/tnt.rb, line 72 def self.parse_response(response) Hash.from_xml(response.body.to_s).deep_transform_keys(&:downcase) rescue StandardError [response.body.to_s.split(':')].to_h.deep_transform_keys(&:downcase) end
to_xml(data)
click to toggle source
Renders a dictionary to XML
@param data [Hash] object to be rendered @return [String]
# File lib/tnt.rb, line 35 def self.to_xml(data) XML_HEADER + Gyoku.xml({ eshipper: data }, XML_RENDER_OPTIONS) end