How to send a post request and receive json back in rails?

Up vote 0 down vote favorite share g+ share fb share tw.

I've looked through a fair amount of the questions - yet, I am still confused. I am making a Rails app that connects with the Healthgraph API (here developer.runkeeper.com/healthgraph/regi...). I am supposed to make a POST request via Rails - based on a parameter I recieve and then recieve the JSON.

I have tried the outh2, runkeeper and other gems and they don't work because of a certain dependency. However, I am lost on how to POST via Rails and recieve a response. I do get the code back in my controller - however, I still don't know how to get an access token.

Def rktest respond_to if params:code require 'oauth2' @code=params:code @cc_id=client_id @client_s=client_secret else @code="None" end I'm trying to also do it via Javascript - but I'd rather not - since it leaves my client secret exposed. Also, I don't recieve data back either. Function get_access_token(code,ccid,cc_s){ $.

AjaxSetup({ 'beforeSend': function(xhr){ xhr. SetRequestHeader("Accept", "text/javascript") } }); var sent = { 'grant_type': 'authorization_code', 'code': code, 'client_id': ccid, 'client_secret': cc_s, 'redirect_uri': 'http://myurl.com/rktest' }; document. Write("" + sent + ""); $.

Ajax({ url: 'https://runkeeper.com/apps/token', data: sent, type: 'POST', dataType: 'json', success: function(data, status, xhr){ if (status === 'error' ||!xhr. ResponseText){ handleError(); }else{ document. Write("" + data + ""); document.

Write("" + status + ""); document. Write("" + xhr + ""); } } }); } Also, here is my routes file currently: match '/rktest', :to => 'main#rktest', :via => :get, :post Even this does not work. RestClient.

Post 'https://runkeeper.com/apps/token', {:params => { :grant_type => 'authorization_code', :code => @code, :client_id => '8e9b36478b764ac38ef1bdabc6d14d60', :client_secret => something, :redirect_uri => "http%3A%2F%2Fopenhealthdesigns.com%2Frktest"}} javascript ruby-on-rails ruby-on-rails-3 json oauth link|improve this question edited Jan 16 at 21:10 asked Jan 16 at 20:13econclicks174 67% accept rate.

Have a look at rubyinside.com/nethttp-cheat-sheet-2940.....

Still confused. Can somebody elucidate? – econclicks Jan 16 at 22:19.

I am using respond_to :json at the top of a controller file with respond_with @notes in the method that I want to return the json, and it works well. The app uses Ajax to return data for an search feature, but I don't think how the data is being called should make a difference. A litte more code for context: class NotesController :class) end respond_with @notes end API Docs - depending on how the method is being called.

If using . Json, a respond_to block would work also. Respond_with respond_to.

– econclicks Jan 16 at 21:12 This is actually a get request, but the type of request should not matter. I am showing you how I am returning json in a Rails 3.1 app. If you place the respond_to :json line in your file and use respond_with , it will return json.

– Scott Radcliff Jan 17 at 4:45.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions