class Fnsapi::TmpStorage
Public Class Methods
new()
click to toggle source
# File lib/fnsapi/tmp_storage.rb, line 5 def initialize @file = File.open(file_path, 'a+') end
Public Instance Methods
token()
click to toggle source
# File lib/fnsapi/tmp_storage.rb, line 15 def token data = JSON.parse(@file.read) expired_at = Time.parse(data['expire_at']) if expired_at < Time.now @file.truncate(0) return end data['token'] rescue JSON::ParserError @file.truncate(0) nil end
write_token(token, expire_at)
click to toggle source
# File lib/fnsapi/tmp_storage.rb, line 9 def write_token(token, expire_at) @file.truncate(0) @file.write({ token: token, expire_at: expire_at }.to_json) @file.rewind end
Private Instance Methods
file_path()
click to toggle source
# File lib/fnsapi/tmp_storage.rb, line 32 def file_path if defined?(Rails) Rails.root.join('tmp', Fnsapi.configuration.tmp_file_name) else 'tmp/' + Fnsapi.configuration.tmp_file_name end end