Created
March 2, 2010 05:05
-
-
Save daviscabral/319159 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
HELP = <<EOS | |
Freshbridge helps you to create an invoice with items from a Pivotal Tracker Project. | |
Just to avoid mess your stuff - this script don't create invoices - just update an existent invoice. | |
DEPENDENCIES: | |
- freshbooks | |
- HTTParty | |
EOS | |
USAGE = <<EOS | |
Usage: freshbridge [freshbooks_subdomain] [freshbooks_token] [pivotal_tracker_token] [project_ids] [invoice_id] [since_date] [pivotal_tracker_user] | |
EOS | |
begin | |
require 'rubygems' | |
require 'freshbooks' | |
require 'httparty' | |
rescue | |
puts HELP | |
exit | |
end | |
if ARGV.delete("--help") || ARGV.delete("-h") | |
puts USAGE | |
exit | |
end | |
$fb_subdomain = ARGV.delete(ARGV.first) | |
$fb_token = ARGV.delete(ARGV.first) | |
$pt_token = ARGV.delete(ARGV.first) | |
$project_ids = ARGV.delete(ARGV.first) | |
$invoice_id = ARGV.delete(ARGV.first) | |
$since_date = ARGV.delete(ARGV.first) | |
$pt_user = ARGV.delete(ARGV.first) | |
unless $fb_subdomain && $fb_token && $pt_token && $project_ids && $invoice_id && $since_date && $pt_user | |
puts USAGE | |
exit | |
end | |
class Tracker | |
include HTTParty | |
format :xml | |
def self.setup(project_id = '123', token = '45a6a078f67d9210d2fba91f8c484e7b', ssl=true) | |
@project_ids, @token, @ssl = project_ids.split(","), token, ssl | |
protocol = @ssl ? 'https' : 'http' | |
port = @ssl ? '443' : '80' | |
self.base_uri "#{protocol}://www.pivotaltracker.com:#{port}" | |
self.basic_auth token, "x" | |
self.headers "X-TrackerToken" => @token | |
end | |
def self.find(query_filter) | |
stories = [] | |
@project_ids.each do |project_id| | |
stories.concat(get("/services/v2/projects/#{project_id}/stories", :query => {:filter => query_filter, })["stories"]) | |
end | |
stories | |
end | |
end | |
FreshBooks.setup("#{$fb_subdomain}.freshbooks.com", $fb_token) | |
Tracker.setup($project_id, $pt_token, true) | |
invoice = FreshBooks::Invoice.get($invoice_id) | |
stories = Tracker.find("#{$pt_user} includedone:true modified_since:#{$since_date}") | |
invoice.notes = "" | |
stories.each do |story| | |
invoice.notes += "[##{story["id"]}] #{story["name"]}\n" | |
end | |
puts invoice.notes | |
invoice.update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment