Class: OTRS::Link
- Inherits:
-
OTRS
show all
- Defined in:
- lib/otrs_connector/otrs/link.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from OTRS
api_url, api_url=, #attributes, #connect, connect, get_from_remote, object_preprocessor, password, password=, process_response, setup_connection_params, user, user=
Constructor Details
#initialize(attributes = {}) ⇒ Link
Returns a new instance of Link.
11
12
13
14
15
16
|
# File 'lib/otrs_connector/otrs/link.rb', line 11
def initialize(attributes = {})
attributes.each do |name, value|
OTRS::Link.set_accessors(name.to_s.underscore)
send("#{name.to_s.underscore.to_sym}=", value)
end
end
|
Class Method Details
.create(attributes) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/otrs_connector/otrs/link.rb', line 22
def self.create(attributes)
attributes[:source_object] = attributes[:object1]
attributes[:target_object] = attributes[:object2]
attributes[:source_key] = attributes[:key1]
attributes[:target_key] = attributes[:key2]
attributes[:state] ||= 'Valid'
attributes[:user_id] ||= 1
tmp = {}
attributes.each do |key,value|
if key == :user_id
tmp[:UserID] = value
end
tmp[key.to_s.camelize] = value
end
data = tmp
params = { :object => 'LinkObject', :method => 'LinkAdd', :data => data }
a = connect(params)
if a.first == "1"
return self
else
nil
end
end
|
.set_accessors(key) ⇒ Object
3
4
5
|
# File 'lib/otrs_connector/otrs/link.rb', line 3
def self.set_accessors(key)
attr_accessor key.to_sym
end
|
.where(attributes) ⇒ Object
Returns list of link objects as Source => Target Haven’t decided if I want this to return the link object or what is being linked to
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/otrs_connector/otrs/link.rb', line 49
def self.where(attributes)
attributes[:state] ||= 'Valid'
tmp = {}
attributes.each do |key,value|
tmp[key.to_s.camelize.to_sym] = value
end
data = tmp
params = { :object => 'LinkObject', :method => 'LinkKeyList', :data => data }
a = connect(params)
a = Hash[*a]
b = []
a.each do |key,value|
c = {}
c[:key2] = "#{key}"
c[:object2] = tmp[:Object2]
c[:object1] = tmp[:Object1]
c[:key1] = tmp[:Key1]
b << self.new(c)
end
self.superclass::Relation.new(b)
end
|
Instance Method Details
#destroy ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/otrs_connector/otrs/link.rb', line 71
def destroy
@type ||= 'Normal'
data = { :Object1 => @object1, :Key1 => @key1, :Object2 => @object2, :Key2 => @key2, :Type => @type }
params = { :object => 'LinkObject', :method => 'LinkDelete', :data => data }
a = connect(params)
if a.first == 1.to_s
return true
else
return false
end
end
|
#persisted? ⇒ Boolean
7
8
9
|
# File 'lib/otrs_connector/otrs/link.rb', line 7
def persisted?
false
end
|
#save ⇒ Object
18
19
20
|
# File 'lib/otrs_connector/otrs/link.rb', line 18
def save
self.class.create(self.attributes)
end
|