Class: FogBugz::BugzScout

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

Overview

This is the core class that does all of the heavy lifting.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ BugzScout

provide BugzScout with the URL of your FogBugz instance, including the ‘scoutsubmit.asp’ entry point example: styledbits.fogbugz.com/scoutsubmit.asp



20
21
22
# File 'lib/bugzscout.rb', line 20

def initialize(url)
  self.url = url
end

Instance Attribute Details

#areaObject

Returns the value of attribute area.



16
17
18
# File 'lib/bugzscout.rb', line 16

def area
  @area
end

#bodyObject

Returns the value of attribute body.



16
17
18
# File 'lib/bugzscout.rb', line 16

def body
  @body
end

#emailObject

Returns the value of attribute email.



16
17
18
# File 'lib/bugzscout.rb', line 16

def email
  @email
end

#newObject

Returns the value of attribute new.



16
17
18
# File 'lib/bugzscout.rb', line 16

def new
  @new
end

#projectObject

Returns the value of attribute project.



16
17
18
# File 'lib/bugzscout.rb', line 16

def project
  @project
end

#titleObject

Returns the value of attribute title.



16
17
18
# File 'lib/bugzscout.rb', line 16

def title
  @title
end

#urlObject

Returns the value of attribute url.



16
17
18
# File 'lib/bugzscout.rb', line 16

def url
  @url
end

#userObject

Returns the value of attribute user.



16
17
18
# File 'lib/bugzscout.rb', line 16

def user
  @user
end

Class Method Details

.submit(url) {|scout| ... } ⇒ Object

Yields:

  • (scout)


62
63
64
65
66
# File 'lib/bugzscout.rb', line 62

def self.submit(url)
  scout = BugzScout.new(url)
  yield scout
  scout.submit
end

Instance Method Details

#submitObject

send the response to FogBugz return true if all goes well throw a BugzScoutError exception along with the error text if otherwise.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bugzscout.rb', line 27

def submit
  # ensure that the required fields are included
  validate

  body = {
    :ScoutUserName => self.user,
    :ScoutProject => self.project,
    :ScoutArea => self.area,
    :Description => self.title, 
    :ForceNewBug => self.new,
    :Extra => self.body,
    :Email => self.email,
    :ScoutDefaultMessage => "",
    :FriendlyResponse => 0 
  }
  client = HTTPClient.new
  response = client.post(url, body).content

  if response =~ /<Error>(.*)<\/Error>/
    # if we see an error response, we know that we fudged some of our input values to BugzScout
    # the error message should contain where we went wrong.
    # We raise the exception so the user can catch it and log if necessary.  No one likes things that fail silently!
    raise(BugzScoutError, $1)
  else
    # we'll return 'true' for the sake of clarity
    return true
  end
end

#validateObject

Raises:



56
57
58
59
60
# File 'lib/bugzscout.rb', line 56

def validate
  raise(BugzScoutError, "You have to provide a user name") if !self.user
  raise(BugzScoutError, "You must provide a FogBugz project") if !self.project
  raise(BugzScoutError, "You have to provide an area") if !self.area
end