Class: Bug

Inherits:
Object
  • Object
show all
Defined in:
lib/buggster.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



12
13
14
# File 'lib/buggster.rb', line 12

def body
  @body
end

#closedObject

Returns the value of attribute closed.



12
13
14
# File 'lib/buggster.rb', line 12

def closed
  @closed
end

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/buggster.rb', line 12

def id
  @id
end

#priorityObject

Returns the value of attribute priority.



12
13
14
# File 'lib/buggster.rb', line 12

def priority
  @priority
end

#projectObject

Returns the value of attribute project.



12
13
14
# File 'lib/buggster.rb', line 12

def project
  @project
end

Class Method Details

.connect(host, port) ⇒ Object



30
31
32
# File 'lib/buggster.rb', line 30

def self.connect(host, port)
  RFuzz::HttpClient.new(host, port)
end

.connectionObject



26
27
28
# File 'lib/buggster.rb', line 26

def self.connection
  @@connections[name]
end

.establish_connection(options) ⇒ Object



34
35
36
37
# File 'lib/buggster.rb', line 34

def self.establish_connection(options)
  @@connections ||= {}
  @@connections[name] = connect(options[:host], options[:port])
end

.get(id) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/buggster.rb', line 39

def self.get(id)
  encoded_id = CGI::escape(id.to_s)
  resp = @@connections[name].get("/#{encoded_id}").http_body
  doc = Hpricot(resp)
  (doc/:bug).each do |xml_bug|
     @bug = Bug.new
     for field in FIELDS
       @bug.send("#{field}=", (xml_bug/field).first.innerHTML)
     end
     @bug.id = id
  end
  return @bug
end

Instance Method Details

#connectionObject



22
23
24
# File 'lib/buggster.rb', line 22

def connection
  self.class.connection
end

#destroy!Object



64
65
66
67
68
69
# File 'lib/buggster.rb', line 64

def destroy!
  encoded_id = CGI::escape(self.id.to_s)
  resp = connection.delete("/#{encoded_id}").http_body
  self.closed = "1"
  self.freeze
end

#generate_xml(bug) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/buggster.rb', line 71

def generate_xml(bug)    
  xml = Builder::XmlMarkup.new
  xml.instruct!
  
  xml.buglist do
  xml.bug do
   xml.project bug.project
   xml.priority bug.priority
   xml.body bug.body
  end
  end
end

#initalize(hash) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/buggster.rb', line 14

def initalize(hash)
  @project = hash[:project]
  @priority = hash[:priority]
  @body = hash[:body]
  @id = hash[:id]
  @closed = hash[:closed]
end

#saveObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/buggster.rb', line 53

def save
  xml = generate_xml(self)
  resp = connection.post("/", :body => "bug=#{xml}").http_body
  doc = Hpricot(resp)
  @bug = Bug.new
  for field in FIELDS
    @bug.send("#{field}=", (doc/:bug/field).first.innerHTML)
  end 
  return @bug
end