Class: OTRS::Service

Inherits:
OTRS
  • Object
show all
Defined in:
lib/otrs_connector/otrs/service.rb

Instance Attribute Summary collapse

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 = {}) ⇒ Service

Returns a new instance of Service.



11
12
13
14
15
# File 'lib/otrs_connector/otrs/service.rb', line 11

def initialize(attributes = {})
  attributes.each do |name, value|
    send("#{name.to_s.underscore.to_sym}=", value)
  end
end

Instance Attribute Details

#change_byObject

Returns the value of attribute change_by.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def change_by
  @change_by
end

#change_timeObject

Returns the value of attribute change_time.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def change_time
  @change_time
end

#commentObject

Returns the value of attribute comment.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def comment
  @comment
end

#config_itemsObject

Returns the value of attribute config_items.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def config_items
  @config_items
end

#create_byObject

Returns the value of attribute create_by.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def create_by
  @create_by
end

#create_timeObject

Returns the value of attribute create_time.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def create_time
  @create_time
end

#criticalityObject

Returns the value of attribute criticality.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def criticality
  @criticality
end

#criticality_idObject

Returns the value of attribute criticality_id.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def criticality_id
  @criticality_id
end

#cur_inci_stateObject

Returns the value of attribute cur_inci_state.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def cur_inci_state
  @cur_inci_state
end

#cur_inci_state_idObject

Returns the value of attribute cur_inci_state_id.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def cur_inci_state_id
  @cur_inci_state_id
end

#cur_inci_state_typeObject

Returns the value of attribute cur_inci_state_type.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def cur_inci_state_type
  @cur_inci_state_type
end

#cur_inci_state_type_from_c_isObject

Returns the value of attribute cur_inci_state_type_from_c_is.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def cur_inci_state_type_from_c_is
  @cur_inci_state_type_from_c_is
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def name
  @name
end

#name_shortObject

Returns the value of attribute name_short.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def name_short
  @name_short
end

#parent_idObject

Returns the value of attribute parent_id.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def parent_id
  @parent_id
end

#service_idObject

Returns the value of attribute service_id.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def service_id
  @service_id
end

#ticketsObject

Returns the value of attribute tickets.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def tickets
  @tickets
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def type
  @type
end

#type_idObject

Returns the value of attribute type_id.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def type_id
  @type_id
end

#valid_idObject

Returns the value of attribute valid_id.



2
3
4
# File 'lib/otrs_connector/otrs/service.rb', line 2

def valid_id
  @valid_id
end

Class Method Details

.allObject



92
93
94
# File 'lib/otrs_connector/otrs/service.rb', line 92

def self.all
  self.where(:name => '%')
end

.find(id) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/otrs_connector/otrs/service.rb', line 17

def self.find(id)
  data = { 'ServiceID' => id, 'UserID' => 1 }
  params = { :object => 'ServiceObject', :method => 'ServiceGet', :data => data }
  object = self.object_preprocessor self.connect(params)
  object.run_callbacks :find do
    object
  end
end

.where(attributes) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/otrs_connector/otrs/service.rb', line 75

def self.where(attributes)
  tmp = {}
  attributes.each do |key,value|
    tmp[key.to_s.camelize.to_sym] = value
  end
  attributes = tmp
  attributes[:UserID] = 1
  data = attributes
  params = { :object => 'ServiceObjectCustom', :method => 'ServiceSearch', :data => data }
  a = connect(params)
  services = self.superclass::Relation.new
  a.each do |service|
    services << self.object_preprocessor(service)
  end
  services
end

Instance Method Details

#create(attributes) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/otrs_connector/otrs/service.rb', line 32

def create(attributes)
  attributes[:valid_id] ||= 1
  attributes[:user_id] ||= 1
  attributes[:type_id] ||= 1
  attributes[:criticality_id] ||= 3
  tmp = {}
  attributes.each do |key,value|
    if key == :user_id
      tmp[:UserID] = value
    end
    if key == :valid_id
      tmp[:ValidID] = value
    end
    if key == :type_id
      tmp[:TypeID] = value
    end
    if key == :criticality_id
      tmp[:CriticalityID] = value
    end
    if key == :parent_id
      tmp[:ParentID] = value
    end
    if key != :user_id or key != :valid_id or key != :type_id or key != :crticality_id or key != :parent_id
      tmp[key.to_s.camelize.to_sym] = value
    end
  end
  attributes = tmp
  data = attributes
  params = { :object => 'ServiceObject', :method => 'ServiceAdd', :data => data }
  a = connect(params)
  service_id = a.first
  unless service_id.nil?
    self.class.find(service_id)
  else
    raise "Could not create service"
  end
  service = self.class.find(service_id)
  service.attributes.each do |key,value|
    instance_variable_set "@#{key.to_s}", value
  end
  service
end

#persisted?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/otrs_connector/otrs/service.rb', line 7

def persisted?
  false
end

#saveObject



26
27
28
29
30
# File 'lib/otrs_connector/otrs/service.rb', line 26

def save
  run_callbacks :save do
    self.create(self.attributes)
  end
end