Class: Unfuzzle::Ticket

Inherits:
Object
  • Object
show all
Includes:
Graft
Defined in:
lib/unfuzzle/lib/unfuzzle/ticket.rb

Overview

Ticket

Represents a single Unfuddle Ticket - is associated to a project and optionally a project’s milestone. Has the following attributes:

id

The unique identifier for this ticket

number

The ticket’s number - this is displayed in the web interface

title

The title of the ticket (short)

description

The full description of the ticket

status

The ticket’s status (new / accepted / resolved / closed)

due_on

The due date for this ticket

created_at

The date/time that this ticket was created

updated_at

The date/time that this ticket was last updated

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Graft

included

Constructor Details

#initialize(*args) ⇒ Ticket

Returns a new instance of Ticket.



39
40
41
42
43
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 39

def initialize(*args)
  self.priority = 3
  self.status = "new"
  super(*args)
end

Class Method Details

.all_by_dinamic_report(with_project_ids = nil, only_my_tickets = false) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 76

def self.all_by_dinamic_report(with_project_ids = nil, only_my_tickets = false)
  query = "?title=Dynamic&conditions_string=status-neq-closed"
  query += ",assignee-eq-current" if only_my_tickets
  query += "&fields_string=id,number,title,hours,assignee,status,reporter"

  res = []

  if with_project_ids.blank?
    response = Request.get("/ticket_reports/dynamic", query)
    res = collection_from(response.body, 'tickets/ticket')
  else
    with_project_ids.each do |id|
      response = Request.get("/projects/#{id}/ticket_reports/dynamic", query)
      res << collection_from(response.body, 'tickets/ticket')
    end
  end

  res.flatten
end

.find_all_by_project_and_report(project_id, report_id) ⇒ Object



70
71
72
73
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 70

def self.find_all_by_project_and_report(project_id, report_id)
  response = Request.get("/projects/#{project_id}/ticket_reports/#{report_id}/generate")
  collection_from(response.body, 'tickets/ticket')
end

.find_all_by_project_id(project_id) ⇒ Object

Return a list of all tickets for an individual project



46
47
48
49
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 46

def self.find_all_by_project_id(project_id)
  response = Request.get("/projects/#{project_id}/tickets")
  collection_from(response.body, 'tickets/ticket')
end

.find_all_by_project_id_and_milestone_id(project_id, milestone_id) ⇒ Object

Return a list of all tickets for a given milestone as part of a project



52
53
54
55
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 52

def self.find_all_by_project_id_and_milestone_id(project_id, milestone_id)
  response = Request.get("/projects/#{project_id}/milestones/#{milestone_id}/tickets")
  collection_from(response.body, 'tickets/ticket')
end

.find_first_by_project_id_and_number(project_id, number) ⇒ Object

Return a list of all tickets for a given milestone as part of a project



58
59
60
61
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 58

def self.find_first_by_project_id_and_number(project_id, number)
  response = Request.get("/projects/#{project_id}/tickets/by_number/#{number}")
  new(response.body)
end

.find_first_by_project_id_and_number_with_comments(project_id, number) ⇒ Object

Return a list of all tickets for a given milestone as part of a project



64
65
66
67
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 64

def self.find_first_by_project_id_and_number_with_comments(project_id, number)
  response = Request.get("/projects/#{project_id}/tickets/by_number/#{number}", "?comments=true")
  [new(response.body), Comment.collection_from(response.body, 'comments/comment')]
end

Instance Method Details

#componentObject

The Component associated with this ticket



117
118
119
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 117

def component
  Component.find_by_project_id_and_component_id(project_id, component_id) unless component_id.nil?
end

#component_nameObject



121
122
123
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 121

def component_name
  component.name unless component.nil?
end

#createObject

Create a ticket in unfuddle



150
151
152
153
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 150

def create
  resource_path = "/projects/#{project_id}/tickets"
  Request.post(resource_path, self.to_xml('ticket'))
end

#milestoneObject

The Milestone associated with this ticket



98
99
100
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 98

def milestone
  Milestone.find_by_project_id_and_milestone_id(project_id, milestone_id)
end

#priority_nameObject



111
112
113
114
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 111

def priority_name
  # priority.name
  Priority.new(priority).name
end

#severityObject

The Severity associated with this ticket



103
104
105
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 103

def severity
  Severity.find_by_project_id_and_severity_id(project_id, severity_id) unless severity_id.nil?
end

#severity_nameObject



107
108
109
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 107

def severity_name
  severity.name unless severity.nil?
end

#to_hashObject

Hash representation of this ticket’s data (for updating)



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 126

def to_hash
  {
    'id'           => id,
    'project-id'   => project_id,
    'milestone-id' => milestone_id,
    'priority'     => priority,
    'severity-id'  => severity_id,
    'number'       => number,
    'summary'      => title,
    'description'  => description,
    'status'       => status,
    'assignee-id'  => assignee_id,
    'reporter-id'  => reporter_id#,
    #'hours'        => hours
  }
end

#updateObject

Update the ticket’s data in unfuddle



144
145
146
147
# File 'lib/unfuzzle/lib/unfuzzle/ticket.rb', line 144

def update
  resource_path = "/projects/#{project_id}/tickets/#{id}"
  Request.put(resource_path, self.to_xml('ticket'))
end