Class: AWeber::OAuth

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer_token, consumer_secret, options = {}) ⇒ OAuth

Returns a new instance of OAuth.



9
10
11
12
13
# File 'lib/aweber/oauth.rb', line 9

def initialize(consumer_token, consumer_secret, options={})
  @consumer_token  = consumer_token
  @consumer_secret = consumer_secret
  @callback_url    = options[:callback_url]
end

Instance Attribute Details

#callback_urlObject

Returns the value of attribute callback_url.



7
8
9
# File 'lib/aweber/oauth.rb', line 7

def callback_url
  @callback_url
end

Instance Method Details

#access_tokenObject



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

def access_token
  @access_token ||= ::OAuth::AccessToken.new(consumer, @access_token_key,
    @access_token_secret)
end

#authorize_with_access(access_token_key, access_token_secret) ⇒ Object

Authorize with an Access Token key and secret you’ve previously retrieved via a user authentication.

Parameters:

  • access_token_key (String)

    Access Token key

  • access_token_secret (String)

    Access Token secret



57
58
59
60
# File 'lib/aweber/oauth.rb', line 57

def authorize_with_access(access_token_key, access_token_secret)
  @access_token_key    = access_token_key
  @access_token_secret = access_token_secret
end

#authorize_with_verifier(verifier) ⇒ Object

Get an Access Token from a Request Token using the verifier code.

Parameters:

  • verifier (String)

    Verification code retrieved from user authentication



39
40
41
42
43
44
# File 'lib/aweber/oauth.rb', line 39

def authorize_with_verifier(verifier)
  token = request_token.get_access_token(:oauth_verifier => verifier)
  @access_token_key    = token.token
  @access_token_secret = token.secret
  access_token
end

#clear_tokensObject

Remove any active token instances and start over



64
65
66
67
# File 'lib/aweber/oauth.rb', line 64

def clear_tokens
  @request_token = nil
  @access_token  = nil
end

#consumerObject



15
16
17
18
19
20
21
22
23
# File 'lib/aweber/oauth.rb', line 15

def consumer
  @consumer ||= ::OAuth::Consumer.new(@consumer_token, @consumer_secret, {
    :site               => AWeber.auth_endpoint,
    :request_token_path => "/#{AWeber::AUTH_VERSION}/oauth/request_token",
    :authorize_path     => "/#{AWeber::AUTH_VERSION}/oauth/authorize",
    :access_token_path  => "/#{AWeber::AUTH_VERSION}/oauth/access_token",
    :scheme             => :query_string
  })
end

#request_token(options = {}) ⇒ Object

Retrieve a Request Token or simply return it, if it already exists.

Parameters:

  • options (Hash) (defaults to: {})

    OAuth parameters. :oauth_callback for example



29
30
31
# File 'lib/aweber/oauth.rb', line 29

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