Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use the current Basecamp API with ActiveResource?
    primarykey
    data
    text
    <p>I'm trying to use the Basecamp Classic API (<a href="http://developer.37signals.com/basecamp/comments.shtml" rel="nofollow">http://developer.37signals.com/basecamp/comments.shtml</a>). The current basecamp-wrapper version was giving me fits, one of the things was because the json responses include pagination output, while the xml ones don't. That was an easy fix, but the problem is the url structure isn't standardized.</p> <p>The API specifies a few things like so, which lead me to believe it'd be simply separating out the element path and collection paths.</p> <blockquote> <pre><code>Get recent comments (for a commentable resource) GET /#{resource}/#{resource_id}/comments.xml Update comment PUT /comments/#{id}.xml </code></pre> </blockquote> <p>I've made several attempts at this and haven't really succeeded. Attempting to handle comments like this is hacky at best, and doesn't actually work because the element_path is different than the collection_path.</p> <pre><code>class Resource &lt; ActiveResource::Base self.site = "https://XXXX.basecamphq.com" self.user = "XXXX" self.password = "X" # This is just X according to the API, I have also read nil works self.format = :xml # json responses include pagination crap # Override element path so it isn't nested class &lt;&lt; self def element_path(id, prefix_options={}, query_options={}) prefix_options, query_options = split_options(prefix_options) if query_options.nil? "#{collection_name}/#{URI.parser.escape id.to_s}.#{format.extension}#{query_string(query_options)}" end end end class Project &lt; Resource end class Message &lt; Resource self.element_name = "post" self.prefix = "/projects/:project_id/" self.collection_name = "posts" def comments @comments ||= Comment.all(:params =&gt; {:resource =&gt; "posts" , :resource_id =&gt; id}) end end class Comment &lt; Resource self.prefix = "/:resource/:resource_id/" end puts m = Message.first(:params =&gt; {:project_id =&gt; PROJECT_ID}) puts m = Message.find(m.id) puts m.update_attribute(:title, "name") </code></pre> <p>This works up until the update_attribute, which is actually getting the proper non-nested url and it's making a PUT request that fails.</p> <p>Why doesn't this work for update? How do I handle the different parent resources in a better manner?</p> <p>Any tips would be awesome. :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload