Class: Io::Flow::V0::Models::Tracking

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Overview

Top level tracking information which contains labels. In cases where shipments are re-labeled, you will see multiple labels for each tracking allowing simple access to see where a shipment is - with which carrier and with the local tracking number

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Tracking

Returns a new instance of Tracking.



22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22016

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :labels, :status, :attributes], 'Tracking')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @labels = HttpClient::Preconditions.assert_class('labels', opts.delete(:labels), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::TrackingLabel) ? x : ::Io::Flow::V0::Models::TrackingLabel.new(x)) }
  @status = (x = opts.delete(:status); x.is_a?(::Io::Flow::V0::Models::TrackingStatus) ? x : ::Io::Flow::V0::Models::TrackingStatus.apply(x))
  @attributes = HttpClient::Preconditions.assert_class('attributes', opts.delete(:attributes), Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('attributes', d[1], String); h }
  @window = (x = opts.delete(:window); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::DatetimeRange) ? x : ::Io::Flow::V0::Models::DatetimeRange.new(x)))
  @order_number = (x = opts.delete(:order_number); x.nil? ? nil : HttpClient::Preconditions.assert_class('order_number', x, String))
end

Instance Attribute Details

#attributes ⇒ Object (readonly)

Returns the value of attribute attributes.



22014
22015
22016
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22014

def attributes
  @attributes
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



22014
22015
22016
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22014

def id
  @id
end

#labels ⇒ Object (readonly)

Returns the value of attribute labels.



22014
22015
22016
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22014

def labels
  @labels
end

#order_number ⇒ Object (readonly)

Returns the value of attribute order_number.



22014
22015
22016
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22014

def order_number
  @order_number
end

#status ⇒ Object (readonly)

Returns the value of attribute status.



22014
22015
22016
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22014

def status
  @status
end

#window ⇒ Object (readonly)

Returns the value of attribute window.



22014
22015
22016
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22014

def window
  @window
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



22031
22032
22033
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22031

def copy(incoming={})
  Tracking.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hash ⇒ Object



22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22035

def to_hash
  {
    :id => id,
    :labels => labels.map { |o| o.to_hash },
    :status => status.value,
    :attributes => attributes,
    :window => window.nil? ? nil : window.to_hash,
    :order_number => order_number
  }
end

#to_json ⇒ Object



22027
22028
22029
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22027

def to_json
  JSON.dump(to_hash)
end