Class: TRMNLP::OAuth::TokenStore
- Inherits:
-
Object
- Object
- TRMNLP::OAuth::TokenStore
- Defined in:
- lib/trmnlp/oauth/token_store.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(path) ⇒ TokenStore
constructor
A new instance of TokenStore.
- #read ⇒ Object
- #write(bundle) ⇒ Object
Constructor Details
#initialize(path) ⇒ TokenStore
Returns a new instance of TokenStore.
8 9 10 |
# File 'lib/trmnlp/oauth/token_store.rb', line 8 def initialize(path) @path = path end |
Instance Method Details
#clear ⇒ Object
25 26 27 |
# File 'lib/trmnlp/oauth/token_store.rb', line 25 def clear path.delete if path.exist? end |
#read ⇒ Object
12 13 14 15 16 |
# File 'lib/trmnlp/oauth/token_store.rb', line 12 def read return nil unless path.exist? TokenBundle.from_h(JSON.parse(path.read)) end |
#write(bundle) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/trmnlp/oauth/token_store.rb', line 18 def write(bundle) path.dirname.mkpath path.write(JSON.generate(bundle.to_h)) path.chmod(0o600) bundle end |