RestClient with api - complex headers


Jonathan Brown <johnnybrown7@...>
 

the api I'm working with is here:

I'm able to log in fine and get back an auth token, but cant figure out how to do anything that requires a token. I get back a forbidden response when I try to get or post a private URL.

they give an example of the request that needs to be sent using curl:

curl \ --header 'Authorization: UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"' \ -X POST \ 'https://api.smarkets.com/v1/users/renew'

My question is: how would one send an equivalent request using the RestClient library in Ruby? I have a feeling that i'm messing up the header because the header in RestClient is all {:key => 'value'} pairs and I don't see how that would translate to the header given in the example.


Adam Wiggins <adam@...>
 

On Fri, Jul 30, 2010 at 3:38 PM, Jonathan Brown <johnnybrown7@...> wrote:

curl \ --header 'Authorization: UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"' \ -X POST \ 'https://api.smarkets.com/v1/users/renew'

How about:

RestClient.post 'https://api.smarkets.com/v1/users/renew', :authorization => 'UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"'


Jonathan Brown <johnnybrown7@...>
 

Thanks much.

that worked with one small tweak: RestClient.post 'https://api.smarkets.com/v1/users/renew', {}, :authorization => 'UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"'

with the added empty hash because headers is the third argument to RestClient.post . Thanks for making this I would have hated to output curl commands or use Net::HTTP, your framework is the perfect tool for this job.

Johnny

On Fri, Jul 30, 2010 at 6:07 PM, Adam Wiggins <adam@...> wrote:
On Fri, Jul 30, 2010 at 3:38 PM, Jonathan Brown <johnnybrown7@...> wrote:

curl \ --header 'Authorization: UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"' \ -X POST \ 'https://api.smarkets.com/v1/users/renew'

How about:

RestClient.post 'https://api.smarkets.com/v1/users/renew', :authorization => 'UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"'



Jonathan Brown <johnnybrown7@...>
 

p.s. the question is on StackOverflow is you want the karma


On Fri, Jul 30, 2010 at 7:21 PM, Jonathan Brown <johnnybrown7@...> wrote:
Thanks much.

that worked with one small tweak: RestClient.post 'https://api.smarkets.com/v1/users/renew', {}, :authorization => 'UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"'

with the added empty hash because headers is the third argument to RestClient.post . Thanks for making this I would have hated to output curl commands or use Net::HTTP, your framework is the perfect tool for this job.

Johnny

On Fri, Jul 30, 2010 at 6:07 PM, Adam Wiggins <adam@...> wrote:
On Fri, Jul 30, 2010 at 3:38 PM, Jonathan Brown <johnnybrown7@...> wrote:

curl \ --header 'Authorization: UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"' \ -X POST \ 'https://api.smarkets.com/v1/users/renew'

How about:

RestClient.post 'https://api.smarkets.com/v1/users/renew', :authorization => 'UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"'