class VNCPostAPI::Order

Constants

DEFAULT_ATTRS

Public Class Methods

new(attributes = {}, persisted = false) click to toggle source
Calls superclass method
# File lib/vncpost_api/resources/order.rb, line 50
def initialize(attributes = {}, persisted = false)
  attributes = DEFAULT_ATTRS.merge(attributes)
  super
end

Public Instance Methods

track() click to toggle source
# File lib/vncpost_api/resources/order.rb, line 55
def track
  tracking_number = @attributes[:returned_code] || @attributes[:code]
  Tracking.find(tracking_number)
end

Private Instance Methods

load_attributes_from_response(response) click to toggle source
# File lib/vncpost_api/resources/order.rb, line 62
def load_attributes_from_response(response)
  # save the response attributes
  if response_code_allows_body?(response.code.to_i) &&
      (response["Content-Length"].nil? || response["Content-Length"] != "0") &&
      !response.body.nil? && response.body.strip.size > 0

    attributes = self.class.format.decode(response.body)
    # Code(client provided code) will be overwrited by response's Code from the server
    # To avoid that, the code returned will be stored as ReturnedCode
    attributes["ReturnedCode"] = attributes.delete("Code")

    load(attributes, false, true)
    # reset the attributes structure after assign attributes that came back from server
    reset_attributes_format
    @persisted = true
  end
end