Class: InPostUKAPI::Base

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

Direct Known Subclasses

Return, ReturnLabel

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.



51
52
53
54
# File 'lib/inpost_uk_api/resources/base.rb', line 51

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

Class Method Details

.add_retailer_prefix_optionObject

Helper to add retailer prefix option when the resource needs it



32
33
34
35
36
37
# File 'lib/inpost_uk_api/resources/base.rb', line 32

def add_retailer_prefix_option
  define_singleton_method('check_prefix_options') do |prefix_options|
    prefix_options[:retailer] = retailer
    super(prefix_options)
  end
end

.retailerObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/inpost_uk_api/resources/base.rb', line 11

def retailer
  if superclass == ActiveResource::Base
    if _retailer_defined?
      _retailer
    else
      _retailer = InPostUKAPI.config.retailer
    end
  else
    superclass.retailer
  end
end

.retailer=(value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/inpost_uk_api/resources/base.rb', line 23

def retailer=(value)
  if superclass == ActiveResource::Base
    self._retailer = value
  else
    superclass.retailer = value
  end
end

.with_account(account_hash) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/inpost_uk_api/resources/base.rb', line 39

def ()
  cached_retailer = retailer
  cached_api_token = connection.bearer_token
  self.retailer = [:retailer]
  connection.bearer_token = [:api_token]
  yield
ensure
  self.retailer = cached_retailer
  connection.bearer_token = cached_api_token
end