Class: AdvancedBilling::BasicAuthCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/advanced_billing/http/auth/basic_auth.rb

Overview

Data class for BasicAuthCredentials.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:) ⇒ BasicAuthCredentials

Returns a new instance of BasicAuthCredentials.

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
# File 'lib/advanced_billing/http/auth/basic_auth.rb', line 35

def initialize(username:, password:)
  raise ArgumentError, 'username cannot be nil' if username.nil?
  raise ArgumentError, 'password cannot be nil' if password.nil?

  @username = username
  @password = password
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



33
34
35
# File 'lib/advanced_billing/http/auth/basic_auth.rb', line 33

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



33
34
35
# File 'lib/advanced_billing/http/auth/basic_auth.rb', line 33

def username
  @username
end

Class Method Details

.from_envObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/advanced_billing/http/auth/basic_auth.rb', line 43

def self.from_env
  username = ENV['USERNAME']
  password = ENV['PASSWORD']
  all_nil = [
    username,
    password
  ].all?(&:nil?)
  return nil if all_nil

  new(username: username, password: password)
end

Instance Method Details

#clone_with(username: nil, password: nil) ⇒ Object



55
56
57
58
59
60
# File 'lib/advanced_billing/http/auth/basic_auth.rb', line 55

def clone_with(username: nil, password: nil)
  username ||= self.username
  password ||= self.password

  BasicAuthCredentials.new(username: username, password: password)
end