Class: RedboothRuby::Session
- Inherits:
-
Object
- Object
- RedboothRuby::Session
- Defined in:
- lib/redbooth-ruby/session.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#auto_refresh_token ⇒ Object
Returns the value of attribute auto_refresh_token.
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#oauth_token ⇒ Object
Returns the value of attribute oauth_token.
-
#oauth_urls ⇒ Object
Returns the value of attribute oauth_urls.
-
#oauth_verifier ⇒ Object
Returns the value of attribute oauth_verifier.
-
#on_token_refresh(&block) ⇒ Object
Returns the value of attribute on_token_refresh.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #client ⇒ Object
- #get_access_token_url ⇒ Object
-
#initialize(opts = {}) ⇒ Session
constructor
A new instance of Session.
- #refresh_access_token! ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ Session
Returns a new instance of Session.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/redbooth-ruby/session.rb', line 12 def initialize(opts = {}) @token = opts[:token] @refresh_token = opts[:refresh_token] @expires_in = opts[:expires_in] @auto_refresh_token = opts[:auto_refresh_token] || true @on_token_refresh = opts[:on_token_refresh] @consumer_key = opts[:consumer_key] || RedboothRuby.configuration[:consumer_key] @consumer_secret = opts[:consumer_secret] || RedboothRuby.configuration[:consumer_secret] @oauth_verifier = opts[:oauth_verifier] @oauth_token = opts[:oauth_token] oauth2_base = opts[:oauth2_base] || RedboothRuby.configuration[:oauth2_base] || 'redbooth.com' oauth_site = "https://#{oauth2_base}/api/3" @oauth_urls = { site: "https://#{oauth2_base}/api/3", authorize_url: "https://#{oauth2_base}/oauth2/authorize", token_url: "https://#{oauth2_base}/oauth2/token" } end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/redbooth-ruby/session.rb', line 6 def access_token @access_token end |
#auto_refresh_token ⇒ Object
Returns the value of attribute auto_refresh_token.
7 8 9 |
# File 'lib/redbooth-ruby/session.rb', line 7 def auto_refresh_token @auto_refresh_token end |
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
8 9 10 |
# File 'lib/redbooth-ruby/session.rb', line 8 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
8 9 10 |
# File 'lib/redbooth-ruby/session.rb', line 8 def consumer_secret @consumer_secret end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
7 8 9 |
# File 'lib/redbooth-ruby/session.rb', line 7 def expires_in @expires_in end |
#oauth_token ⇒ Object
Returns the value of attribute oauth_token.
9 10 11 |
# File 'lib/redbooth-ruby/session.rb', line 9 def oauth_token @oauth_token end |
#oauth_urls ⇒ Object
Returns the value of attribute oauth_urls.
10 11 12 |
# File 'lib/redbooth-ruby/session.rb', line 10 def oauth_urls @oauth_urls end |
#oauth_verifier ⇒ Object
Returns the value of attribute oauth_verifier.
9 10 11 |
# File 'lib/redbooth-ruby/session.rb', line 9 def oauth_verifier @oauth_verifier end |
#on_token_refresh(&block) ⇒ Object
Returns the value of attribute on_token_refresh.
7 8 9 |
# File 'lib/redbooth-ruby/session.rb', line 7 def on_token_refresh @on_token_refresh end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
7 8 9 |
# File 'lib/redbooth-ruby/session.rb', line 7 def refresh_token @refresh_token end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/redbooth-ruby/session.rb', line 6 def token @token end |
Instance Method Details
#client ⇒ Object
36 37 38 39 40 |
# File 'lib/redbooth-ruby/session.rb', line 36 def client = @oauth_urls [:raise_errors] = false @client ||= OAuth2::Client.new(consumer_key, consumer_secret, ) end |
#get_access_token_url ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/redbooth-ruby/session.rb', line 42 def get_access_token_url uri = URI.parse(@oauth_urls[:token_url]) params = URI.decode_www_form(uri.query.to_s) params << ['oauth_verifier', oauth_verifier] if oauth_verifier params << ['oauth_token', oauth_token] if oauth_token uri.query = URI.encode_www_form(params) if params.size > 0 uri.to_s end |
#refresh_access_token! ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/redbooth-ruby/session.rb', line 56 def refresh_access_token! new_access_token = access_token.refresh! if new_access_token on_token_refresh.call(access_token, new_access_token) if on_token_refresh.is_a?(Proc) @token = new_access_token.token @refresh_token = new_access_token.refresh_token @expires_in = new_access_token.expires_in @access_token = nil end new_access_token end |
#valid? ⇒ Boolean
31 32 33 34 |
# File 'lib/redbooth-ruby/session.rb', line 31 def valid? return false unless token true end |