Class: BingAdsRubySdk::OAuth2::FsStore

Inherits:
Object
  • Object
show all
Defined in:
lib/bing_ads_ruby_sdk/oauth2/fs_store.rb

Overview

Oauth2 token default non-encrypted File System store

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FsStore

Returns a new instance of FsStore.

Parameters:

  • filename (String)

    the uniq filename to identify filename storing data.



8
9
10
# File 'lib/bing_ads_ruby_sdk/oauth2/fs_store.rb', line 8

def initialize(filename)
  @filename = filename
end

Instance Method Details

#readHash?

Reads the token from file

Returns:

  • (Hash)

    if the token information that was stored.

  • (nil)

    if the file doesn’t exist.



24
25
26
27
# File 'lib/bing_ads_ruby_sdk/oauth2/fs_store.rb', line 24

def read
  return nil unless File.file?("./#{filename}")
  JSON.parse(File.read(filename))
end

#write(value) ⇒ File, self

Writes the token to file

Returns:

  • (File)

    if the file was written (doesn’t mean the token is).

  • (self)

    if the filename don’t exist.



15
16
17
18
19
# File 'lib/bing_ads_ruby_sdk/oauth2/fs_store.rb', line 15

def write(value)
  return nil unless filename
  File.open(filename, "w") { |f| JSON.dump(value, f) }
  self
end