Grackle's appending of id breaks list members POST call

3 views
Skip to first unread message

Alex Kahn

unread,
Feb 26, 2010, 4:30:01 PM2/26/10
to Grackle Development
Hi,

I'm attempting to add a user to a list. To do this, I need to POST
to /:user/:list_id/members (:user is the owner of the group) with an
id parameter that refers to a user to add to the list. Here's what my
call looks like:

client.alexanderkahn._('funny-list').members! :id => 2352334

This returns a 404, because the URL I'm posting to is:
http://twitter.com/alexanderkahn/funny-list/members/23523333.json

I believe this URL is getting used because the call_with_format method
appends my ID parameter to the URL to be requested rather than passing
it along as a POST parameter. Here's that method:

def call_with_format(format)
id = request.params.delete(:id)
request << "/#{id}" if id
request << ".#{format}"
res = send_request
process_response(format,res)
ensure
clear
end

(http://github.com/hayesdavis/grackle/blob/master/lib/grackle/
client.rb#L215-223)

Am I correct in guessing that this appending is causing this error? I
guess that some Twitter API methods will happily take the ID at the
end of the URL, but this one I'm trying to use doesn't.

I would appreciate any ideas or guidance on how to fix or work around
this problem.

Thanks,
Alex

Hayes Davis

unread,
Feb 28, 2010, 8:53:41 PM2/28/10
to grac...@googlegroups.com
Alex,

Sorry for taking so long to respond. Unfortunately the best solution I could put around this is to add a flag on the Grackle::Client that toggles this behavior. If you go get the latest Grackle gem that I just released (0.1.9... it also contains your README changes... thanks!), you can set :auto_append_ids=>false in your Grackle::Client constructor options and it will give you the behavior you want. You can also set client.auto_append_ids = false if you want to turn this on/off on an existing client instance.

If you have any thoughts on a better way to solve this problem that doesn't break existing behaviors, I'm definitely open to suggestions. Hopefully this flag will do the trick for your needs.

Hayes

Todd Dewell

unread,
Feb 28, 2010, 9:53:37 PM2/28/10
to grac...@googlegroups.com
I'm going to try this fix and thing this approach is fine.  I just hacked the code out that appended the id to get
something working fast.  Will let you know how it worked.  Thanks for putting this in.

Todd

Alex Kahn

unread,
Mar 1, 2010, 3:52:14 PM3/1/10
to Grackle Development
Hi,

I think this solution will work for me. Thanks for adding it in.

In some early use, it looks like it will be clunky to have to disable
appending before a call and enable after a call. I can't set it
globally since two of the methods I'm using need this switched on or
off. Something that could be less clunky would be a switch on the
client itself, like the switch for API version or REST vs. search API.
So the call would look like:

client[:no_append].alexanderkahn.23434.members! :id => 234234

Then I wouldn't have to worry about enabling/disabling. Hayes, what
are your thoughts on this?

Cheers,
Alex

> > client.rb#L215-223<http://github.com/hayesdavis/grackle/blob/master/lib/grackle/%0Aclien...>

Hayes Davis

unread,
Mar 2, 2010, 11:30:46 AM3/2/10
to grac...@googlegroups.com
Alex,

I guess the most generic solution would be a cleaner mechanism for including ids as a method call at the end of a method chain that you can use all the time instead of the :id=>some_id mechanism.

You can do any of the following now:

  client.users.show._("#{some_id}?")

... which is ugly.

or

  client.users.show._(some_id).json

... which requires that you specify the format.

or

  client.get { users.show._(some_id) }

... using Grackle's block syntax for HTTP verbs which looks pretty nice but is a little more complex.


An new feature could be a special convention for a parameter that should actually be appended. You could run the client with auto_append_ids = false and then use this convention if you wanted to append a parameter to the path.

  client.users.show? :_ => some_id

... which would append some_id to the request path.

Thoughts?

Hayes
Reply all
Reply to author
Forward
0 new messages