Class: HermesAPI::Base

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/hermes_api/resources/base.rb

Direct Known Subclasses

DropOffReturnLabel, PickupReturnLabel

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, persisted = false) ⇒ Base

Returns a new instance of Base.



25
26
27
28
29
30
# File 'lib/hermes_api/resources/base.rb', line 25

def initialize(attributes = {}, persisted = false)
  if defined?(self.class::DEFAULT_ATTRS)
    attributes = self.class::DEFAULT_ATTRS.merge(attributes)
  end
  super
end

Class Method Details

.rootObject



10
11
12
# File 'lib/hermes_api/resources/base.rb', line 10

def root
  nil
end

.with_session(user, password) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/hermes_api/resources/base.rb', line 14

def with_session(user, password)
  existing_user = self.user
  existing_password = self.password
  self.user = user
  self.password = password
  yield
  self.user = existing_user
  self.password = existing_password
end

Instance Method Details

#load(attributes, remove_root = false, persisted = false) ⇒ Object



32
33
34
35
# File 'lib/hermes_api/resources/base.rb', line 32

def load(attributes, remove_root = false, persisted = false)
  attributes.deep_transform_keys! { |k| k.to_s.underscore }
  super
end

#to_xml(options = {}) ⇒ Object



37
38
39
# File 'lib/hermes_api/resources/base.rb', line 37

def to_xml(options = {})
  super({root: self.class.root, camelize: :lower}.merge(options))
end