Module: OnlyofficeDigitaloceanWrapper::TokenMethods

Included in:
DigitalOceanWrapper
Defined in:
lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/token_methods.rb

Overview

Methods to login in account

Instance Method Summary collapse

Instance Method Details

#correct_access_token?true, false

Check if access token is correct

Returns:

  • (true, false)

    result of check



8
9
10
11
12
13
14
15
# File 'lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/token_methods.rb', line 8

def correct_access_token?
  begin
    @client.droplets.all.first
  rescue DropletKit::Error
    return false
  end
  true
end

#read_token(token_file_path: "#{Dir.home}/.do/access_token", force_file_read: false) ⇒ String

Read access token from file system

Parameters:

  • token_file_path (String) (defaults to: "#{Dir.home}/.do/access_token")

    path to token

  • force_file_read (True, False) (defaults to: false)

    should read from file be forced

Returns:

  • (String)

    token



21
22
23
24
25
26
27
28
29
# File 'lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/token_methods.rb', line 21

def read_token(token_file_path: "#{Dir.home}/.do/access_token",
               force_file_read: false)
  return ENV['DO_ACCESS_TOKEN'] if ENV['DO_ACCESS_TOKEN'] && !force_file_read

  File.read(token_file_path).delete("\n")
rescue Errno::ENOENT
  raise Errno::ENOENT, "No access token found in #{token_file_path}. " \
                       "Please create file #{token_file_path} with token"
end