whichdigital / active-rest-client

ActiveRestClient API Client
https://rubygems.org/gems/active_rest_client
MIT License
386 stars 44 forks source link

Feature request: auto escape :id or allow overriding the value of :id easily #96

Closed l4u closed 9 years ago

l4u commented 9 years ago

related #94

l4u commented 9 years ago

Currently I can change the URL after the :id is mapped to it. Is there a way I can change the value of :id before the URL mapping?

andyjeffries commented 9 years ago

I don't understand the bug report/problem? Using your code from the other ticket:

class Item < ActiveRestClient::Base
  base_url "http://api.my-url.com/v2"
  username 'username'
  password 'password'

  get :all, "/list/"
  get :find, "/items/:id"
end

To change the ID, you pass a different value in to the #find method, e.g.

Item.find(id: "Whatever you want here")

If you want it escaping, you can do that yourself (I wouldn't want to automatically escape them, just in case someone's API requires that they aren't escaped, or are escaped in some other way).

You can also adjust the ID within a filter - https://github.com/whichdigital/active-rest-client#using-filters

l4u commented 9 years ago

At before_request it seems that I can get the full URL, but not the :id in get_params. Currently, I can do Item.find(id: CGI.escape(item_id)). But is there a good place that I can move the CGI.escape into the model instead of placing it at the controller? THANKS!

andyjeffries commented 9 years ago

There's nowhere easy. This may be something that's possible with a Proxy, but I haven't tried.

What type of value are you passing in the ID field that need escaping?

l4u commented 9 years ago

The ID is an e-mail address. Maybe I will just use the above workaround. Thanks!