Skip to content

@jsmestad /api.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
# 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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.