Class: OnlyofficeGmailHelper::EmailAccount

Inherits:
Object
  • Object
show all
Defined in:
lib/onlyoffice_gmail_helper/email_account.rb

Overview

Class for storing default mail accounts

Class Method Summary collapse

Class Method Details

.default_accountMailAccount

Returns default account for GMail.

Returns:



30
31
32
# File 'lib/onlyoffice_gmail_helper/email_account.rb', line 30

def self.
  @default_account ||= MailAccount.new(read_defaults[:user], read_defaults[:password])
end

.read_defaultsHash

Read default values for account

Returns:

  • (Hash)

    result



10
11
12
13
14
15
16
17
# File 'lib/onlyoffice_gmail_helper/email_account.rb', line 10

def self.read_defaults
  return read_env_defaults if read_env_defaults

  yaml = YAML.load_file("#{Dir.home}/.gem-onlyoffice_gmail_helper/config.yml")
  { user: yaml['user'], password: yaml['password'] }
rescue Errno::ENOENT
  raise Errno::ENOENT, 'No config found. Please create ~/.gem-onlyoffice_gmail_helper/config.yml'
end

.read_env_defaultsHash

Read keys from env variables

Returns:

  • (Hash)


21
22
23
24
25
26
27
# File 'lib/onlyoffice_gmail_helper/email_account.rb', line 21

def self.read_env_defaults
  return false unless ENV.key?('GMAIL_USER') && ENV.key?('GMAIL_PASSWORD')

  # rubocop:disable Style/FetchEnvVar
  { user: ENV['GMAIL_USER'], password: ENV['GMAIL_PASSWORD'] }
  # rubocop:enable Style/FetchEnvVar
end