Class: Tick::Base
- Inherits:
-
Object
- Object
- Tick::Base
- Defined in:
- lib/tick/base.rb
Instance Attribute Summary collapse
-
#api_name ⇒ Object
readonly
Returns the value of attribute api_name.
-
#api_path ⇒ Object
readonly
Returns the value of attribute api_path.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#api_name ⇒ Object (readonly)
Returns the value of attribute api_name.
33 34 35 |
# File 'lib/tick/base.rb', line 33 def api_name @api_name end |
#api_path ⇒ Object (readonly)
Returns the value of attribute api_path.
33 34 35 |
# File 'lib/tick/base.rb', line 33 def api_path @api_path end |
#created_at ⇒ Object
Returns the value of attribute created_at.
32 33 34 |
# File 'lib/tick/base.rb', line 32 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
32 33 34 |
# File 'lib/tick/base.rb', line 32 def id @id end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
32 33 34 |
# File 'lib/tick/base.rb', line 32 def updated_at @updated_at end |
Class Method Details
.api_name ⇒ Object
43 44 45 |
# File 'lib/tick/base.rb', line 43 def self.api_name self.to_s.split('::').last.downcase end |
.api_path ⇒ Object
47 48 49 |
# File 'lib/tick/base.rb', line 47 def self.api_path "/api/#{api_name}s" end |
.list(options = {}, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tick/base.rb', line 51 def self.list(={}, &block) url = "https://#{current_session.company}.tickspot.com#{api_path}" params = authentication_params.merge!() request_manager.GET(url, parameters:params, success:lambda{|operation, result| objects = [] # Parse XML error = Pointer.new(:object) xml = GDataXMLDocument.alloc.initWithXMLString(result.to_s, error:error) # Create the objects error = Pointer.new(:object) xml_nodes = xml.nodesForXPath("//#{api_name}", error:error) xml_nodes.each do |xml_node| object = new object.set_properties_from_xml_node(xml_node) objects << object end block.call(objects) if block }, failure:lambda{|operation, error| block.call(error) if block }) self end |
Instance Method Details
#set_properties_from_xml_node(xml_node) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/tick/base.rb', line 35 def set_properties_from_xml_node(xml_node) self.class::XML_PROPERTIES.each do |property| xml_elements = xml_node.elementsForName(property) value = xml_elements ? get_xml_element_value(xml_elements.first) : nil self.send("#{property}=", value) end end |