Class: OTRS::GeneralCatalog

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OTRS

api_url, api_url=, #connect, connect, get_from_remote, object_preprocessor, password, password=, process_response, setup_connection_params, user, user=

Constructor Details

#initialize(attributes = {}) ⇒ GeneralCatalog

Returns a new instance of GeneralCatalog.



13
14
15
16
17
18
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 13

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

Instance Attribute Details

#change_byObject

Really recommend reading OTRS API Documentation for the GeneralCatalog



4
5
6
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 4

def change_by
  @change_by
end

#change_timeObject

Really recommend reading OTRS API Documentation for the GeneralCatalog



4
5
6
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 4

def change_time
  @change_time
end

#commentObject

Really recommend reading OTRS API Documentation for the GeneralCatalog



4
5
6
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 4

def comment
  @comment
end

#create_byObject

Really recommend reading OTRS API Documentation for the GeneralCatalog



4
5
6
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 4

def create_by
  @create_by
end

#create_timeObject

Really recommend reading OTRS API Documentation for the GeneralCatalog



4
5
6
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 4

def create_time
  @create_time
end

#item_idObject

Really recommend reading OTRS API Documentation for the GeneralCatalog



4
5
6
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 4

def item_id
  @item_id
end

#nameObject

Really recommend reading OTRS API Documentation for the GeneralCatalog



4
5
6
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 4

def name
  @name
end

#valid_idObject

Really recommend reading OTRS API Documentation for the GeneralCatalog



4
5
6
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 4

def valid_id
  @valid_id
end

Class Method Details

.class_list(name = '') ⇒ Object

Name variable filters the full classlist down so you can get just what you wanted



74
75
76
77
78
79
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 74

def self.class_list(name='')
  data = { }
  params = { :object => 'GeneralCatalogObject', :method => 'ClassList', :data => data }
  items = connect(params).first
  items.collect{ |i| i if i[name] }.compact
end

.find(id) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 32

def self.find(id)
  data = { 'ItemID' => id }
  params = { :object => 'GeneralCatalogObject', :method => 'ItemGet', :data => data }
  a = connect(params)
  unless a.first.nil?
    a = a.first.except('Class') ## Class field is causing issues in Rails
  end
  self.new(a)
end

.item_list(name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 42

def self.item_list(name)
  data = { :Class => name, :Valid => 1 }
  params = { :object => 'GeneralCatalogObject', :method => 'ItemList', :data => data }
  a = connect(params).first
  #b = []
  #unless a.nil?
  #  a.each do |key,value|
  #    b << self.find(key)
  #  end
  #  self.superclass::Relation.new(b)
  #end
end

.item_list_fast(name) ⇒ Object



55
56
57
58
59
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 55

def self.item_list_fast(name)
  data = { :Class => name, :Valid => 1 }
  params = { :object => 'GeneralCatalogObject', :method => 'ItemList', :data => data }
  a = connect(params).first
end

.set_accessor(key) ⇒ Object



5
6
7
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 5

def self.set_accessor(key)
  attr_accessor key.to_sym
end

Instance Method Details

#attributesObject



20
21
22
23
24
25
26
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 20

def attributes
  attributes = {}
  self.instance_variables.each do |v|
    attributes[v.to_s.gsub('@','').to_sym] = self.instance_variable_get(v)
  end
  attributes
end

#item_listObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 61

def item_list
  data = { :Class => self.name }
  params = { :object => 'GeneralCatalogObject', :method => 'ItemList', :data => data }
  a = connect(params)
  unless a.nil? then a = a.first end
  b = []
  a.each do |key,value|
    b << self.find(key)
  end
  self.superclass::Relation.new(b)
end

#persisted?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 9

def persisted?
  false
end

#saveObject



28
29
30
# File 'lib/otrs_connector/otrs/general_catalog.rb', line 28

def save
  self.create(self.attributes)
end