Class: XPlanner::ModelHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers/xplanner_model_helper.rb

Direct Known Subclasses

Iteration, Person, Project, Story, Task

Constant Summary collapse

@@soap_client =
false
@@base_url =
''

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_urlObject



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

.fetch_from_remote(rpc, payload, path, my_class) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/helpers/xplanner_model_helper.rb', line 26

def self.fetch_from_remote( rpc, payload, path, my_class )
  invalid_usage unless @@soap_client
  h = @@soap_client.call( rpc, payload ).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

.invalid_usageObject



22
23
24
# File 'lib/helpers/xplanner_model_helper.rb', line 22

def self.invalid_usage
  raise 'No SoapClient initialised'
end

.parse_date(date) ⇒ Object



57
58
59
60
# File 'lib/helpers/xplanner_model_helper.rb', line 57

def self.parse_date( date )
  formatter = '%Y-%m-%eT%H:%M:%S.%LZ'
  DateTime.strptime( date, formatter )
end

.remote_delete(rpc, payload) ⇒ Object



41
42
43
44
# File 'lib/helpers/xplanner_model_helper.rb', line 41

def self.remote_delete( rpc, payload )
  invalid_usage unless @@soap_client
  @@soap_client.call( rpc, payload ).success?
end

.soap_clientObject



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

#create_payloadObject



68
69
70
# File 'lib/helpers/xplanner_model_helper.rb', line 68

def create_payload
  payload = hashify.delete_if { |key, value| [:last_update_time, :dirty_bit].include? key  }
end

#hashifyObject



62
63
64
65
66
# File 'lib/helpers/xplanner_model_helper.rb', line 62

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



46
47
48
49
50
51
52
53
54
55
# File 'lib/helpers/xplanner_model_helper.rb', line 46

def remote_update( rpc, payload )
  invalid_usage unless @@soap_client
  if @dirty_bit
    result = @@soap_client.call( rpc, payload )
    @dirty_bit = false if( result.success? )
    return result.success?
  else
    return true
  end
end