Class: Protocol::HTTP::Header::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/http/header/authorization.rb

Overview

Used for basic authorization.

Examples:

headers.add(*Authorization.new(“samuel”, “password”))

Constant Summary collapse

KEY =
"Authorization"

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Authorization

Returns a new instance of Authorization.



33
34
35
36
# File 'lib/protocol/http/header/authorization.rb', line 33

def initialize(username, password)
	@username = username
	@password = password
end

Instance Method Details

#encodedObject



42
43
44
# File 'lib/protocol/http/header/authorization.rb', line 42

def encoded
	"#{@username}:#{@password}"
end

#to_aryObject



38
39
40
# File 'lib/protocol/http/header/authorization.rb', line 38

def to_ary
	return KEY, self.to_str
end

#to_strObject



46
47
48
# File 'lib/protocol/http/header/authorization.rb', line 46

def to_str
	'Basic %s' % Base64.strict_encode64(self.encoded)
end