lib/roart/ticket.rb in roart-0.1.5.1 vs lib/roart/ticket.rb in roart-0.1.6

- old
+ new

@@ -1,10 +1,10 @@ module Roart module Tickets - DefaultAttributes = %w(queue owner creator subject status priority initial_priority final_priority requestors cc admin_cc created starts started due resolved told last_updated time_estimated time_worked time_left) + DefaultAttributes = %w(queue owner creator subject status priority initial_priority final_priority requestors cc admin_cc created starts started due resolved told last_updated time_estimated time_worked time_left text) RequiredAttributes = %w(queue subject) end class Ticket @@ -60,21 +60,29 @@ self.create else self.before_update uri = "#{self.class.connection.server}/REST/1.0/ticket/#{self.id}/edit" payload = @attributes.clone - payload.delete(:id) + payload.delete("text") + payload.delete("id") # Can't have text in an update, only create, use comment for updateing payload = payload.to_content_format + puts payload resp = self.class.connection.post(uri, :content => payload) + puts resp resp = resp.split("\n") raise "Ticket Update Failed" unless resp.first.include?("200") - if resp[2].match(/^# Ticket (\d+) updated./) - self.after_update - true - else - false + resp.each do |line| + puts "line" + if line.match(/^# Ticket (\d+) updated./) + self.after_update + puts "FOUND" + return true + else + #TODO: Add warnign to ticket + end end + return false end end # Add a comment to a ticket # Example: @@ -109,18 +117,21 @@ uri = "#{self.class.connection.server}/REST/1.0/ticket/new" payload = @attributes.to_content_format resp = self.class.connection.post(uri, :content => payload) resp = resp.split("\n") raise "Ticket Create Failed" unless resp.first.include?("200") - if tid = resp[2].match(/^# Ticket (\d+) created./) - @attributes[:id] = tid[1].to_i - self.after_create - @new_record = false - true - else - false + resp.each do |line| + if tid = line.match(/^# Ticket (\d+) created./) + @attributes[:id] = tid[1].to_i + self.after_create + @new_record = false + return true + else + #TODO: Add Warnings To Ticket + end end + return false end def create! #:nodoc: raise "Ticket Create Failed" unless self.create true @@ -239,11 +250,11 @@ object.instance_variable_set("@attributes", attr) object.send("add_methods!") array << object end return array - elsif attrs.is_a?(Hash) + elsif attrs.is_a?(Hash) || attrs.is_a?(HashWithIndifferentAccess) object = self.allocate object.instance_variable_set("@attributes", attrs) object.send("add_methods!") end object.instance_variable_set("@history", false) @@ -277,14 +288,40 @@ else raise TicketSystemInterfaceError, "Error Getting Ticket: #{status}" end end + def page_list_array(uri) #:nodoc: + page = self.connection.get(uri) + raise TicketSystemError, "Can't get ticket." unless page + page = page.split("\n") + status = page.delete_at(0) + if status.include?("200") + page = page.join("\n") + chunks = page.split(/^--$/) + page = [] + for chunk in chunks + chunk = chunk.split("\n") + chunk.delete_if{|x| !x.include?(":")} + page << chunk + end + page + else + raise TicketSystemInterfaceError, "Error Getting Ticket: #{status}" + end + end + def get_tickets_from_search_uri(uri) #:nodoc: - page = page_array(uri) + page = page_list_array(uri + "&format=l") page.extend(Roart::TicketPage) - page = page.to_search_array - self.instantiate(page) + page = page.to_search_list_array + array = Array.new + for ticket in page + ticket = self.instantiate(ticket) + ticket.instance_variable_set("@full", true) + array << ticket + end + array end def get_ticket_from_uri(uri) #:nodoc: page = page_array(uri) page.extend(Roart::TicketPage)