class Novaposhta2::Package

Represents a package.

Options

cost

Mandatory. Cost of the package contents, for insurance needs.

description

Mandatory. Description of package contents.

internal_number

Internal order number.

payer_type

Sender of Recipient. Default: Sender.

payment_method

Cash or NonCash. Default: Cash.

seats

Number of boxes. Default: 1.

volume

Mandatory. Volume of the package in cm

weight

Mandatory. Weight of the package in kg.

Public Class Methods

track(tracking) click to toggle source

Get tracking information by tracking number.

# File lib/novaposhta2/package.rb, line 47
def self.track(tracking)
  post('InternetDocument', 'documentsTracking', Documents: [tracking.to_s])['data'][0]
end

Public Instance Methods

print() click to toggle source

Print package markings.

rate() click to toggle source

Get the shipping rate.

# File lib/novaposhta2/package.rb, line 24
def rate
  post('InternetDocument', 'getDocumentPrice', params)['data'][0]['Cost'].to_i
end
save() click to toggle source

Commit the package.

# File lib/novaposhta2/package.rb, line 29
def save
  data = post('InternetDocument', 'save', params)

  @ref = data['data'][0]['Ref']
  @tracking = data['data'][0]['IntDocNumber']
end
track() click to toggle source

Get package tracking information.

# File lib/novaposhta2/package.rb, line 42
def track
  self.class.track(@tracking)
end

Private Instance Methods

params() click to toggle source
# File lib/novaposhta2/package.rb, line 53
def params
  {
      DateTime: (options[:date] || Time.now).strftime('%d.%m.%Y'),
      ServiceType: 'WarehouseWarehouse',
      Sender: config.sender['ref'],
      CitySender: config.sender['city'],
      SenderAddress: config.sender['address'],
      ContactSender: config.sender['contact'],
      SendersPhone: config.sender['phone'],
      Recipient: @recipient.ref,
      CityRecipient: @recipient.city.ref,
      RecipientAddress: @address.ref,
      ContactRecipient: @recipient.contact_ref,
      RecipientsPhone: @recipient.phone,
      PaymentMethod: :Cash || options[:payment_method],
      PayerType: :Sender || options[:payer_type],
      Cost: options[:cost],
      SeatsAmount: 1 || options[:seats],
      Description: options[:description],
      CargoType: 'Cargo',
      Weight: options[:weight],
      VolumeGeneral: options[:volume] || options[:width] * options[:height] * options[:depth],
      InfoRegClientBarcodes: options[:internal_number]
  }
end