Class: Contacts::OAuthConsumer

Inherits:
Consumer
  • Object
show all
Defined in:
lib/contacts/oauth_consumer.rb

Direct Known Subclasses

Google, Yahoo

Instance Attribute Summary collapse

Attributes inherited from Consumer

#error

Instance Method Summary collapse

Methods inherited from Consumer

configuration, configuration_attribute, configure, #contacts, deserialize, #serialize

Constructor Details

#initialize(consumer_options, request_token_params) ⇒ OAuthConsumer

Returns a new instance of OAuthConsumer.



9
10
11
12
# File 'lib/contacts/oauth_consumer.rb', line 9

def initialize(consumer_options, request_token_params)
  @consumer_options = consumer_options
  @request_token_params = request_token_params
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



29
30
31
# File 'lib/contacts/oauth_consumer.rb', line 29

def access_token
  @access_token
end

#request_tokenObject

Returns the value of attribute request_token.



28
29
30
# File 'lib/contacts/oauth_consumer.rb', line 28

def request_token
  @request_token
end

Instance Method Details

#authentication_url(target = self.return_url) ⇒ Object



31
32
33
34
# File 'lib/contacts/oauth_consumer.rb', line 31

def authentication_url(target = self.return_url)
  @request_token = consumer.get_request_token({:oauth_callback => target}, @request_token_params)
  @request_token.authorize_url
end

#authorize(params) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/contacts/oauth_consumer.rb', line 36

def authorize(params)
  begin
    @access_token = @request_token.get_access_token(:oauth_verifier => params['oauth_verifier'])
  rescue OAuth::Unauthorized => error
    @error = error.message
  end
end

#initialize_serialized(data) ⇒ Object



14
15
16
17
18
19
# File 'lib/contacts/oauth_consumer.rb', line 14

def initialize_serialized(data)
  value = data['request_token'] and
    @request_token = deserialize_oauth_token(consumer, value)
  value = data['access_token'] and
    @access_token = deserialize_oauth_token(consumer, value)
end

#serializable_dataObject



21
22
23
24
25
26
# File 'lib/contacts/oauth_consumer.rb', line 21

def serializable_data
  data = {}
  data['access_token'] = serialize_oauth_token(@access_token) if @access_token
  data['request_token'] = serialize_oauth_token(@request_token) if @request_token
  data
end