API - ActiveResource client
it seems as though Pivotal is written in rails, but I've been having a bear of a time trying to integrate with the API using a standard rails ActiveResource client. The following code generates errors because the xml response is not formatted as a "standard" rails rest response.
class Story < ActiveResource::Base
PROJECT_ID = 3575
TOKEN = 'my_api_token'
self.site = "https://www.pivotaltracker.com/services/v1/projects/#{PROJECT_ID}"
def self.headers
{'Token' => TOKEN}
end
end
Story.find :all
any ideas on how to fix this?
class Story < ActiveResource::Base
PROJECT_ID = 3575
TOKEN = 'my_api_token'
self.site = "https://www.pivotaltracker.com/services/v1/projects/#{PROJECT_ID}"
def self.headers
{'Token' => TOKEN}
end
end
Story.find :all
any ideas on how to fix this?
3
people have this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
-
Inappropriate?The server piece of Tracker happens to be written in Rails, but we have a mixture of client technologies used to connect to the Tracker API.
As it stands right now, ActiveResource out of box will not work with the API. ActiveResource is very particular about the format of the XML, that specific format in some cases doesn't play nice with some of the other client technologies.
We are currently looking into a more neutral XML format that will work ActiveResource as well as the other client technologies used. -
Does it work now? -
Inappropriate?Yes we were able to come up with a neutral XML format, take a look at the API help page for more details http://www.pivotaltracker.com/help/api.
-
Inappropriate?Thanks! I tried it with stories and it worked. However, I cannot get a list of projects, or the details of one project via ActiveResource. I can access it via Curl.
My ActiveResource class is the following:
self.element_name = "project"
self.site = URI::parse("http://www.pivotaltracker.com/services/v2/projects/6212")
headers['X-TrackerToken'] = api_token
I tried to access it via:
PivotalProject.find(6212, :params => {:project_id => 6212}) and other varations
No matter what, I get a 404 resource not found error.
I’m anxious but excited
-
Inappropriate?Thanks for letting us know that ActiveResource isn't working for the project resource, I added bug for it.
-
Thank you for the confirmation. I am sure it will be fixed soon. In the meantime, I will use the API directly via Net::HTTP::start -
It works now. Excellent. Thank you. It was my bad. -
Inappropriate?After looking at your example more carefully. Your site for the PivotalProject ActiveResource is wrong. It should be:
self.site = "http://www.pivotaltracker.com/services/v2"
or
self.site =
URI::parse("http://www.pivotaltracker.com/services/v2")
Then PivotalProject.find(6212) and PivotalProject.find(:all) should work for you. If it doesn't let us know.
1 person says
this answers the question
-
Just realized that I did not reply. It works now. Excellent. Thank you. It was my bad. -
Inappropriate?I finally got a chance to test out the v2 api with an active resouce client, and could not get the examples to work. I keep getting a 400 http response from the pivotal api.
require 'rubygems'
require 'activeresource'
class Story < ActiveResource::Base
PROJECT_ID = 3575
TOKEN = 'secret'
self.site = "http://www.pivotaltracker.com/services/v2/projects/#{PROJECT_ID}"
headers['X-TrackerToken'] = TOKEN
end
error:
ActiveResource::BadRequest: Failed with 400 Bad Request
from /opt/local/lib/ruby/gems/1.8/gems/activeresource-2.3.2/lib/active_resource/connection.rb:164:in `handle_response'
from /opt/local/lib/ruby/gems/1.8/gems/activeresource-2.3.2/lib/active_resource/connection.rb:151:in `request'
from /opt/local/lib/ruby/gems/1.8/gems/activeresource-2.3.2/lib/active_resource/connection.rb:116:in `get'
from /opt/local/lib/ruby/gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:576:in `find_every'
from /opt/local/lib/ruby/gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:519:in `find'
from (irb):2
Is this an issue with using rails 2.3?
I’m frustrated
-
Inappropriate?Okay, i'm back up and running now. The example code uses "http://pivotaltracker.com", but I needed to be running on https.
once I made that change, it worked fine.
I’m happy
Loading Profile...



