Class: GoogleR::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/google_r/token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_typeObject

Returns the value of attribute access_type.



4
5
6
# File 'lib/google_r/token.rb', line 4

def access_type
  @access_type
end

#audienceObject

Returns the value of attribute audience.



4
5
6
# File 'lib/google_r/token.rb', line 4

def audience
  @audience
end

#expires_atObject

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_toObject

Returns the value of attribute issued_to.



4
5
6
# File 'lib/google_r/token.rb', line 4

def issued_to
  @issued_to
end

#scopesObject

Returns the value of attribute scopes.



4
5
6
# File 'lib/google_r/token.rb', line 4

def scopes
  @scopes
end

#tokenObject

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_headersObject



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

.urlObject



11
12
13
# File 'lib/google_r/token.rb', line 11

def self.url
  "https://www.googleapis.com"
end

Instance Method Details

#expires_inObject



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

Returns:

  • (Boolean)


41
42
43
# File 'lib/google_r/token.rb', line 41

def new?
  self.token.nil?
end

#pathObject



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