Class: Metova::Oauth::TwitterProvider

Inherits:
GenericProvider show all
Defined in:
lib/metova/oauth/twitter_provider.rb

Constant Summary collapse

TWITTER_SITE_URL =
'https://api.twitter.com'
TWITTER_API_URL =
'https://api.twitter.com/1.1'
ME_URL =
"#{TWITTER_API_URL}/account/verify_credentials.json?include_entities=false&skip_status=true"

Instance Attribute Summary

Attributes inherited from GenericProvider

#access_token, #info, #token_secret, #uid

Instance Method Summary collapse

Methods inherited from GenericProvider

authenticate, #initialize

Constructor Details

This class inherits a constructor from Metova::Oauth::GenericProvider

Instance Method Details

#authenticateObject



8
9
10
11
12
# File 'lib/metova/oauth/twitter_provider.rb', line 8

def authenticate
  self.info = OmniAuth::AuthHash.new me
  self.uid = info.id
  self
end

#consumerObject



32
33
34
35
36
37
# File 'lib/metova/oauth/twitter_provider.rb', line 32

def consumer
  @consumer ||= begin
    raise Metova::Oauth::Error::DeviseNotConfigured.new unless setup_with_devise?
    OAuth::Consumer.new(consumer_key, consumer_secret, site: TWITTER_SITE_URL, scheme: :header)
  end
end

#meObject



22
23
24
25
26
# File 'lib/metova/oauth/twitter_provider.rb', line 22

def me
  super do
    JSON.parse oauth_access_token.get(ME_URL).body
  end
end

#nameObject



14
15
16
# File 'lib/metova/oauth/twitter_provider.rb', line 14

def name
  'Twitter'
end

#oauth_access_tokenObject



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

def oauth_access_token
  OAuth::AccessToken.from_hash consumer, oauth_token: access_token, oauth_token_secret: token_secret
end

#providerObject



18
19
20
# File 'lib/metova/oauth/twitter_provider.rb', line 18

def provider
  :twitter
end