Class: LinkedIn::OAuth

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/linked_in/oauth.rb

Overview

>> oauth = LinkedIn::OAuth.new(‘token’, ‘secret’)

> #<LinkedIn::OAuth:0x1021db048 …>

>> oauth.request_token.authorize_url

> “api.linkedin.com/uas/oauth/authorize?oauth_token=XXXX” # goto URL

>> oauth.authorize_from_request(oauth.request_token.token, oauth.request_token.secret, PIN) DONE

Constant Summary collapse

SITE_URL =
'https://api.linkedin.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctoken, csecret, options = {}) ⇒ OAuth

Options



18
19
20
21
22
23
24
25
26
# File 'lib/linked_in/oauth.rb', line 18

def initialize(ctoken, csecret, options={})
  @ctoken = ctoken
  @csecret = csecret
  @consumer_options = {
    :request_token_path => "/uas/oauth/requestToken?oauth_callback=oob",
    :access_token_path  => "/uas/oauth/accessToken",
    :authorize_path     => "/uas/oauth/authorize"
  }.merge(options)
end

Instance Attribute Details

#consumer_optionsObject (readonly)

Returns the value of attribute consumer_options.



15
16
17
# File 'lib/linked_in/oauth.rb', line 15

def consumer_options
  @consumer_options
end

#csecretObject (readonly)

Returns the value of attribute csecret.



15
16
17
# File 'lib/linked_in/oauth.rb', line 15

def csecret
  @csecret
end

#ctokenObject (readonly)

Returns the value of attribute ctoken.



15
16
17
# File 'lib/linked_in/oauth.rb', line 15

def ctoken
  @ctoken
end

Instance Method Details

#access_tokenObject



52
53
54
# File 'lib/linked_in/oauth.rb', line 52

def access_token
  @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
end

#authorize_from_access(atoken, asecret) ⇒ Object



56
57
58
# File 'lib/linked_in/oauth.rb', line 56

def authorize_from_access(atoken, asecret)
  @atoken, @asecret = atoken, asecret
end

#authorize_from_request(rtoken, rsecret, verifier_or_pin) ⇒ Object

For web apps use params, for desktop apps, use the verifier is the pin that twitter gives users.



46
47
48
49
50
# File 'lib/linked_in/oauth.rb', line 46

def authorize_from_request(rtoken, rsecret, verifier_or_pin)
  request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
  access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
  @atoken, @asecret = access_token.token, access_token.secret
end

#consumerObject



28
29
30
# File 'lib/linked_in/oauth.rb', line 28

def consumer
  @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => SITE_URL}.merge(consumer_options))
end

#request_token(options = {}) ⇒ Object

Note: If using oauth with a web app, be sure to provide :oauth_callback. Options:

:oauth_callback => String, url that linkedin should redirect to


40
41
42
# File 'lib/linked_in/oauth.rb', line 40

def request_token(options={})
  @request_token ||= consumer.get_request_token(options)
end

#set_callback_url(url) ⇒ Object



32
33
34
35
# File 'lib/linked_in/oauth.rb', line 32

def set_callback_url(url)
  clear_request_token
  request_token(:oauth_callback => url)
end