Module: Yt::Associations::Authenticable
- Defined in:
- lib/yt/associations/has_authentication.rb
Instance Method Summary collapse
- #auth ⇒ Object
- #authentication ⇒ Object
- #authentication_url ⇒ Object
- #initialize(options = {}) ⇒ Object
-
#refresh ⇒ Object
Obtains a new access token.
Instance Method Details
#auth ⇒ Object
32 33 34 |
# File 'lib/yt/associations/has_authentication.rb', line 32 def auth self end |
#authentication ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/yt/associations/has_authentication.rb', line 36 def authentication @authentication = current_authentication @authentication ||= use_refresh_token! if @refresh_token @authentication ||= if @authorization_code @authentication ||= use_device_code! if @device_code @authentication ||= raise_missing_authentication! end |
#authentication_url ⇒ Object
44 45 46 47 48 49 |
# File 'lib/yt/associations/has_authentication.rb', line 44 def authentication_url host = 'accounts.google.com' path = '/o/oauth2/auth' query = authentication_url_params.to_param URI::HTTPS.build(host: host, path: path, query: query).to_s end |
#initialize(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/yt/associations/has_authentication.rb', line 22 def initialize( = {}) @access_token = [:access_token] @refresh_token = [:refresh_token] @device_code = [:device_code] @expires_at = [:expires_at] @authorization_code = [:authorization_code] @redirect_uri = [:redirect_uri] @scopes = [:scopes] end |
#refresh ⇒ Object
Obtains a new access token. Returns true if the new access token is different from the previous one
53 54 55 56 57 |
# File 'lib/yt/associations/has_authentication.rb', line 53 def refresh old_access_token = authentication.access_token @authentication = @access_token = @refreshed_authentications = nil old_access_token != authentication.access_token end |