Class: Io::Flow::V0::Clients::Trackings

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Trackings

Returns a new instance of Trackings.



5046
5047
5048
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5046

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#get_trackings_and_versions_by_organization(organization, incoming = {}) ⇒ Object



5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5078

def get_trackings_and_versions_by_organization(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
    :tracking_id => (x = opts.delete(:tracking_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('tracking_id', x, Array).map { |v| HttpClient::Preconditions.assert_class('tracking_id', v, String) }),
    :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
    :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
    :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/trackings/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::TrackingVersion.new(x) }
end

#get_trackings_by_id(id) ⇒ Object

Public endpoint to get all relevant information about a tracking, label(s) under it, and event(s) under those label(s)



5052
5053
5054
5055
5056
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5052

def get_trackings_by_id(id)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/trackings/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::Tracking.new(r)
end

#get_trackings_by_organization(organization, incoming = {}) ⇒ Object



5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5058

def get_trackings_by_organization(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
    :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
    :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
    :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/trackings").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Tracking.new(x) }
end

#post_trackings_by_organization(organization, tracking_form) ⇒ Object



5071
5072
5073
5074
5075
5076
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5071

def post_trackings_by_organization(organization, tracking_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = tracking_form; x.is_a?(::Io::Flow::V0::Models::TrackingForm) ? x : ::Io::Flow::V0::Models::TrackingForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/trackings").with_json(tracking_form.to_json).post
  ::Io::Flow::V0::Models::Tracking.new(r)
end