Sha256: 96eeb33ae34405e24e379dcdd2f539a624e818b56d15e7aa7a0308baf10664e2

Contents?: true

Size: 1.57 KB

Versions: 21

Compression:

Stored size: 1.57 KB

Contents

class OTRS::Ticket::Article < OTRS::Ticket
  
  def self.set_accessors(key)
    attr_accessor key.to_sym
  end
  
  def initialize(attributes = {})
    attributes.each do |name, value|
      OTRS::Ticket::Article.set_accessors(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 create(attributes)
    data = { 'TicketID' => attributes[:ticket_id], 'From' => attributes[:email], 'Subject' => attributes[:title], 'Body' => attributes[:body] }
    data['ArticleType'] ||= 'email-external'
    data['UserID'] ||= 1
    data['SenderType'] ||= 'agent'
    data['HistoryType'] ||= 'NewTicket'
    data['HistoryComment'] ||= ' '
    data['ContentType'] ||= 'text/plain'
    params = { :object => 'TicketObject', :method => 'ArticleCreate', :data => data }
    a = connect(params)
    if a.first.nil? then nil else a end
  end
  
  def self.find(id)
    data = { 'ArticleID' => id, 'UserID' => 1 }
    params = { :object => 'TicketObject', :method => 'ArticleGet', :data => data }
    a = connect(params)
    a = Hash[*a].symbolize_keys
    self.new(a)
  end
  
  def self.where(ticket_id)
    data = { 'TicketID' => ticket_id }
    params = { :object => 'TicketObject', :method => 'ArticleIndex', :data => data }
    a = connect(params)
    b = []
    a.each do |c|
      b << find(c)
    end
    OTRS::Relation.new(b)
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

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