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
http://developer.runkeeper.com/healthgraph/registration-authorization).

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.

    <script type="text/javascript" src="javascripts/
jquery-1.7.1.min.js"></script>

    <script type="text/javascript">

    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("<p>" + sent + "</p>");

    $.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("<p>" + data + "</p>");
    document.write("<p>" + status + "</p>");
    document.write("<p>" + xhr + "</p>");

    }
    }
    });

    }

    <%= 'get_access_token(\''+@code+'\',\''+@cc_id+'\',\''+@cc_s
+'\');' %>

   </script>

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 => 'fb66f35c944246588db30e1288501315',
        :redirect_uri => "http%3A%2F%2Fopenhealthdesigns.com%2Frktest"}}

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to