Module: DHL::Ecommerce

Defined in:
lib/dhl-ecommerce.rb,
lib/dhl/ecommerce/base.rb,
lib/dhl/ecommerce/impb.rb,
lib/dhl/ecommerce/event.rb,
lib/dhl/ecommerce/label.rb,
lib/dhl/ecommerce/account.rb,
lib/dhl/ecommerce/product.rb,
lib/dhl/ecommerce/version.rb,
lib/dhl/ecommerce/location.rb,
lib/dhl/ecommerce/manifest.rb,
lib/dhl/ecommerce/tracked_event.rb,
lib/dhl/ecommerce/operations/find.rb,
lib/dhl/ecommerce/operations/list.rb,
lib/dhl/ecommerce/standard_address.rb,
lib/dhl/ecommerce/errors/base_error.rb,
lib/dhl/ecommerce/errors/validation_error.rb,
lib/dhl/ecommerce/errors/authentication_error.rb

Defined Under Namespace

Modules: Errors, Operations Classes: Account, Base, Event, Impb, Label, Location, Manifest, Product, StandardAddress, TrackedEvent

Constant Summary collapse

VERSION =
"1.0.5"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject



50
51
52
53
# File 'lib/dhl-ecommerce.rb', line 50

def self.access_token
  # TODO This needs better error handling.
  @access_token ||= client.get("https://api.dhlglobalmail.com/v1/auth/access_token", username: @username, password: @password, state: Time.now.to_i).body.response.data[:access_token]
end

.client_idObject

Returns the value of attribute client_id.



42
43
44
# File 'lib/dhl-ecommerce.rb', line 42

def client_id
  @client_id
end

.label_formatObject

Returns the value of attribute label_format.



42
43
44
# File 'lib/dhl-ecommerce.rb', line 42

def label_format
  @label_format
end

.password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



43
44
45
# File 'lib/dhl-ecommerce.rb', line 43

def password=(value)
  @password = value
end

.username=(value) ⇒ Object (writeonly)

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



43
44
45
# File 'lib/dhl-ecommerce.rb', line 43

def username=(value)
  @username = value
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



45
46
47
# File 'lib/dhl-ecommerce.rb', line 45

def configure
  yield self
end

.request(method, url, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dhl-ecommerce.rb', line 55

def self.request(method, url, &block)
  client.params = {
    access_token: self.access_token,
    client_id: client_id
  }

  response = client.run_request method.downcase.to_sym, url, nil, nil, &block

  case response.status
  when 400
    case response.body.response.meta.error.error_type
    when "INVALID_CLIENT_ID", "INVALID_KEY", "INVALID_TOKEN", "INACTIVE_KEY"
      raise Errors::AuthenticationError.new response.body.response.meta.error.error_message, response
    when "VALIDATION_ERROR", "INVALID_FACILITY_CODE"
      errors = response.body.response.data.mpu_list.mpu.error_list.error
      errors = [errors] unless errors.is_a? Array

      raise Errors::ValidationError.new response.body.response.meta.error.error_message, response, errors
    else
      raise Errors::BaseError.new response.body.response.meta.error.error_message, response
    end
  end

  response.body.response.data
end