rbz
rbz

Reputation: 769

getting "undefined method `auth_code' for "Client function":String"

I am trying to run a simple authentication call to retrieve profiles via linkedin.
I am running ruby on rails and tried the example "http://developer.linkedin.com/documents/code-samples" explained here.

When running my code, i get an this error
undefined method `auth_code' for "Client function":String

I have included in my GemFile the following:

   gem 'linkedin'
   gem 'oauth2'
   gem 'oauth'

With the following code:

 #Instantiate your OAuth2 client Object
  def client 
    OAuth2::Client.new(
      CONSUMER_KEY,
      CONSUMER_SECRET,
      :authorize_url => "/uas/oauth2/authorization?response_type=code",
      :token_url => "/uas/oauth2/accessToken",
      :site => "https://www.linkedin.com"
    )   
    pp 'Client function'
  end 

  def test1
    pp ' to authorize function'
    authorize
  end 

  def authorize
    pp 'in authorize'
    #Redirect user in order to authenticate
    redirect_to client.auth_code.authorize_url(:scope => 'r_fullprofile r_emailaddress r_network',
                                               :state => STATE,
                                               :redirect_uri => REDIRECT_URI)
  end 

So when it gets to redirect_to client.auth_code.authorize_url() i am getting undefined for "auth_code".

Any reason why this is? do i need another type of gem installed. I have tried bundle update and bundle install. Nothing is happening.

Any help is much appreciative. Thank you

Upvotes: 0

Views: 286

Answers (2)

Mark Thomas
Mark Thomas

Reputation: 37507

A ruby method returns the output of the last statement. In your case, it is the pp statement. Either remove the pp or put it at the beginning of the method.

Upvotes: 1

Lazarus Lazaridis
Lazarus Lazaridis

Reputation: 6029

Your client method returns the string "Client function" via the pp method instead of the client instance you create.

Upvotes: 1

Related Questions