Class: BasicAuth
- Inherits:
-
Object
- Object
- BasicAuth
- Defined in:
- lib/parsers/http/basicauth.rb
Defined Under Namespace
Classes: ParserError
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user, pass) ⇒ BasicAuth
constructor
A new instance of BasicAuth.
- #to_s ⇒ Object
- #userpwd ⇒ Object
Constructor Details
#initialize(user, pass) ⇒ BasicAuth
Returns a new instance of BasicAuth.
6 7 8 9 |
# File 'lib/parsers/http/basicauth.rb', line 6 def initialize(user, pass) @username = user @password = pass end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/parsers/http/basicauth.rb', line 5 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/parsers/http/basicauth.rb', line 5 def username @username end |
Class Method Details
.parse(raw_value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/parsers/http/basicauth.rb', line 19 def self.parse(raw_value) decoded = raw_value.unpack("m").first si = decoded.index ':' raise ParserError.new 'Malformed string, expecting ":"' if si.nil? username = decoded[0...si] password = decoded[si + 1..-1] raise ParserError.new 'Username cannot be blank' if username.empty? self.new username, password end |
Instance Method Details
#to_s ⇒ Object
15 16 17 |
# File 'lib/parsers/http/basicauth.rb', line 15 def to_s [self.userpwd].pack('m').strip end |
#userpwd ⇒ Object
11 12 13 |
# File 'lib/parsers/http/basicauth.rb', line 11 def userpwd "#{@username}:#{@password}" end |