Class: SysAid::Activity

Inherits:
Object
  • Object
show all
Defined in:
lib/sysaid/activity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActivity

Returns a new instance of Activity.



6
7
8
# File 'lib/sysaid/activity.rb', line 6

def initialize
  reset_all_attributes
end

Instance Attribute Details

#ciidObject

Returns the value of attribute ciid.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def ciid
  @ciid
end

#cust_int1Object

Returns the value of attribute cust_int1.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def cust_int1
  @cust_int1
end

#cust_int2Object

Returns the value of attribute cust_int2.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def cust_int2
  @cust_int2
end

#cust_int3Object

Returns the value of attribute cust_int3.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def cust_int3
  @cust_int3
end

#cust_int4Object

Returns the value of attribute cust_int4.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def cust_int4
  @cust_int4
end

#cust_list1Object

Returns the value of attribute cust_list1.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def cust_list1
  @cust_list1
end

#cust_list2Object

Returns the value of attribute cust_list2.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def cust_list2
  @cust_list2
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def description
  @description
end

#from_timeObject

Returns the value of attribute from_time.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def from_time
  @from_time
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def id
  @id
end

#sr_idObject

Returns the value of attribute sr_id.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def sr_id
  @sr_id
end

#to_timeObject

Returns the value of attribute to_time.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def to_time
  @to_time
end

#userObject

Returns the value of attribute user.



4
5
6
# File 'lib/sysaid/activity.rb', line 4

def user
  @user
end

Class Method Details

.find_by_id(activity_id) ⇒ Object

Returns a specific Activity based on an Activity ID



42
43
44
45
46
47
48
49
50
# File 'lib/sysaid/activity.rb', line 42

def self.find_by_id(activity_id)
  activity = SysAid::Activity.new

  activity.id = activity_id

  return nil unless activity.refresh

  return activity
end

.find_by_ticket_id(ticket_id) ⇒ Object

Returns an array of Activity IDs based on ticket_id. Returns false on error.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sysaid/activity.rb', line 29

def self.find_by_ticket_id(ticket_id)
  SysAid.ensure_logged_in

  response = SysAid.call(:execute_select_query, message: sql_query(" service_req_id = #{ticket_id}"))

  if response.to_hash[:execute_select_query_response][:return]
    return response.to_hash[:execute_select_query_response][:return]
  end

  return false
end

Instance Method Details

#deleteObject

Deletes an activity from the SysAid server

No return value as SysAid’s ‘delete’ call returns void. No idea why.

Example:

>> activity_object.delete
=> true


92
93
94
95
96
97
98
# File 'lib/sysaid/activity.rb', line 92

def delete
  SysAid.ensure_logged_in
  
  SysAid.call(:delete, message: to_xml(false))

  reset_all_attributes
end

#refreshObject

Loads the latest ticket information from the SysAid server



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sysaid/activity.rb', line 53

def refresh
  SysAid.ensure_logged_in

  response = SysAid.call(:load_by_string_id, message: to_xml)

  if response.to_hash[:load_by_string_id_response][:return]
    set_self_from_response(response.to_hash[:load_by_string_id_response][:return])
    return true
  end

  return false
end

#reset_all_attributesObject

Needed by both initialize and delete (to empty out the object when deleted)



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sysaid/activity.rb', line 11

def reset_all_attributes
  self.ciid = nil
  self.cust_int1 = nil
  self.cust_int2 = nil
  self.cust_int3 = nil
  self.cust_int4 = nil
  self.cust_list1 = nil
  self.cust_list2 = nil
  self.description = nil
  self.from_time = Date.new
  self.id = nil
  self.sr_id = nil
  self.to_time = Date.new
  self.user = nil
end

#saveObject

Saves an activity back to the SysAid server

Example:

>> activity_object.save
=> true


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sysaid/activity.rb', line 71

def save
  SysAid.ensure_logged_in

  # Save it via the SOAP API
  response = SysAid.call(:save, message: to_xml(false))
  if response.to_hash[:save_response][:return]
    # In the case of new activities, the SysAid response will be the assigned ID
    self.id = response.to_hash[:save_response][:return] unless self.id
    return true
  else
    return false
  end
end