public
Created

  • Download Gist
api.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
# Projects
Project.all # get all projects
@project = Project.find('84948') # get specific project
 
# Members
@project.members.all # access a project's members
@project.members.add!(:role => 'Owner', :name => 'John Doe', :initials => 'JD', :email => 'john.doe@mymail.com') # add user to project
@member = @project.members.find('3747') # get specific member
@member.remove!
 
# Stories
@project.stories.all # access stories for project
@story = @project.stories.find('3838') # find specific project
@story.update!(:estimate => 4, :state => 'started', ...)
@story.delete!
 
@story.start!
@story.finish!
@story.deliver!
@story.accept!
@story.reject!
 
# Notes
@story.notes.all # get all notes
@story.notes.add(:text => "This story is close to finished")
 
# Tasks
 
# Attachments
 
# Iterations
 
# Activity Feed
api_mock.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
require 'rubygems'
require 'rest_client'
require 'nokogiri'
#require 'happy_mapper'
 
module PivotalTracker
class Client
class << self
attr_writer :use_ssl
end
 
def self.use_ssl
@use_ssl || false
end
 
def self.token(username, password, method='post')
response = if method == 'post'
RestClient.post 'https://www.pivotaltracker.com/services/tokens/active', :username => username, :password => password
else
RestClient.get "https://#{username}:#{password}@www.pivotaltracker.com/services/tokens/active"
end
@token ||= Nokogiri::XML(response).search('guid').inner_html
end
 
def self.connection(options={})
if use_ssl
@secure_connection ||= RestClient::Resource.new('https://www.pivotaltracker.com/services/v2', :headers => {'X-TrackerToken' => @token, 'Content-Type' => 'application/xml'})
else
@connection ||= RestClient::Resource.new('http://www.pivotaltracker.com/services/v2', :headers => {'X-TrackerToken' => @token, 'Content-Type' => 'application/xml'})
end
end
 
end
 
 
class Project
 
class << self
def all
# /projects
# Parse each and create new project array
# response.each {|x| projects << parse(x) }
#parse(connection['/projects'].get)
Client.connection['/projects'].get
end
 
def find(id)
# http://www.pivotaltracker.com/services/v2/projects/#{id}
# parse response
#parse(connection['/projects/#{id}'])
Client.connection["/projects/#{id}"].get
end
end
 
attr_accessor :stories
 
def initialize
self.stories ||= []
end
 
end
 
 
class Story
attr_accessor :project
 
def initialize(project_id)
self.project = project_id
end
 
def all
Client.connection["/projects/#{project}/stories"].get
end
 
end
 
Client.token("justin.smestad@hotmail.com", "my_password")
@project = Project.new
# Project.all
Client.use_ssl = true
Project.find('4165')
p @project.stories.nil?
p Story.new('4165').all
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.