Class: FlexmlsApi::Authentication::OAuthSession
- Inherits:
-
Object
- Object
- FlexmlsApi::Authentication::OAuthSession
- Defined in:
- lib/flexmls_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(options = {}) ⇒ OAuthSession
constructor
A new instance of OAuthSession.
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ OAuthSession
Returns a new instance of OAuthSession.
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/flexmls_api/authentication/oauth2.rb', line 92 def initialize(={}) @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",3600) 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?
104 105 106 |
# File 'lib/flexmls_api/authentication/oauth2.rb', line 104 def expired? @start_time + Rational(@expires_in - @refresh_timeout, 86400) < DateTime.now end |
#to_json(*a) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/flexmls_api/authentication/oauth2.rb', line 108 def to_json(*a) hash = {} SESSION_ATTRIBUTES.each do |k| value = self.send(k) hash[k.to_s] = value unless value.nil? end hash.to_json(*a) end |