Class: Unfuddler::Ticket
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Unfuddler::Ticket
- Defined in:
- lib/unfuddler.rb
Defined Under Namespace
Classes: Interacter
Class Method Summary collapse
-
.find(project_id, arguments = nil) ⇒ Object
Find tickets associated with a project.
Instance Method Summary collapse
-
#create(project_id = nil) ⇒ Object
Create a ticket.
- #delete ⇒ Object
-
#save(update = nil) ⇒ Object
Save ticket.
Class Method Details
.find(project_id, arguments = nil) ⇒ Object
Find tickets associated with a project.
Required argument is project_id, which is the id of the project to search for tickets.
Optional argument is argument, which searches the tickets to match the keys in the argument. e.g.
Ticket.find(:status => "new")
Returns all tickets with status “new”
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/unfuddler.rb', line 68 def self.find(project_id, arguments = nil) tickets = [] Unfuddler.get("projects/#{project_id}/tickets.xml")["tickets"].each do |project| tickets << Ticket.new(project) end if arguments specified_tickets = [] # Check each ticket if all the expected values pass, return all # tickets where everything passes in an array tickets.each do |ticket| matches = 0 arguments.each_pair do |method, expected_value| matches += 1 if ticket.send(method) == expected_value end specified_tickets << ticket if matches == arguments.length end return specified_tickets end tickets end |
Instance Method Details
#create(project_id = nil) ⇒ Object
Create a ticket
Optional argument is project_id
105 106 107 108 |
# File 'lib/unfuddler.rb', line 105 def create(project_id = nil) ticket = self.to_hash.to_xml(:root => "ticket") Unfuddler.post("projects/#{project_id or self.project_id}/tickets", ticket) end |
#delete ⇒ Object
131 132 133 |
# File 'lib/unfuddler.rb', line 131 def delete Unfuddler.delete("projects/#{self.project_id}/tickets/#{self.id}") end |
#save(update = nil) ⇒ Object
Save ticket
Optional argument is what to update if the ticket object is not altered
97 98 99 100 |
# File 'lib/unfuddler.rb', line 97 def save(update = nil) update = self.to_hash.to_xml(:root => "ticket") unless update Unfuddler.put("projects/#{self.project_id}/tickets/#{self.id}", update) end |