Class: Saasu::Base
- Inherits:
-
Object
- Object
- Saasu::Base
- Defined in:
- lib/saasu/base.rb
Direct Known Subclasses
Constant Summary collapse
- ENDPOINT =
"https://secure.saasu.com/webservices/rest/r1"
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
Returns all resources matching the supplied conditions.
-
.api_key ⇒ Object
Return the API key.
- .api_key=(key) ⇒ Object
-
.defaults(options = nil) ⇒ Object
Allows defaults for the object to be set.
-
.file_uid ⇒ Object
Returns the file_uid.
- .file_uid=(uid) ⇒ Object
-
.find(uid) ⇒ Object
Finds a specific resource by its uid.
Instance Method Summary collapse
-
#initialize(xml) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(xml) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/saasu/base.rb', line 7 def initialize(xml) klass = self.class.name.split("::")[1].downcase xml.children.each do |child| if !child.text? child.attributes.each do |attr| send("#{attr[1].name.underscore.sub(/#{klass}_/, "")}=", attr[1].text) end send("#{child.name.underscore.sub(/#{klass}_/, "")}=", child.children.first.text) unless child.children.first.nil? end end end |
Class Method Details
.all(options = {}) ⇒ Object
Returns all resources matching the supplied conditions
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/saasu/base.rb', line 50 def all( = {}) response = get() xml = Nokogiri::XML(response).css("#{defaults[:collection_name]}") collection = xml.inject([]) do |result, item| result << new(item) result end collection end |
.api_key ⇒ Object
Return the API key
31 32 33 |
# File 'lib/saasu/base.rb', line 31 def api_key @@api_key end |
.api_key=(key) ⇒ Object
25 26 27 |
# File 'lib/saasu/base.rb', line 25 def api_key=(key) @@api_key = key end |
.defaults(options = nil) ⇒ Object
Allows defaults for the object to be set. Generally the class name will be suitable and options will not need to be provided
74 75 76 77 78 79 80 81 |
# File 'lib/saasu/base.rb', line 74 def defaults( = nil) @defaults ||= if @defaults = .merge!() else @defaults end end |
.file_uid ⇒ Object
Returns the file_uid
43 44 45 |
# File 'lib/saasu/base.rb', line 43 def file_uid @@file_uid end |
.file_uid=(uid) ⇒ Object
37 38 39 |
# File 'lib/saasu/base.rb', line 37 def file_uid=(uid) @@file_uid = uid end |
.find(uid) ⇒ Object
Finds a specific resource by its uid
64 65 66 67 68 |
# File 'lib/saasu/base.rb', line 64 def find(uid) response = get({:uid => uid}, false) xml = Nokogiri::XML(response).css("#{defaults[:resource_name]}") new(xml.first) end |