We've been using BugzScout for a while in a lot of other scripts to post errors as bugs, but in the long run I was going to need something a bit more robust. So I started writing a wrapper for the FogBugz API in Ruby 1.
What has been written thus far can ge found on github at this address 2: www.github.com/austinmoody/ruby-fogbugz-api/tree/master
It is very incomplete at the moment, but does enough for what I need right now. I've got more plans to use it for other things here so I'll be needing to flesh it out more.
The application I'm using it in right now is a small web-application used by people in our office to add information to data coming in on an interface bound for our medical practice management system. After they have completed what they need to the data is dropped out as HL7 and sent on. At any point in the application they can click on a link which will allow them to submit a Question or a Bug to our FogBugz installation.
This navigation menu is present on all pages in the application, complete with the Send Bug/Question to IT link.
Clicking that link will reveal a previously hidden form that allows the user to enter in their question or problem.
Once they hit the Save button, a case is created in FogBugz using the API. The user is shown the case id number in case they need to contact us with any follow up information.
On our side we get the case filed in the proper project, with the user's name and what controller and action the case was submitted from. If they where on a page for a specific data item (patient, physician, whatever) the case will also (eventually) contain an account number or database id so that we can know exactly where they were at when the question popped in their head.
This was pretty easily done in Rails. One day if I ever had time (yeah whatever) I think it would be neat to get something together as a Rails plugin which would make it easy to drop FogBugz integration right in. For now...
In my main layout I have a div that contains the remote form used to submit the question/bug initially hidden:
- <div id="fogbugz-submit" style="display: none;">
- <small><a href="#" onclick="toggle_visibility('fogbugz-submit');">cancel</a></small>
- <%= image_tag("spinner.gif",
- :align=>"absmiddle",
- :border=>0,
- :id=>"spinner",
- :style=>"display: none;")
- %>
- <% form_remote_tag :update=>"fogbugz-submit",
- :complete=>"addFormListener();",
- :before => "Element.show('spinner')",
- :success => "Element.hide('spinner')",
- :url => {:controller=>"bug",:action=>"create"} do -%>
- <%= hidden_field_tag "current_location", request.request_uri %>
- <%= hidden_field_tag "current_controller", controller.controller_name %>
- <%= hidden_field_tag "current_action", controller.action_name %>
- <p><b>Bug/Question Description:</b></p>
- <p><%= text_area_tag "case_text", nil, :size=>"40x15" %></p>
- <p><%= submit_tag "Save" %></p>
- <% end -%>
- </div>
The user clicks on the Send Bug/Question to IT link to expose the form.
- <a href="#" onclick="toggle_visibility('fogbugz-submit');"><%= image_tag("bug.gif") %> Send Bug/Question To IT</a>
Hitting the Save button calls the create action in the Bug controller:
- def create
- parameters = {
- "sTitle"=>"ECS Bug/Question - #{session[:ecs].name} - #{Time.now.strftime("%m/%d/%Y %H:%M")}",
- "sEvent"=>params[:case_text] + "\n\nURI: #{params[:current_location]}\nCONTROLLER: #{params[:current_controller]}\nACTION: #{params[:current_action]}",
- "sProject"=>FB_SETUP["sProject"],
- "sArea" => FB_SETUP["sArea"],
- "sCategory" => FB_SETUP["sCategory"]
- }
- @new_case = $fb.new_case(parameters)
- respond_to do |format|
- format.js
- end
- end
There is a create.rjs:
- page.replace "fogbugz-submit", :partial => "layouts/fogbugz", :locals => {:new_case => @new_case}
Which does nothing but replace the contents of the fogbugz-submit div with a partial to show the user information about the newly created case.
- <p id="flashgood">New Bug/Question has been submitted to the IT Department.<br />Please reference Case # <b><%= @new_case["ixBug"] %></b> if you need more information.</p>
To set all this up I have a file called load_fogbugz.rb in my Rails config/initializers directory.
- FB_SETUP = YAML.load_file("#{RAILS_ROOT}/config/fogbugz.yml")
This just loads up a Yaml file I've created in my Rails config folder which looks like:
- url: myfogbugz.com
- use_ssl: true
- token: gobbledygook
- sProject: "ECS - ECP Charge System"
- sArea: Website
- sCategory: Bug
This file, of course, would have to be updated with your own information.
Lastly, at the end of the config/environment.rb file I the following line which creates the FogBugz API object to be used in the application.
- $fb = FogBugz.new(FB_SETUP["url"],FB_SETUP["use_ssl"],FB_SETUP["token"])
I've still got other things to think about here in terms of error handling (what if the FogBugz server isn't reachable? etc...) but this is a start that we plan to flesh out before people get their hands on it.
Also, I'm struggling with the idea of having a token stored in that Yaml file (which was created with my user). I've been thinking of creating an API user in FogBugz to use, but I don't really have the extra licenses right now.
Please feel free to contact me with questions or comments.
1 → After I'd gotten to my stopping point I found that someone else had already started a Ruby-FogBugz wrapper over on RubyForge. Crazy me was just looking at github and not really thinking. So now I'm wondering if I should carry on with what I'm doing or start adding to what Richard has started.
2 → This was my first time toying with github. Really like it so far. Actually already have someone who has contributed some changes to the code (Greg McIntyre, puyo on gitub).

0 comments:
Post a Comment