Class: Fog::Backblaze::TokenCache::FileTokenCache

Inherits:
Fog::Backblaze::TokenCache show all
Defined in:
lib/fog/backblaze/token_cache.rb

Overview

stored in local file

Constant Summary

Constants inherited from Fog::Backblaze::TokenCache

TTLS

Instance Method Summary collapse

Methods inherited from Fog::Backblaze::TokenCache

#access_part, #auth_response, #auth_response=, #buckets, #buckets=, #fetch, #reset, #upload_url, #write_part

Constructor Details

#initialize(file) ⇒ FileTokenCache

Returns a new instance of FileTokenCache.


106
107
108
109
# File 'lib/fog/backblaze/token_cache.rb', line 106

def initialize(file)
  @file = file
  super()
end

Instance Method Details

#load_dataObject


111
112
113
114
115
116
117
# File 'lib/fog/backblaze/token_cache.rb', line 111

def load_data
  if File.exist?(@file)
    ::JSON.parse(File.open(@file, 'rb', &:read))
  else
    {}
  end
end

#save_dataObject


119
120
121
122
123
# File 'lib/fog/backblaze/token_cache.rb', line 119

def save_data
  File.open(@file, 'wb') do |f|
    f.write(::JSON.pretty_generate(@data) + "\n")
  end
end