Class: SendleAPI::Base

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

Direct Known Subclasses

Address, Contact, Order, Product, Receiver, Sender, Tracking, Volume, Weight

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.



12
13
14
15
16
17
# File 'lib/sendle_api/resources/base.rb', line 12

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

Class Method Details

.basic_auth_detailsObject



53
54
55
# File 'lib/sendle_api/resources/base.rb', line 53

def basic_auth_details
  "#{SendleAPI.config.sendle_id}:#{SendleAPI.config.api_key}"
end

.set_siteObject



45
46
47
48
49
50
51
# File 'lib/sendle_api/resources/base.rb', line 45

def set_site
  self.site = if SendleAPI.config.testing?
    "https://#{basic_auth_details}@sandbox.sendle.com"
  else
    "https://#{basic_auth_details}@api.sendle.com"
  end
end

.validate_configsObject



57
58
59
60
61
62
63
64
65
# File 'lib/sendle_api/resources/base.rb', line 57

def validate_configs
  unless SendleAPI.config.sendle_id
    raise ArgumentError, "SendleAPI sendle_id is missing, please set it in the config and restart."
  end

  unless SendleAPI.config.api_key
    raise ArgumentError, "SendleAPI api_key is missing, please set it in the config and restart."
  end
end

Instance Method Details

#errorsObject



24
25
26
# File 'lib/sendle_api/resources/base.rb', line 24

def errors
  @errors ||= Errors.new(self)
end

#saveObject



19
20
21
22
# File 'lib/sendle_api/resources/base.rb', line 19

def save
  self.class.validate_configs
  super
end