Class: BirdGrinder::Tweeter::OAuthAuthorization

Inherits:
AbstractAuthorization show all
Defined in:
lib/bird_grinder/tweeter/oauth_authorization.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractAuthorization

#add_header_to

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/bird_grinder/tweeter/oauth_authorization.rb', line 18

def self.enabled?
  oauth = BirdGrinder::Settings.oauth
  oauth.present? && [:consumer_key, :consumer_secret, :access_token_token, :access_token_secret].all? { |k| oauth[k].present? }
end

.request_tokenObject



33
34
35
# File 'lib/bird_grinder/tweeter/oauth_authorization.rb', line 33

def self.request_token
  @request_token ||= self.oauth_consumer.get_request_token
end

.retrieve_access_token!(raw_request_token, request_secret, pin) ⇒ Object

From the twitter gem, with modification



24
25
26
27
28
29
30
31
# File 'lib/bird_grinder/tweeter/oauth_authorization.rb', line 24

def self.retrieve_access_token!(raw_request_token, request_secret, pin)
  request_token = OAuth::RequestToken.new(self.oauth_consumer, raw_request_token, request_secret)
  access_token  = request_token.get_access_token(:oauth_verifier => pin)
  original_settings = BirdGrinder::Settings.oauth.to_hash
  original_settings.merge! :access_token_token => access_token.token,
                           :access_token_secret => access_token.secret
  BirdGrinder::Settings.update! :oauth => original_settings.stringify_keys
end

Instance Method Details

#header_for(request) ⇒ Object

Authenticates a given request.



11
12
13
14
15
16
# File 'lib/bird_grinder/tweeter/oauth_authorization.rb', line 11

def header_for(request)
  OAuth::Client::Helper.new(request, {
    :token    => self.class.oauth_access_token,
    :consumer => self.class.oauth_consumer
  }).header
end