class KayakoClient::Ticket
Constants
- FLAG_BLUE
- FLAG_GREEN
- FLAG_NONE
NOTE: department is required to be of :tickets type
- FLAG_ORANGE
- FLAG_PURPLE
- FLAG_RED
- FLAG_YELLOW
- SEARCH_AUTHOR
- SEARCH_CONTENTS
- SEARCH_CREATOR_EMAIL
- SEARCH_EMAIL
- SEARCH_FULL_NAME
- SEARCH_NOTES
- SEARCH_TAGS
- SEARCH_TICKET_ID
- SEARCH_USER
- SEARCH_USER_GROUP
- SEARCH_USER_ORGANIZATION
- TICKET_TYPES
Public Class Methods
all(*args)
click to toggle source
Calls superclass method
# File lib/kayako_client/ticket.rb, line 160 def self.all(*args) options = args.last.is_a?(Hash) ? args.pop : {} components = [] args.each_index do |index| break if index > 5 if args[index] components[index] ||= [] components[index] << args[index] end end options.keys.each do |option| case option.to_s.gsub(%r{_}, '') when 'departmentid', 'department' index = 0 when 'ticketstatusid', 'ticketstatus' index = 1 when 'ownerstaffid', 'ownerstaff' index = 2 when 'userid', 'user' index = 3 when 'count', 'limit' index = 4 components[index] = [] when 'start', 'offset' index = 5 components[index] = [] else next end components[index] ||= [] components[index] << options.delete(option) end raise ArgumentError, "missing :department_id" unless components[0] e = path + '/ListAll' + components.inject('') do |uri, item| uri << '/' + (item.nil? ? '-1' : item.flatten.uniq.join(',')) end super(options.merge(:e => e)) end
get(id = :all, options = {})
click to toggle source
Calls superclass method
# File lib/kayako_client/ticket.rb, line 204 def self.get(id = :all, options = {}) if id == :all all(options.delete(:id), options) else super(options.merge(:id => id)) end end
search(query, flags = SEARCH_CONTENTS, options = {})
click to toggle source
# File lib/kayako_client/ticket.rb, line 212 def self.search(query, flags = SEARCH_CONTENTS, options = {}) unless configured? || (options[:api_url] && options[:api_key] && options[:secret_key]) raise RuntimeError, "client not configured" end params = { :e => '/Tickets/TicketSearch', :query => query } params[:ticketid] = 1 unless flags & SEARCH_TICKET_ID == 0x0000 params[:contents] = 1 unless flags & SEARCH_CONTENTS == 0x0000 params[:author] = 1 unless flags & SEARCH_AUTHOR == 0x0000 params[:email] = 1 unless flags & SEARCH_EMAIL == 0x0000 params[:creatoremail] = 1 unless flags & SEARCH_CREATOR_EMAIL == 0x0000 params[:fullname] = 1 unless flags & SEARCH_FULL_NAME == 0x0000 params[:notes] = 1 unless flags & SEARCH_NOTES == 0x0000 params[:usergroup] = 1 unless flags & SEARCH_USER_GROUP == 0x0000 params[:userorganization] = 1 unless flags & SEARCH_USER_ORGANIZATION == 0x0000 params[:user] = 1 unless flags & SEARCH_USER == 0x0000 params[:tags] = 1 unless flags & SEARCH_TAGS == 0x0000 response = post_request(options.merge(params)) log = options[:logger] || logger if response.is_a?(KayakoClient::HTTPOK) objects = [] if log log.debug "Response:" log.debug response.body end payload = xml_backend.new(response.body, { :logger => log }) payload.each do |element| object = new(payload.to_hash(element).merge(inherited_options(options))) object.loaded! objects << object end log.info ":post(:search, '#{params[:query]}', #{sprintf("0x%04X", flags)}) successful (#{objects.size} objects)" if log objects else log.error "Response: #{response.status} #{response.body}" if log raise StandardError, "server returned #{response.status}: #{response.body}" end end
Public Instance Methods
created_by_user?()
click to toggle source
# File lib/kayako_client/ticket.rb, line 146 def created_by_user? !user_id.nil? && user_id > 0 end
Also aliased as: has_user?
has_owner_staff?()
click to toggle source
# File lib/kayako_client/ticket.rb, line 156 def has_owner_staff? !owner_staff_id.nil? && owner_staff_id > 0 end
has_user_organization?()
click to toggle source
# File lib/kayako_client/ticket.rb, line 152 def has_user_organization? !user_organization_id.nil? && user_organization_id > 0 end
posts()
click to toggle source
# File lib/kayako_client/ticket.rb, line 130 def posts if instance_variable_defined?(:@posts) instance_variable_get(:@posts) elsif !new? && id && id > 0 logger.debug "posts are missing - trying to load" if logger post = KayakoClient::TicketPost.all(id, inherited_options) if post && !post.empty? instance_variable_set(:@posts, post) else instance_variable_set(:@posts, nil) end else nil end end
Private Instance Methods
validate(method, params)
click to toggle source
# File lib/kayako_client/ticket.rb, line 258 def validate(method, params) if method == :post unless params[:auto_user_id] || params[:user_id] || params[:staff_id] raise ArgumentError, ":auto_user_id, :user_id or :staff_id is required" end end if params.has_key?(:template_group_id) && params.has_key?(:template_group_name) raise ArgumentError, "Only one of :template_group_id or :template_group_name should be used" end end