Class: Pathfinder::StateManager
- Inherits:
-
Object
- Object
- Pathfinder::StateManager
- Defined in:
- lib/pathfinder_dnd/state_manager.rb
Overview
Sets up the OAuth connection to Google Drive and manages user settings such as the Google Drive key/id of the character sheet document.
Instance Attribute Summary collapse
-
#auth ⇒ Object
for ease of use.
-
#doc_id ⇒ Object
Returns the value of attribute doc_id.
-
#session ⇒ Object
for ease of use.
-
#token ⇒ Object
for ease of use.
Instance Method Summary collapse
-
#authorize ⇒ Object
Round-trip the user through Google’s OAuth process.
-
#get_character_sheet ⇒ Object
Perform all necessary input to get a character sheet from a user’s Google Drive.
-
#initialize(storage = Pathfinder::STORAGE) ⇒ StateManager
constructor
create a StateManager with a optional storage backend.
Constructor Details
#initialize(storage = Pathfinder::STORAGE) ⇒ StateManager
create a StateManager with a optional storage backend. Loads data including OAuth tokens and the document identifier from the PStore By default all StateMangers read/write to the Pathfinder settings PStore in ~/.config/pathfinder.pstore
27 28 29 30 31 32 33 34 35 |
# File 'lib/pathfinder_dnd/state_manager.rb', line 27 def initialize(storage = Pathfinder::STORAGE) @storage = storage @auth = Pathfinder::OAuth.new(@storage) @token = @auth.load_token @storage.transaction do @doc_id = @storage[:doc] end end |
Instance Attribute Details
#auth ⇒ Object
for ease of use
20 21 22 |
# File 'lib/pathfinder_dnd/state_manager.rb', line 20 def auth @auth end |
#doc_id ⇒ Object
Returns the value of attribute doc_id.
21 22 23 |
# File 'lib/pathfinder_dnd/state_manager.rb', line 21 def doc_id @doc_id end |
#session ⇒ Object
for ease of use
20 21 22 |
# File 'lib/pathfinder_dnd/state_manager.rb', line 20 def session @session end |
#token ⇒ Object
for ease of use
20 21 22 |
# File 'lib/pathfinder_dnd/state_manager.rb', line 20 def token @token end |
Instance Method Details
#authorize ⇒ Object
Round-trip the user through Google’s OAuth process
38 39 40 41 42 |
# File 'lib/pathfinder_dnd/state_manager.rb', line 38 def @auth. @auth.save_token @token = @auth.access_token end |
#get_character_sheet ⇒ Object
Perform all necessary input to get a character sheet from a user’s Google Drive.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pathfinder_dnd/state_manager.rb', line 52 def get_character_sheet if @token.nil? self.() end if @doc_id.nil? puts "\n\nPaste the `key=` parameter from your character's Google Drive URL here:" self.doc_id = gets.chomp end @session = GoogleDrive.login_with_oauth(@token) return Pathfinder::CharacterSheet.new(@session, @doc_id) end |