class Myparcel::API::Shipments

Class for getting shipments

Public Instance Methods

all() click to toggle source
# File lib/myparcel/api/shipments.rb, line 5
def all
  find
end
create(options = {}) click to toggle source
# File lib/myparcel/api/shipments.rb, line 19
def create(options = {})
  shipment_type = options.fetch(:shipment_type, :standard)
  shipments = options.fetch(:shipments, [])
  raise 'options[:shipments] must have at least one shipment.' if shipments.empty?

  options[:headers] ||= {}
  options[:headers]['Content-Type'] = headers_for_shipment(shipment_type)

  options[:body] ||= {}
  options[:body] = JSON.generate(data: { shipments: shipments })

  response = request :post, path, options
  response['data']['ids']
end
delete(options = {}) click to toggle source
# File lib/myparcel/api/shipments.rb, line 34
def delete(options = {})
  shipment_ids = options.fetch :shipment_ids, []
  raise 'options[:shipment_ids] cannot be empty or nil' if shipment_ids.empty?

  shipment_ids = shipment_ids.join(';')
  full_path = [path, shipment_ids].join('/')

  response = request :delete, full_path, options
  response['data']
end
find(options = {}) click to toggle source
# File lib/myparcel/api/shipments.rb, line 9
def find(options = {})
  shipment_ids = options.fetch(:shipment_ids, [])
  shipment_ids = shipment_ids.join(';') if shipment_ids.is_a?(Array)

  full_path = shipment_ids.empty? ? path : [path, shipment_ids].join('/')

  response = request :get, full_path, options
  response['data']['shipments']
end
path() click to toggle source
# File lib/myparcel/api/shipments.rb, line 45
def path
  'shipments'
end