Class: Endicia::LabelResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/endicia_ruby/label_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ LabelResponse

Returns a new instance of LabelResponse.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/endicia_ruby/label_response.rb', line 24

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"
      v = v["Image"]["__content__"]
    end
    setter = :"#{k.tableize.singularize}="
    send(setter, v) if !k['xmlns'] && respond_to?(setter)
  end
end

Instance Attribute Details

#cost_centerObject

Returns the value of attribute cost_center.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def cost_center
  @cost_center
end

#error_messageObject

Returns the value of attribute error_message.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def error_message
  @error_message
end

#final_postageObject

Returns the value of attribute final_postage.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def final_postage
  @final_postage
end

#imageObject

Returns the value of attribute image.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def image
  @image
end

#picObject

Returns the value of attribute pic.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def pic
  @pic
end

#postage_balanceObject

Returns the value of attribute postage_balance.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def postage_balance
  @postage_balance
end

#postmark_dateObject

Returns the value of attribute postmark_date.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def postmark_date
  @postmark_date
end

#reference_idObject

Returns the value of attribute reference_id.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def reference_id
  @reference_id
end

#reference_id2Object

Returns the value of attribute reference_id2.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def reference_id2
  @reference_id2
end

#reference_id3Object

Returns the value of attribute reference_id3.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def reference_id3
  @reference_id3
end

#reference_id4Object

Returns the value of attribute reference_id4.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def reference_id4
  @reference_id4
end

#request_bodyObject

Returns the value of attribute request_body.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def request_body
  @request_body
end

#request_urlObject

Returns the value of attribute request_url.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def request_url
  @request_url
end

#requester_idObject

Returns the value of attribute requester_id.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def requester_id
  @requester_id
end

#response_bodyObject

Returns the value of attribute response_body.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def response_body
  @response_body
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def status
  @status
end

#tracking_numberObject

Returns the value of attribute tracking_number.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def tracking_number
  @tracking_number
end

#transaction_date_timeObject

Returns the value of attribute transaction_date_time.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def transaction_date_time
  @transaction_date_time
end

#transaction_idObject

Returns the value of attribute transaction_id.



5
6
7
# File 'lib/endicia_ruby/label_response.rb', line 5

def transaction_id
  @transaction_id
end

Instance Method Details

#critical_error?Boolean

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

Returns:

  • (Boolean)


47
48
49
# File 'lib/endicia_ruby/label_response.rb', line 47

def critical_error?
  CRITICAL_ERROR_CODES.include?(status.to_i)
end

#label_generated?Boolean

True if this result represents a successful label response

Returns:

  • (Boolean)


41
42
43
# File 'lib/endicia_ruby/label_response.rb', line 41

def label_generated?
  status && status.to_i == 0
end