Class: Atig::OAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/atig/oauth.rb

Constant Summary collapse

CONSUMER_KEY =
'TO9wbD379qmFSJp6pFs5w'
CONSUMER_SECRET =
'Gap8ishP3J3JrjH4JEspcii4poiZgMowHRazWGM1cYg'
@@profiles =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, nick) ⇒ OAuth

Returns a new instance of OAuth.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/atig/oauth.rb', line 24

def initialize(context, nick)
  uri = URI(context.opts.api_base)
  site = "https://#{uri.host}"

  @nick  = nick
  @oauth = ::OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, {
                                   site: site,
                                   proxy: ENV["HTTP_PROXY"] || ENV["http_proxy"]
                                 })

  if @@profiles.key? @nick
    token,secret = @@profiles[@nick]
    @access = ::OAuth::AccessToken.new(@oauth, token, secret)
  end
end

Instance Attribute Details

#accessObject (readonly)

Returns the value of attribute access.



21
22
23
# File 'lib/atig/oauth.rb', line 21

def access
  @access
end

#oauthObject (readonly)

Returns the value of attribute oauth.



22
23
24
# File 'lib/atig/oauth.rb', line 22

def oauth
  @oauth
end

Class Method Details

.dumpObject



12
13
14
# File 'lib/atig/oauth.rb', line 12

def dump
  @@profiles
end

.load(profiles) ⇒ Object



16
17
18
# File 'lib/atig/oauth.rb', line 16

def load(profiles)
  @@profiles = profiles
end

Instance Method Details

#urlObject



44
45
46
47
# File 'lib/atig/oauth.rb', line 44

def url
  @request = @oauth.get_request_token
  @request.authorize_url
end

#verified?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/atig/oauth.rb', line 40

def verified?
  @access != nil
end

#verify(code) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/atig/oauth.rb', line 49

def verify(code)
  @access = @request.get_access_token(oauth_verifier: code)
  if @access then
    @@profiles[@nick] = [ @access.token , @access.secret ]
  end
rescue
  false
end