Class: XPlanner::ModelHelper
- Inherits:
-
Object
- Object
- XPlanner::ModelHelper
show all
- Defined in:
- lib/helpers/xplanner_model_helper.rb
Constant Summary
collapse
- @@soap_client =
false
- @@base_url =
''
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.base_url ⇒ Object
18
19
20
|
# File 'lib/helpers/xplanner_model_helper.rb', line 18
def self.base_url
@@base_url
end
|
.base_url=(url) ⇒ Object
14
15
16
|
# File 'lib/helpers/xplanner_model_helper.rb', line 14
def self.base_url=( url )
@@base_url = url
end
|
.check_client_initialised ⇒ Object
22
23
24
|
# File 'lib/helpers/xplanner_model_helper.rb', line 22
def self.check_client_initialised
raise 'No SoapClient initialised' unless XPlanner.connection?
end
|
.fetch_from_remote(rpc, payload, path, my_class) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/helpers/xplanner_model_helper.rb', line 30
def self.fetch_from_remote( rpc, payload, path, my_class )
check_client_initialised
r = @@soap_client.call( rpc, payload )
return nil if r.nil?
h = r.decode_soap_response( path )
if h.class == Array
results = h.collect { |thing| my_class.new( thing ) }
elsif h.class == Hash
if h.has_key? :id
results = my_class.new( h )
else
results = nil
end
end
results
end
|
.parse_date(date) ⇒ Object
66
67
68
69
|
# File 'lib/helpers/xplanner_model_helper.rb', line 66
def self.parse_date( date )
formatter = '%Y-%m-%eT%H:%M:%S.%LZ'
DateTime.strptime( date, formatter )
end
|
.remote_delete(rpc, payload) ⇒ Object
50
51
52
53
|
# File 'lib/helpers/xplanner_model_helper.rb', line 50
def self.remote_delete( rpc, payload )
check_client_initialised
@@soap_client.call( rpc, payload ).success?
end
|
.soap_client ⇒ Object
10
11
12
|
# File 'lib/helpers/xplanner_model_helper.rb', line 10
def self.soap_client
@@soap_client
end
|
.soap_client=(client) ⇒ Object
6
7
8
|
# File 'lib/helpers/xplanner_model_helper.rb', line 6
def self.soap_client=( client )
@@soap_client = client
end
|
Instance Method Details
#check_client_initialised ⇒ Object
26
27
28
|
# File 'lib/helpers/xplanner_model_helper.rb', line 26
def check_client_initialised
raise 'No SoapClient initialised' unless XPlanner.connection?
end
|
#create_payload ⇒ Object
77
78
79
|
# File 'lib/helpers/xplanner_model_helper.rb', line 77
def create_payload
payload = hashify.delete_if { |key, value| [:last_update_time, :dirty_bit].include? key }
end
|
#hashify ⇒ Object
71
72
73
74
75
|
# File 'lib/helpers/xplanner_model_helper.rb', line 71
def hashify
out = {}
instance_variables.each { |var| out[var.to_s.gsub(/@/, '').to_sym] = instance_variable_get(var) }
out
end
|
#remote_update(rpc, payload) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/helpers/xplanner_model_helper.rb', line 55
def remote_update( rpc, payload )
check_client_initialised
if @dirty_bit
result = @@soap_client.call( rpc, payload )
@dirty_bit = false if( result.success? )
return result.success?
else
return true
end
end
|