Class: DHL::Ecommerce::Account

Inherits:
Base
  • Object
show all
Includes:
Operations::Find, Operations::List
Defined in:
lib/dhl/ecommerce/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Operations::List

included

Methods included from Operations::Find

included

Constructor Details

#initialize(attributes = {}) ⇒ Account

Returns a new instance of Account.



9
10
11
12
13
14
15
16
# File 'lib/dhl/ecommerce/account.rb', line 9

def initialize(attributes = {})
  super attributes

  unless attributes.empty?
    @id = attributes[:account].to_i if attributes[:account]
    @address = StandardAddress.new attributes
  end
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



7
8
9
# File 'lib/dhl/ecommerce/account.rb', line 7

def address
  @address
end

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'lib/dhl/ecommerce/account.rb', line 7

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/dhl/ecommerce/account.rb', line 7

def id
  @id
end

Instance Method Details

#locationsObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/dhl/ecommerce/account.rb', line 18

def locations
        response = DHL::Ecommerce.request :get, "https://api.dhlglobalmail.com/v1/#{self.resource_name.downcase}s/#{id}/#{DHL::Ecommerce::Location.resource_name.downcase}s"
        response[self.resource_name]["#{DHL::Ecommerce::Location.resource_name}s"][DHL::Ecommerce::Location.resource_name] = [response[self.resource_name]["#{DHL::Ecommerce::Location.resource_name}s"][DHL::Ecommerce::Location.resource_name]] unless response[self.resource_name]["#{DHL::Ecommerce::Location.resource_name}s"][DHL::Ecommerce::Location.resource_name].is_a? Array

        response[self.resource_name]["#{DHL::Ecommerce::Location.resource_name}s"].map do |attributes|
    location = DHL::Ecommerce::Location.new attributes
    location.instance_variable_set :@account, self
    location
  end
end