Class: AWeber::OAuth

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of OAuth.



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

def initialize(consumer_token, consumer_secret, options={})
  @consumer_token  = consumer_token
  @consumer_secret = consumer_secret
end

Instance Method Details

#access_tokenObject



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

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



62
63
64
65
# File 'lib/aweber/oauth.rb', line 62

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



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

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



69
70
71
72
# File 'lib/aweber/oauth.rb', line 69

def clear_tokens
  @request_token = nil
  @access_token  = nil
end

#consumerObject



12
13
14
15
16
17
18
19
20
# File 'lib/aweber/oauth.rb', line 12

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



26
27
28
# File 'lib/aweber/oauth.rb', line 26

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

#request_token=(request_token) ⇒ Object

Set a Request Token

@param [Request Token] request_token the oauth request token to be set.


34
35
36
# File 'lib/aweber/oauth.rb', line 34

def request_token=(request_token)
  @request_token = request_token
end