Class: Postat

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePostat

Returns a new instance of Postat.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/postat.rb', line 8

def initialize
  @client = Savon.client(wsdl: POSTAT_CONFIG[:wsdl],
                         convert_request_keys_to: :none,
                         env_namespace: :soapenv,
                         namespace_identifier: :post,
                         log: true,
                         pretty_print_xml: true,
                         endpoint: POSTAT_CONFIG[:endpoint],
                         namespaces: {
                           'xmlns:post' => 'http://post.ondot.at',
                           'xmlns:arr'  => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays',
                           'xmlns:core' => 'http://Core.Model',
                           'xmlns:ser'  => 'http://schemas.microsoft.com/2003/10/Serialization/'
                         }
  )
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/postat.rb', line 6

def client
  @client
end

Instance Method Details

#delete_label(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/postat.rb', line 25

def delete_label(options = {})
  message = []
  options[:shipments]&.each do |shipment|
    row = init_message
    row['post:Number'] = shipment[:reference_number]
    add_common_params(row)
    message<< { 'post:CancelShipmentRow' => row }
  end
  response = client.call(:cancel_shipments, message: { 'post:shipments' => message })
  handle_response(response, action: :cancel_shipments)
end

#generate_label(options = {}) ⇒ Object

NOTE: be careful with the order of attributes to avoid fake missing attribute errors



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/postat.rb', line 38

def generate_label(options = {})
  message = init_message
  message['post:DeliveryServiceThirdPartyID'] = options[:delivery_code]
  message['post:Number'] = options[:reference_number]
  message['post:ColloList'] = add_packages(options[:package])
  # message['post:ShippingDateTimeFrom'] = (Time.zone.now + 180).iso8601
  message['post:OURecipientAddress'] = add_address(options[:to])
  message['post:OUShipperAddress'] = add_address(options[:from])
  add_common_params(message)
  message['post:PrinterObject'] = add_printing_details
  # TODO: Look for the new attrs names for: PaymentType, Commodities

  response = client.call(:import_shipment, message: { 'post:row' => message })
  handle_response response
end