Class: InPostUKAPI::Base
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- InPostUKAPI::Base
- Defined in:
- lib/inpost_uk_api/resources/base.rb
Direct Known Subclasses
Class Method Summary collapse
-
.add_retailer_prefix_option ⇒ Object
Helper to add retailer prefix option when the resource needs it.
- .retailer ⇒ Object
- .retailer=(value) ⇒ Object
- .with_account(account_hash) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes = {}, persisted = false) ⇒ Base
constructor
A new instance of Base.
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_option ⇒ Object
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 || [:retailer] = retailer super() end end |
.retailer ⇒ Object
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 with_account(account_hash) cached_retailer = retailer cached_api_token = connection.bearer_token self.retailer = account_hash[:retailer] connection.bearer_token = account_hash[:api_token] yield ensure self.retailer = cached_retailer connection.bearer_token = cached_api_token end |