Class: Io::Flow::V0::Clients::Manifests

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Manifests

Returns a new instance of Manifests.



4279
4280
4281
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4279

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

Instance Method Details

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



4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4283

def get(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) }),
    :carrier_tracking_number => (x = opts.delete(:carrier_tracking_number); x.nil? ? nil : HttpClient::Preconditions.assert_class('carrier_tracking_number', x, Array).map { |v| HttpClient::Preconditions.assert_class('carrier_tracking_number', v, String) }),
    :flow_tracking_number => (x = opts.delete(:flow_tracking_number); x.nil? ? nil : HttpClient::Preconditions.assert_class('flow_tracking_number', x, Array).map { |v| HttpClient::Preconditions.assert_class('flow_tracking_number', v, String) }),
    :service => (x = opts.delete(:service); x.nil? ? nil : HttpClient::Preconditions.assert_class('service', x, Array).map { |v| HttpClient::Preconditions.assert_class('service', 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)}/manifests").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Manifest.new(x) }
end

#get_by_id(organization, id) ⇒ Object



4325
4326
4327
4328
4329
4330
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4325

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

#get_services_and_outstanding_by_service(organization, service) ⇒ Object

Generates a new manifest with all outstanding labels and redirects to a downloadable PDF of carrier-generated manifest or bill of lading (BOL). If no outstanding labels, this will generate a 422 error.



4318
4319
4320
4321
4322
4323
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4318

def get_services_and_outstanding_by_service(organization, service)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('service', service, String)
  r = @client.request("/#{CGI.escape(organization)}/manifests/services/#{CGI.escape(service)}/outstanding").get
  r
end

#post(organization, manifest_form) ⇒ Object

Creates a new manifest/carrier BOL with specific tracking numbers



4300
4301
4302
4303
4304
4305
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4300

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

#post_bridge(organization, bridge_manifest_form) ⇒ Object

Generates manifest/carrier BOL’s from order numbers for Global-e bridge



4308
4309
4310
4311
4312
4313
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4308

def post_bridge(organization, bridge_manifest_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = bridge_manifest_form; x.is_a?(::Io::Flow::V0::Models::BridgeManifestForm) ? x : ::Io::Flow::V0::Models::BridgeManifestForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/manifests/bridge").with_json(bridge_manifest_form.to_json).post
  r.map { |x| ::Io::Flow::V0::Models::BridgeManifest.new(x) }
end