Class: Dhl::Bcs::V2::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dhl/bcs/v2/client.rb

Constant Summary collapse

WSDL =
'https://cig.dhl.de/cig-wsdls/com/dpdhl/wsdl/geschaeftskundenversand-api/2.0/geschaeftskundenversand-api-2.0.wsdl'

Instance Method Summary collapse

Constructor Details

#initialize(config, log: true, test: false, **options) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dhl/bcs/v2/client.rb', line 10

def initialize(config, log: true, test: false, **options)
  raise "User must be specified" if config[:user].nil?
  raise "Signature (password) must be specified" if config[:signature].nil?
  raise "EKP (first part of the DHL account number) must be specified" if config[:ekp].nil?
  raise "Participation Number (last two characters of account number) must be specified" if config[:participation_number].nil?
  raise "Api User must be specified" if config[:api_user].nil?
  raise "Api Password must be specified" if config[:api_pwd].nil?

  @ekp = config[:ekp]
  @participation_number = config[:participation_number]

  @logIO = StringIO.new
  @logger = log && Logger.new($stdout)

  @client = Savon.client({
    endpoint: (test ? 'https://cig.dhl.de/services/sandbox/soap' : 'https://cig.dhl.de/services/production/soap'),
    wsdl: WSDL,
    basic_auth: [config[:api_user], config[:api_pwd]],
    logger: Logger.new(@logIO),
    log: true,
    soap_header: {
      'cis:Authentification' => {
        'cis:user' => config[:user],
        'cis:signature' => config[:signature],
        'cis:type' => 0
      }
    },
    namespaces: { 'xmlns:cis' => 'http://dhl.de/webservice/cisbase' }
  })
end

Instance Method Details

#create_shipment_order(*shipments, **options) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/dhl/bcs/v2/client.rb', line 60

def create_shipment_order(*shipments, **options)
  request(:create_shipment_order, build_shipment_orders(shipments, **options)) do |response|
    [response.body[:create_shipment_order_response][:creation_state]].flatten.map do |creation_state|
      creation_state[:label_data]
    end
  end
end

#get_manifest(date) ⇒ Object

returns base64 encoded PDF Dokument



93
94
95
96
97
# File 'lib/dhl/bcs/v2/client.rb', line 93

def get_manifest(date)
  request(:get_manifest, 'manifestDate' => date) do |response|
    response.body[:get_manifest_response][:manifest_data]
  end
end

#get_version(major: 2, minor: 0, build: nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/dhl/bcs/v2/client.rb', line 41

def get_version(major: 2, minor: 0, build: nil)
  request(:get_version,
    'bcs:Version' => {
      'majorRelease' => major,
      'minorRelease' => minor
    }.tap { |h| h['build'] = build if build }
  ) do |response|
    response.body[:get_version_response][:version]
  end
end

#last_logObject



99
100
101
# File 'lib/dhl/bcs/v2/client.rb', line 99

def last_log
  @logIO.string
end

#update_shipment_order(shipment_number, shipment, **options) ⇒ Object



68
69
70
71
72
# File 'lib/dhl/bcs/v2/client.rb', line 68

def update_shipment_order(shipment_number, shipment, **options)
  request(:update_shipment_order, { 'cis:shipmentNumber' => shipment_number }.merge(build_shipment_orders([shipment], **options))) do |response|
    clean_response_data(response.body[:update_shipment_order_response][:label_data])
  end
end

#validate_shipment(*shipments, **options) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/dhl/bcs/v2/client.rb', line 52

def validate_shipment(*shipments, **options)
  request(:validate_shipment, build_shipment_orders(shipments, **options)) do |response|
    [response.body[:validate_shipment_response][:validation_state]].flatten.map do |validation_state|
      validation_state[:status]
    end
  end
end