Class: SparkApi::Authentication::OAuthSession
- Inherits:
-
Object
- Object
- SparkApi::Authentication::OAuthSession
- Defined in:
- lib/spark_api/authentication/oauth2.rb
Overview
Representation of a session with the api using oauth2
Constant Summary collapse
- SESSION_ATTRIBUTES =
[:access_token, :expires_in, :scope, :refresh_token, :refresh_timeout, :start_time]
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Is the user session token expired?.
-
#initialize(o = {}) ⇒ OAuthSession
constructor
A new instance of OAuthSession.
- #to_hash ⇒ Object
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(o = {}) ⇒ OAuthSession
Returns a new instance of OAuthSession.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/spark_api/authentication/oauth2.rb', line 157 def initialize(o={}) = OptionsHash.new(o) @access_token = ["access_token"] @expires_in = ["expires_in"] @scope = ["scope"] @refresh_token = ["refresh_token"] @start_time = .fetch("start_time", DateTime.now) @refresh_timeout = .fetch("refresh_timeout", 43200) if @start_time.is_a? String @start_time = DateTime.parse(@start_time) end end |
Instance Method Details
#expired? ⇒ Boolean
Is the user session token expired?
172 173 174 175 |
# File 'lib/spark_api/authentication/oauth2.rb', line 172 def expired? return false if @expires_in.nil? @start_time + Rational(@expires_in - @refresh_timeout, 86400) < DateTime.now end |
#to_hash ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/spark_api/authentication/oauth2.rb', line 181 def to_hash hash = {} SESSION_ATTRIBUTES.each do |k| value = self.send(k) hash[k.to_s] = value unless value.nil? end hash end |
#to_json(*a) ⇒ Object
177 178 179 |
# File 'lib/spark_api/authentication/oauth2.rb', line 177 def to_json(*a) to_hash.to_json(*a) end |