Class: Hapyrus::Credentials

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/hapyrus/credentials.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

home_directory, parse_command, to_command_class

Constructor Details

#initialize(user = nil, password = nil) ⇒ Credentials

Returns a new instance of Credentials.



5
6
7
8
# File 'lib/hapyrus/credentials.rb', line 5

def initialize(user=nil, password=nil)
  @user = user || ENV['HAPYRUS_LOGIN']
  @password = password || ENV['HAPYRUS_PASSWORD']
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



4
5
6
# File 'lib/hapyrus/credentials.rb', line 4

def password
  @password
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/hapyrus/credentials.rb', line 4

def user
  @user
end

Instance Method Details

#authenticate!Object



9
10
11
12
# File 'lib/hapyrus/credentials.rb', line 9

def authenticate!
  @authenticated = true
  write_credentials
end

#authenticated?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/hapyrus/credentials.rb', line 13

def authenticated?
  @authenticated
end

#write_credentialsObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/hapyrus/credentials.rb', line 16

def write_credentials
  dir = File.dirname(credentials_file)
  FileUtils.mkdir_p(dir)
  File.delete(credentials_file) if FileTest.exists?(credentials_file)
  File.open(credentials_file, 'w', 0400) do |out|
    out.puts @user
    out.puts @password
  end
  FileUtils.chmod(0700, dir)
end