Class: Wesabe::Model::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/wesabe/model/base.rb

Direct Known Subclasses

Account, Institution, Merchant, Txaction

Constant Summary collapse

@@user =
nil
@@password =
nil
@@content_type =
Wesabe::API_DEFAULT_CONTENT_TYPE
@@api =
resource
@@api_cache =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Base



38
39
40
# File 'lib/wesabe/model/base.rb', line 38

def initialize(xml)
  @xml = xml
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



22
23
24
# File 'lib/wesabe/model/base.rb', line 22

def xml
  @xml
end

Class Method Details

.configure(opts = {}) ⇒ Object



24
25
26
27
28
29
# File 'lib/wesabe/model/base.rb', line 24

def self.configure(opts={})
  @@user = opts[:user]
  @@password = opts[:password]
  @@content_type = opts[:content_type] if opts[:content_type] && Wesabe::API_CONTENT_TYPES.include?(opts[:content_type])
  @@api = resource
end

.find(path, xpath) ⇒ Object



31
32
33
# File 'lib/wesabe/model/base.rb', line 31

def self.find(path, xpath)
  new(get_xml(path).xpath(xpath))
end

.find_collection(path, xpath) ⇒ Object



34
35
36
# File 'lib/wesabe/model/base.rb', line 34

def self.find_collection(path, xpath)
  get_xml(path).xpath(xpath).collect{|item_xml| new(item_xml)}
end

.resourceObject



16
17
18
# File 'lib/wesabe/model/base.rb', line 16

def self.resource
  RestClient::Resource.new(Wesabe::API_SITE, :user => @@user, :password => @@password, :content_type => @@content_type)
end