Class: Tick::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/tick/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#api_name ⇒ Object
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
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
|
.authentication_params ⇒ Object
121
122
123
124
125
126
|
# File 'lib/tick/base.rb', line 121
def self.authentication_params
{
email: current_session.email,
password: current_session.password
}
end
|
.current_session ⇒ Object
128
129
130
131
132
133
134
|
# File 'lib/tick/base.rb', line 128
def self.current_session
if Session.current
Session.current
else
raise AuthenticationError.new("User is not logged in.")
end
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(options={}, &block)
url = "https://#{current_session.company}.tickspot.com#{api_path}"
params = authentication_params.merge!(options)
request_manager.GET(url, parameters:params, success:lambda{|operation, result|
objects = []
error = Pointer.new(:object)
xml = GDataXMLDocument.alloc.initWithXMLString(result.to_s, error:error)
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
|
.request_manager ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/tick/base.rb', line 136
def self.request_manager
manager = AFHTTPRequestOperationManager.manager
request_serializer = AFHTTPRequestSerializer.serializer
request_serializer.setValue("application/xml", forHTTPHeaderField:"Content-type")
manager.requestSerializer = request_serializer
response_serializer = AFHTTPResponseSerializer.serializer
response_serializer.acceptableContentTypes = NSSet.setWithObjects("application/xml", nil)
manager.responseSerializer = response_serializer
manager
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
|