Sha256: 6faf50daaed25c9533ba6c5724b5655db9769aa931bcd987d6b2b11040a40edd

Contents?: true

Size: 1.96 KB

Versions: 21

Compression:

Stored size: 1.96 KB

Contents

class OTRS::GeneralCatalog < OTRS
  attr_accessor :name, :change_time, :change_by, :valid_id, :create_time, :item_id, :comment, :create_by
  def self.set_accessor(key)
    attr_accessor key.to_sym
  end
  
  def persisted?
    false
  end
  
  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
  
  def attributes
    attributes = {}
    self.instance_variables.each do |v|
      attributes[v.to_s.gsub('@','').to_sym] = self.instance_variable_get(v)
    end
    attributes
  end
  
  def save
    self.create(self.attributes)
  end
  
  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
  
  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
  
  def self.item_list_fast(name)
    data = { :Class => name, :Valid => 1 }
    params = { :object => 'GeneralCatalogObject', :method => 'ItemList', :data => data }
    a = connect(params).first
  end
  
  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
  
  def self.class_list
    data = { }
    params = { :object => 'GeneralCatalogObject', :method => 'ClassList', :data => data }
    a = connect(params).first
  end
  
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
otrs_connector-1.0.0 lib/otrs_connector/otrs/general_catalog.rb
otrs_connector-0.5.20 lib/otrs_connector/otrs/general_catalog.rb
otrs_connector-0.5.19 lib/otrs_connector/otrs/general_catalog.rb
otrs_connector-0.5.18 lib/otrs_connector/otrs/general_catalog.rb
otrs_connector-0.5.17 lib/otrs_connector/otrs/general_catalog.rb
otrs_connector-0.5.16 lib/otrs_connector/otrs/general_catalog.rb
otrs_connector-0.5.15 lib/otrs_connector/otrs/general_catalog.rb
otrs_connector-0.5.14 lib/otrs_connector/otrs/general_catalog.rb
otrs_connector-0.5.13 lib/otrs/general_catalog.rb
otrs_connector-0.5.12 lib/otrs/general_catalog.rb
otrs_connector-0.5.11 lib/otrs/general_catalog.rb
otrs_connector-0.5.10 lib/otrs/general_catalog.rb
otrs_connector-0.5.9 lib/otrs/general_catalog.rb
otrs_connector-0.5.8 lib/otrs/general_catalog.rb
otrs_connector-0.5.7 lib/otrs/general_catalog.rb
otrs_connector-0.5.6 lib/otrs/general_catalog.rb
otrs_connector-0.5.4 lib/otrs/general_catalog.rb
otrs_connector-0.5.3 lib/otrs/general_catalog.rb
otrs_connector-0.5.2 lib/otrs/general_catalog.rb
otrs_connector-0.5.1 lib/otrs/general_catalog.rb