Class: ChemistryKit::Config::BasicAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/chemistrykit/config/basic_auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ BasicAuth

Returns a new instance of BasicAuth.



9
10
11
12
13
14
15
16
17
# File 'lib/chemistrykit/config/basic_auth.rb', line 9

def initialize(opts)
  opts.each do |key, value|
    begin
      send("#{key}=", value)
    rescue NoMethodError
      raise ArgumentError.new "The config key: \"#{key}\" is unknown!"
    end
  end
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



7
8
9
# File 'lib/chemistrykit/config/basic_auth.rb', line 7

def base_url
  @base_url
end

#http_pathObject

Returns the value of attribute http_path.



7
8
9
# File 'lib/chemistrykit/config/basic_auth.rb', line 7

def http_path
  @http_path
end

#https_pathObject

Returns the value of attribute https_path.



7
8
9
# File 'lib/chemistrykit/config/basic_auth.rb', line 7

def https_path
  @https_path
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/chemistrykit/config/basic_auth.rb', line 7

def password
  @password
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/chemistrykit/config/basic_auth.rb', line 7

def username
  @username
end

Instance Method Details

#http?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/chemistrykit/config/basic_auth.rb', line 19

def http?
  !!http_path
end

#http_urlObject



27
28
29
# File 'lib/chemistrykit/config/basic_auth.rb', line 27

def http_url
  base_url.gsub(%r{http://}, "http:\/\/#{username}:#{password}@") + (http_path || '')
end

#https?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/chemistrykit/config/basic_auth.rb', line 23

def https?
  !!https_path
end

#https_urlObject



31
32
33
# File 'lib/chemistrykit/config/basic_auth.rb', line 31

def https_url
  base_url.gsub(%r{http://}, "https:\/\/#{username}:#{password}@") + (https_path || '')
end