class Endicia::LabelResponse
Constants
- CRITICAL_ERROR_CODES
Attributes
cost_center[RW]
error_message[RW]
final_postage[RW]
image[RW]
pic[RW]
postage_balance[RW]
postage_price[RW]
postmark_date[RW]
reference_id[RW]
reference_id2[RW]
reference_id3[RW]
reference_id4[RW]
request_body[RW]
request_url[RW]
requester_id[RW]
response_body[RW]
status[RW]
tracking_number[RW]
transaction_date_time[RW]
transaction_id[RW]
Public Class Methods
new(result)
click to toggle source
# File lib/endicia_ruby/label_response.rb, line 26 def initialize(result) self.response_body = filter_response_body(result.body.dup) data = result["LabelRequestResponse"] || {} data.each do |k, v| if k == 'Base64LabelImage' k = "image" elsif k == 'Label' # when customs form is included in xml, Endicia returns the image in a different format k = "image" # There can be one or many <Image> elements in <Label>. MultiXml parses multiples into an array. v = [v["Image"]].flatten.first["__content__"] end setter = :"#{k.tableize.singularize}=" send(setter, v) if !k['xmlns'] && respond_to?(setter) end end
Public Instance Methods
critical_error?()
click to toggle source
True if this is an error and it's a “critical” one, meaning the ability to generate further labels could be impeded by the information received back
# File lib/endicia_ruby/label_response.rb, line 50 def critical_error? CRITICAL_ERROR_CODES.include?(status.to_i) end
label_generated?()
click to toggle source
True if this result represents a successful label response
# File lib/endicia_ruby/label_response.rb, line 44 def label_generated? status && status.to_i == 0 end
Private Instance Methods
filter_response_body(string)
click to toggle source
# File lib/endicia_ruby/label_response.rb, line 82 def filter_response_body(string) # Strip image data for readability: string.gsub(/<((Base64Label)?Image( PartNumber=\"\d+\")?)>.+?<\/((Base64Label)?Image)>/, '<\1>[data]</\4>') end