Class: SK::SDK::Base

Inherits:
ActiveResource::Base show all
Defined in:
lib/sk_sdk/base.rb

Defined Under Namespace

Classes: SkCollection

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveResource::Base

#load_attributes_from_response

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



21
22
23
24
# File 'lib/sk_sdk/base.rb', line 21

def initialize(attributes = {}, *args)
  attr = attributes[self.class.element_name] || attributes
  super(attr, *args)
end

Class Method Details

.headersObject

If headers are not defined in a given subclass, then obtain headers from the superclass.



55
56
57
58
59
60
61
62
63
# File 'lib/sk_sdk/base.rb', line 55

def self.headers
  if defined?(@headers)
    @headers
  elsif superclass != Object && superclass.headers
    superclass.headers
  else
    @headers ||= {}
  end
end

.set_connection(opts) ⇒ Object

Define the connection to be used when talking to a salesking server

@param opts

Parameters:

  • [String] (Hash)

    a customizable set of options



42
43
44
45
46
47
48
49
50
51
# File 'lib/sk_sdk/base.rb', line 42

def self.set_connection(opts)
  self.site   = site_api_url(opts[:site])
  self.format = :json
  if opts[:token] #oAuth access token in header
    self.headers['Authorization'] = "Bearer #{opts[:token]}"
  else
    self.user     = opts[:user]
    self.password = opts[:password]
  end
end

Instance Method Details

#saveObject



32
# File 'lib/sk_sdk/base.rb', line 32

def save; save_with_validation; end