Class: DHLEcommerceEU::ShipmentResource

Inherits:
BaseResource show all
Defined in:
lib/dhl_ecommerce_eu/resources/shipment_resource.rb

Instance Attribute Summary

Attributes inherited from BaseResource

#client

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from DHLEcommerceEU::BaseResource

Instance Method Details

#create(params: { generateLabel: true, labelFormat: 'pdf', labelSize: '10x15' }, **attributes) ⇒ Shipment

Create a shipment

Example for return connect {

  "dataElement": {
    "parcelOriginOrganization": 'IT',
    "parcelDestinationOrganization": 'NL',
    "general": {
      "timestamp": '2022-07-01T13:05:05Z',
      "product": 'ParcelEurope.return.network'
    },
    "cPAN": {
      "addresses": {
        "sender": [
          {
            "type": 'default',
            "name": 'Tiziana Test',
            "additionalName": 'Buying Tests',
            "email": '[email protected]',
            "street1": 'Teststrada 10',
            "postcode": '20123',
            "city": 'Milan',
            "country": 'IT',
            "customerIdentification": '5012345678', # The owner DHL account number
            "customerAccountNr1": '1234567890' # The owner DHL account number
          }
        ],
        "recipient": [
          {
            "type": 'doorstep',
            "name": 'Thijs Testbedrijf',
            "email": '[email protected]',
            "street1": 'Teststraat 10',
            "postcode": '9737 PE',
            "city": 'Groningen',
            "country": 'NL'
          }
        ]
      },
      "features": {
        "physical": {
          "grossWeight": '1.0',
          "length": '0.2',
          "height": '0.2',
          "width": '0.3'
        }
      }
    }
  }
}

Parameters:

  • params (Hash) (defaults to: { generateLabel: true, labelFormat: 'pdf', labelSize: '10x15' })

    params default: { generateLabel: true, labelFormat: ‘pdf’, labelSize: ‘10x15’ }

  • **attributes (Hash)

    attributes

Returns:



60
61
62
63
64
65
66
67
68
69
# File 'lib/dhl_ecommerce_eu/resources/shipment_resource.rb', line 60

def create(params: { generateLabel: true, labelFormat: 'pdf', labelSize: '10x15' }, **attributes)
  response = post_request('ccc/send-cpan', params: params, body: attributes)
  case response.headers['Content-Type']
  when 'application/pdf'
    Shipment.new id: response.headers['shipmentId'], label_blob: response.body.to_s
  when 'application/json'
    payload = response.parse
    raise Error, "Your request was malformed. #{payload['error']}" if payload['error']
  end
end