Class: Unfuddler::Ticket

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/unfuddler.rb

Defined Under Namespace

Classes: Interacter

Class Method Summary collapse

Instance Method Summary collapse

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”



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/unfuddler.rb', line 82

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



119
120
121
122
# File 'lib/unfuddler.rb', line 119

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

#deleteObject



146
147
148
# File 'lib/unfuddler.rb', line 146

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



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

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