Class: Shmac::AuthorizationHeader

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/shmac/authorization_header.rb

Defined Under Namespace

Classes: FormatError

Constant Summary collapse

AUTH_HEADER_PATTERN =
/(.+) (.+):(.+)$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ AuthorizationHeader



16
17
18
19
# File 'lib/shmac/authorization_header.rb', line 16

def initialize value
  @value = value
  self.parts = value
end

Instance Attribute Details

#partsObject

Returns the value of attribute parts.



10
11
12
# File 'lib/shmac/authorization_header.rb', line 10

def parts
  @parts
end

Class Method Details

.generate(organization:, access_key:, signature:) ⇒ Object



12
13
14
# File 'lib/shmac/authorization_header.rb', line 12

def self.generate organization:, access_key:, signature:
  new("%s %s:%s" % [organization, access_key, signature])
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
25
# File 'lib/shmac/authorization_header.rb', line 21

def == other
  return false unless other.is_a?(self.class)

  Security.secure_compare self.to_s, other.to_s
end

#access_key_idObject



44
45
46
# File 'lib/shmac/authorization_header.rb', line 44

def access_key_id
  parts[2]
end

#organizationObject



40
41
42
# File 'lib/shmac/authorization_header.rb', line 40

def organization
  parts[1]
end

#signatureObject



48
49
50
# File 'lib/shmac/authorization_header.rb', line 48

def signature
  parts[3]
end

#to_sObject



27
28
29
# File 'lib/shmac/authorization_header.rb', line 27

def to_s
  @value
end