Class: Geotrigger::AGO::Session::Device
- Inherits:
-
Object
- Object
- Geotrigger::AGO::Session::Device
- Extended by:
- Forwardable
- Includes:
- AccessToken, ExpirySet
- Defined in:
- lib/geotrigger/ago/session.rb
Overview
AGO::Session implementation for Devices
Constant Summary
Constants included from ExpirySet
ExpirySet::TOKEN_EXPIRY_BUFFER
Instance Attribute Summary collapse
-
#ago_data ⇒ Object
readonly
Returns the value of attribute ago_data.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
Instance Method Summary collapse
-
#access_token ⇒ Object
Returns a valid
access_token. -
#device_data ⇒ Object
Fetches data from AGO about the device specified by this :access_token+.
-
#initialize(session, opts = {}) ⇒ Device
constructor
Accepts the abstract
AGO::Sessionand a Hash with:client_idand:refresh_tokenkeys.
Methods included from AccessToken
Methods included from ExpirySet
Constructor Details
#initialize(session, opts = {}) ⇒ Device
Accepts the abstract AGO::Session and a Hash with :client_id and :refresh_token keys.
171 172 173 174 |
# File 'lib/geotrigger/ago/session.rb', line 171 def initialize session, opts = {} @session, @client_id, @refresh_token = session, opts[:client_id], opts[:refresh_token] end |
Instance Attribute Details
#ago_data ⇒ Object (readonly)
Returns the value of attribute ago_data.
166 167 168 |
# File 'lib/geotrigger/ago/session.rb', line 166 def ago_data @ago_data end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
165 166 167 |
# File 'lib/geotrigger/ago/session.rb', line 165 def refresh_token @refresh_token end |
Instance Method Details
#access_token ⇒ Object
Returns a valid access_token. Registers a new Device with AGO if needed.
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/geotrigger/ago/session.rb', line 179 def access_token if @ago_data.nil? if @refresh_token.nil? register else refresh_access_token end elsif not @ago_data[:expires_at].nil? and Time.now >= @ago_data[:expires_at] refresh_access_token end @ago_data['access_token'] end |
#device_data ⇒ Object
Fetches data from AGO about the device specified by this :access_token+.
194 195 196 |
# File 'lib/geotrigger/ago/session.rb', line 194 def device_data @device_data ||= hc(:get, 'portals/self', token: access_token)['deviceInfo'] end |