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.



66132
66133
66134
66135
66136
66137
66138
66139
66140
66141
66142
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66132

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :labels, :status, :attributes, :url], '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 }
  @url = HttpClient::Preconditions.assert_class('url', opts.delete(:url), String)
  @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

#attributesObject (readonly)

Returns the value of attribute attributes.



66130
66131
66132
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66130

def attributes
  @attributes
end

#idObject (readonly)

Returns the value of attribute id.



66130
66131
66132
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66130

def id
  @id
end

#labelsObject (readonly)

Returns the value of attribute labels.



66130
66131
66132
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66130

def labels
  @labels
end

#order_numberObject (readonly)

Returns the value of attribute order_number.



66130
66131
66132
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66130

def order_number
  @order_number
end

#statusObject (readonly)

Returns the value of attribute status.



66130
66131
66132
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66130

def status
  @status
end

#urlObject (readonly)

Returns the value of attribute url.



66130
66131
66132
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66130

def url
  @url
end

#windowObject (readonly)

Returns the value of attribute window.



66130
66131
66132
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66130

def window
  @window
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



66148
66149
66150
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66148

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

#to_hashObject



66152
66153
66154
66155
66156
66157
66158
66159
66160
66161
66162
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66152

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

#to_jsonObject



66144
66145
66146
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66144

def to_json
  JSON.dump(to_hash)
end