Class: GoogleR::Token
- Inherits:
-
Object
- Object
- GoogleR::Token
- Defined in:
- lib/google_r/token.rb
Instance Attribute Summary collapse
-
#access_type ⇒ Object
Returns the value of attribute access_type.
-
#audience ⇒ Object
Returns the value of attribute audience.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#issued_to ⇒ Object
Returns the value of attribute issued_to.
-
#scopes ⇒ Object
Returns the value of attribute scopes.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #expires_in ⇒ Object
-
#initialize(token) ⇒ Token
constructor
A new instance of Token.
- #new? ⇒ Boolean
- #path ⇒ Object
- #to_google(yajl_opts = {}) ⇒ Object
Constructor Details
#initialize(token) ⇒ Token
Returns a new instance of Token.
6 7 8 9 |
# File 'lib/google_r/token.rb', line 6 def initialize(token) self.token = token self.scopes = [] end |
Instance Attribute Details
#access_type ⇒ Object
Returns the value of attribute access_type.
4 5 6 |
# File 'lib/google_r/token.rb', line 4 def access_type @access_type end |
#audience ⇒ Object
Returns the value of attribute audience.
4 5 6 |
# File 'lib/google_r/token.rb', line 4 def audience @audience end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
4 5 6 |
# File 'lib/google_r/token.rb', line 4 def expires_at @expires_at end |
#issued_to ⇒ Object
Returns the value of attribute issued_to.
4 5 6 |
# File 'lib/google_r/token.rb', line 4 def issued_to @issued_to end |
#scopes ⇒ Object
Returns the value of attribute scopes.
4 5 6 |
# File 'lib/google_r/token.rb', line 4 def scopes @scopes end |
#token ⇒ Object
Returns the value of attribute token.
4 5 6 |
# File 'lib/google_r/token.rb', line 4 def token @token end |
Class Method Details
.api_headers ⇒ Object
15 16 17 |
# File 'lib/google_r/token.rb', line 15 def self.api_headers {} end |
.from_json(json, *attrs) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/google_r/token.rb', line 23 def self.from_json(json, *attrs) token = self.new(*attrs) token.issued_to = json["issued_to"] token.audience = json["audience"] token.scopes = json["scope"].split(" ") token.expires_at = Time.at(Time.now.to_i + json["expires_in"]) token.access_type = json["access_type"] token end |
.url ⇒ Object
11 12 13 |
# File 'lib/google_r/token.rb', line 11 def self.url "https://www.googleapis.com" end |
Instance Method Details
#expires_in ⇒ Object
33 34 35 |
# File 'lib/google_r/token.rb', line 33 def expires_in expires_at.to_i - Time.now.to_i end |
#new? ⇒ Boolean
41 42 43 |
# File 'lib/google_r/token.rb', line 41 def new? self.token.nil? end |
#path ⇒ Object
19 20 21 |
# File 'lib/google_r/token.rb', line 19 def path "/oauth2/v2/tokeninfo" end |
#to_google(yajl_opts = {}) ⇒ Object
37 38 39 |
# File 'lib/google_r/token.rb', line 37 def to_google(yajl_opts = {}) Yajl::Encoder.encode({}, yajl_opts) end |