Hey,
So I tried the ActiveResource client from the http://www.pivotaltracker.com/help/ap...
and the below is my simple code, I had set my "my_proj_id" and "my_token" properly.
require 'rubygems'
require 'activeresource'
class Story < ActiveResource::Base
self.site = "http://www.pivotaltracker.com/service..."
headers['X-TrackerToken'] = ''
end
Story.find(:all)
The error it throws:
/home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:182:in `typecast_xml_value': can't typecast "307" (RuntimeError)
from /home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:208:in `block in typecast_xml_value'
from /home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:207:in `each'
from /home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:207:in `inject'
from /home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:207:in `typecast_xml_value'
from /home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:164:in `from_xml'
from /home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activeresource-2.3.5/lib/active_resource/formats/xml_format.rb:19:in `decode'
from /home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activeresource-2.3.5/lib/active_resource/connection.rb:138:in `get'
from /home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activeresource-2.3.5/lib/active_resource/base.rb:639:in `find_every'
from /home/victoria7/.rvm/gems/ruby-1.9.1-p378/gems/activeresource-2.3.5/lib/active_resource/base.rb:582:in `find'
from pivotal_story.rb:10:in `'
Has this got something to do with the xml data that comes as part of the response?
I did search for this error in the existing topics but could not find one. Sorry if it is an already answered one and do point me to the topic.
Thanks for all help!
Official
Response
-
The following workaround by jeremyhaberman seem to work, so I'm posting that as the "official" workaround to this issue. Thanks Jeremy! :
To work around this issue, I put the following in a file named 'tracker_xml_fix.rb' in config/initializers:
class Hash
class << self
alias_method :from_xml_original, :from_xml
def from_xml(xml)
scrubbed = scrub_attributes(xml)
from_xml_original(scrubbed)
end
def scrub_attributes(xml)
xml.gsub(/<stories.*>/, "<stories type=\"array\">")
end
end
end
And it seems to have done the trick. It removes all the attributes from the top-level 'stories' element except for the 'type' attribute (actually, it removes the 'type' attribute and its value and restores it, assuming it was 'type="array"').
-
I have the same problem with ruby 1.9.2p0, use to work fine with 1.8.6.
-
-
I'm also using Ruby 1.9.2p0 and Rails 3.0.3
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/core_ext/hash/conversions.rb:96:in `typecast_xml_value' -
-
Thanks, we have opened a bug to investigate...
-
-
-
It's still in the backlog. Anyone is welcome to investigate further and tell us exactly what it is about Tracker's response that ActiveResource doesn't like ;)
-
-
-
-
-
I've tracked it down. It's the 'total' and 'count' attributes on the root of the stories XML (and I assume anywhere else there's 'total' and 'count' attributes on an array).
...
<stories type="array" count="67" total="67">
...
I'm pretty sure if you add any attribute there that isn't 'type' it will throw an error when it tries to convert it from XML to Hash.
It looks like this problem was also encountered on Redmine:
http://www.redmine.org/issues/4745- view 1 more comment
-
-
Good news! Any clue on when the next major API revision will be? Are we talking weeks, months, year? Thanks.
-
-
Chad, I'd love an update on this one. I just spent most of a day pulling my hair out before stumbling on this thread.
-
-
-
-
I am trying to follow your guide on the pivotal api using ruby and everything works except for getting stories using Active Resource. Here is my current simple code taken from your tutorial:
require 'rubygems'
require 'active_resource'
class Story < ActiveResource::Base
self.site = "http://www.pivotaltracker.com/service..."
headers['X-TrackerToken'] = '5c5352c0dcb9b41158d75720ff57b593'
end
# Find stories
Story.find(:all)
Finding by ID gets me a story object which is okay. Finding using :all, :first, or :last gives me a:
Users/eumir/.rvm/gems/ruby-1.9.2-p180@aestimator/gems/activesupport-3.0.7/lib/active_support/core_ext/hash/conversions.rb:96:in `typecast_xml_value': can't typecast "15" (RuntimeError)
I can give more info if needed. Thanks!
This reply was created from a merged topic originally titled
Story active resource problem. -
-
So this bug makes the api incompatible with Rails3, and has been this way for over a year!?
If Pivotal is too lazy to fix such a glaring bug, then WHY IS THIS NOT AT LEAST MENTIONED IN THE API DOCS? -
-
To work around this issue, I put the following in a file named 'tracker_xml_fix.rb' in config/initializers:
class Hash
class << self
alias_method :from_xml_original, :from_xml
def from_xml(xml)
scrubbed = scrub_attributes(xml)
from_xml_original(scrubbed)
end
def scrub_attributes(xml)
xml.gsub(/<stories.*>/, "<stories type=\"array\">")
end
end
end
And it seems to have done the trick. It removes all the attributes from the top-level 'stories' element except for the 'type' attribute (actually, it removes the 'type' attribute and its value and restores it, assuming it was 'type="array"').-
Thanks... I banged my head against this problem repeatedly today, and your snippet has gotten me going again.
-
-
-
-
-
The following workaround by jeremyhaberman seem to work, so I'm posting that as the "official" workaround to this issue. Thanks Jeremy! :
To work around this issue, I put the following in a file named 'tracker_xml_fix.rb' in config/initializers:
class Hash
class << self
alias_method :from_xml_original, :from_xml
def from_xml(xml)
scrubbed = scrub_attributes(xml)
from_xml_original(scrubbed)
end
def scrub_attributes(xml)
xml.gsub(/<stories.*>/, "<stories type=\"array\">")
end
end
end
And it seems to have done the trick. It removes all the attributes from the top-level 'stories' element except for the 'type' attribute (actually, it removes the 'type' attribute and its value and restores it, assuming it was 'type="array"').-
I used that myself. But the point is that you *do not document that there is a problem in the API page*. The examples you give on that page will not actually work! So you need to note it there.
-
-
-
-
Loading Profile...



Twitter,
Facebook, or email.

EMPLOYEE



