Class: Cukebase::Ticket

Inherits:
Object
  • Object
show all
Includes:
ActiveAttr::Model
Defined in:
lib/cukebase/ticket.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Ticket

Returns a new instance of Ticket.



35
36
37
38
39
# File 'lib/cukebase/ticket.rb', line 35

def initialize *args, &block
  super

  @changes = {}
end

Class Method Details

.wrap_setter(name) ⇒ Object



28
29
30
31
32
33
# File 'lib/cukebase/ticket.rb', line 28

def self.wrap_setter name
  define_method "#{name}=" do |value|
    @changes[name] = value if @changes && value != send(name)
    super value
  end
end

Instance Method Details

#create_ticket(content) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cukebase/ticket.rb', line 60

def create_ticket content
  data = {}
  data[:summary] = summary if summary?
  data[:description] = content if content
  data[:ticket_type] = ticket_type if ticket_type?
  data[:category_id] = category_id if category_id?
  data[:priority_id] = priority_id if priority_id?
  data[:status_id] = status_id if status_id?
  data[:assignee_id] = assignee_id if assignee_id?
  data[:milestone_id] = milestone_id if milestone_id?

  Request.post "#{Cukebase.config.project}/tickets", body: data.to_xml(root: "ticket", skip_types: true, skip_instruct: true)
end

#save(content = nil) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/cukebase/ticket.rb', line 74

def save content=nil
  if ticket_id?
    update_ticket content
  else
    create_ticket content
  end
end

#update_ticket(content) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/cukebase/ticket.rb', line 49

def update_ticket content
  data = {}

  data[:changes] = @changes if @changes.any?
  data[:content] = content if content && self.content != content

  if data.any?
    Request.post "#{Cukebase.config.project}/tickets/#{ticket_id}/notes", body: data.to_xml(root: "ticket-note", skip_types: true, skip_instruct: true)
  end
end