Class: Kuaipan::Session

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/kuaipan/session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ Session

Returns a new instance of Session.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kuaipan/session.rb', line 12

def initialize(opt={})
  oauth_callback = opt.delete(:oauth_callback)
  @consumer = KAuth::Consumer.new(Config[:oauth_consumer_key], 
                                  Config[:oauth_consumer_secret], 
                                  Config.options_base)
  # get rtoken
  begin
    rtoken = @consumer.get_request_token(oauth_callback)
    @base = Base.new(@consumer)
    # set authorize_url
    @authorize_url = {authorize_url: "#{ Config[:authorize_url] }&oauth_token=#{ rtoken }"}
  rescue KAuth::KAuthError => myKauthError
    KpErrors.raise_errors(myKauthError.res)
  end
end

Instance Attribute Details

#authorize_urlObject (readonly)

Returns the value of attribute authorize_url.



5
6
7
# File 'lib/kuaipan/session.rb', line 5

def authorize_url
  @authorize_url
end

#baseObject (readonly)

Returns the value of attribute base.



5
6
7
# File 'lib/kuaipan/session.rb', line 5

def base
  @base
end

#consumerObject (readonly)

Returns the value of attribute consumer.



5
6
7
# File 'lib/kuaipan/session.rb', line 5

def consumer
  @consumer
end

Class Method Details

.skip_oauth_session(oauth_token, oauth_token_secret, user_id, opts = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/kuaipan/session.rb', line 46

def self.skip_oauth_session(oauth_token, oauth_token_secret, user_id, opts={})
  session = Session.new(opts)
  session.consumer.oauth_token = oauth_token
  session.consumer.oauth_token_secret = oauth_token_secret
  session.consumer.user_id = user_id
  session
end

Instance Method Details

#get_oauth_resultObject



40
41
42
43
44
# File 'lib/kuaipan/session.rb', line 40

def get_oauth_result
  {oauth_token: @consumer.oauth_token,
   oauth_token_secret: @consumer.oauth_token_secret,
   user_id: @consumer.user_id}
end

#set_atoken(oauth_verifier) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kuaipan/session.rb', line 28

def set_atoken(oauth_verifier)
  # set accesstoken
  begin
    @consumer.set_atoken(oauth_verifier)
    {oauth_token: @consumer.oauth_token,
     oauth_token_secret: @consumer.oauth_token_secret,
     user_id: @consumer.user_id}
  rescue KAuth::KAuthError => myKauthError
    KpErrors.raise_errors(myKauthError.res)
  end
end