Class: DHLAPI::RetoureClient

Inherits:
BaseClient show all
Defined in:
lib/dhl_api/clients/retoure_client.rb

Constant Summary collapse

URL =
'https://api-eu.dhl.com/parcel/de/shipping/returns/v1/orders'
TEST_URL =
'https://api-sandbox.dhl.com/parcel/de/shipping/returns/v1/orders'

Instance Attribute Summary collapse

Attributes inherited from BaseClient

#http_client, #response

Instance Method Summary collapse

Constructor Details

#initialize(username: nil, password: nil, label_type: 'BOTH') ⇒ RetoureClient

Returns a new instance of RetoureClient.



6
7
8
9
10
# File 'lib/dhl_api/clients/retoure_client.rb', line 6

def initialize(username: nil, password: nil, label_type: 'BOTH')
  @username = username
  @password = password
  @label_type = label_type
end

Instance Attribute Details

#label_typestring #label_type=(value) ⇒ Object

Overloads:

  • #label_typestring

    Read the label type. Default to ‘BOTH’

    Returns:

    • (string)

      The label type you will to receive

  • #label_type=(value) ⇒ Object

    Parameters:

    • value (String)

      possible values: ‘BOTH’, ‘SHIPMENT_LABEL’, ‘QR_LABEL’



17
18
19
# File 'lib/dhl_api/clients/retoure_client.rb', line 17

def label_type
  @label_type
end

Instance Method Details

#connectionObject



25
26
27
# File 'lib/dhl_api/clients/retoure_client.rb', line 25

def connection
  super.basic_auth(user: username, pass: password)
end

#create_label(attributes = {}) ⇒ Object



19
20
21
22
23
# File 'lib/dhl_api/clients/retoure_client.rb', line 19

def create_label(attributes = {})
  payload = attributes.deep_transform_keys { |key| key.to_s.camelize(:lower) }
  self.response = connection.post(url, json: payload, params: { labelType: label_type })
  RetoureLabel.new handle_response.parse
end