Class: TRMNLP::OAuth::TokenStore

Inherits:
Object
  • Object
show all
Defined in:
lib/trmnlp/oauth/token_store.rb

Instance Method Summary collapse

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

#clearObject



25
26
27
# File 'lib/trmnlp/oauth/token_store.rb', line 25

def clear
  path.delete if path.exist?
end

#readObject



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