class Tessera::Ticket

Public Class Methods

create(params) click to toggle source

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

# File lib/tessera/ticket.rb, line 34
def create(params)
  ticket = Tessera::Otrs::Ticket.new(params[:ticket]).to_hash
  article = Tessera::Otrs::Article.new(params[:article]).to_hash
  attachment = if params[:attachment] && params[:attachment].is_a?(Hash)
                 Tessera::Otrs::Attachment.new(params[:attachment]).to_hash
               elsif params[:attachment] && params[:attachment].is_a?(Array)
                 params[:attachment].map do |a|
                   Tessera::Otrs::Attachment.new(a).to_hash
                 end
               end
  body = { Ticket: ticket }
  body = body.merge(Article: article)
  body = body.merge(Attachment: attachment) if attachment

  Tessera::Api::TicketCreate.call(body)
end
find(ticket_id) click to toggle source

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

# File lib/tessera/ticket.rb, line 6
def find(ticket_id)
  ticket = if ticket_id.is_a? Array
             ::Tessera::Api::TicketList.call(ticket_id)
           else
             ::Tessera::Api::TicketGet.call(ticket_id)
           end
  if ticket['Error']
    raise TicketNotFound.new(ticket['Error']['ErrorMessage'],
                             ticket['Error']['ErrorCode'])
  elsif ticket['Ticket'] && ticket['Ticket'].count > 1
    ticket['Ticket'].map do |ticket_json|
      ::Tessera::Model::Ticket.new(ticket_json)
    end
  else
    ::Tessera::Model::Ticket.new(ticket['Ticket'].first)
  end
end
new(result) click to toggle source
# File lib/tessera/ticket.rb, line 54
def initialize(result)
  @result = result
end
where(params) click to toggle source

rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize

# File lib/tessera/ticket.rb, line 26
def where(params)
  result = Tessera::Api::TicketSearch.call(params)
  ticket_ids = result['TicketID'] ? result['TicketID'] : []
  new(ticket_ids)
end

Public Instance Methods

count() click to toggle source
# File lib/tessera/ticket.rb, line 58
def count
  @result.size
end
ticket_ids() click to toggle source
# File lib/tessera/ticket.rb, line 62
def ticket_ids
  @result.map(&:to_i)
end
tickets() click to toggle source
# File lib/tessera/ticket.rb, line 66
def tickets
  return [] if @result.empty?
  @tickets ||= @result.map do |id|
    ::Tessera::Ticket.find(id)
  end
end