Class: FontsDotCom::AuthParam

Inherits:
Object
  • Object
show all
Defined in:
lib/fonts_dot_com/auth_param.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ AuthParam

Returns a new instance of AuthParam.



16
17
18
19
20
21
# File 'lib/fonts_dot_com/auth_param.rb', line 16

def initialize(message)
  @message = message
  @digest = OpenSSL::Digest.new('md5')
  @hasher = OpenSSL::HMAC.new(priv_key, @digest)
  @concatenation = "#{pub_key}|#{message}"
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



14
15
16
# File 'lib/fonts_dot_com/auth_param.rb', line 14

def auth
  @auth
end

#concatenationObject

Returns the value of attribute concatenation.



14
15
16
# File 'lib/fonts_dot_com/auth_param.rb', line 14

def concatenation
  @concatenation
end

#digestObject

Returns the value of attribute digest.



14
15
16
# File 'lib/fonts_dot_com/auth_param.rb', line 14

def digest
  @digest
end

#hashObject

Returns the value of attribute hash.



14
15
16
# File 'lib/fonts_dot_com/auth_param.rb', line 14

def hash
  @hash
end

#hash64Object

Returns the value of attribute hash64.



14
15
16
# File 'lib/fonts_dot_com/auth_param.rb', line 14

def hash64
  @hash64
end

#hasherObject

Returns the value of attribute hasher.



14
15
16
# File 'lib/fonts_dot_com/auth_param.rb', line 14

def hasher
  @hasher
end

#messageObject

Returns the value of attribute message.



14
15
16
# File 'lib/fonts_dot_com/auth_param.rb', line 14

def message
  @message
end

#paramObject

Returns the value of attribute param.



14
15
16
# File 'lib/fonts_dot_com/auth_param.rb', line 14

def param
  @param
end

Class Method Details

.create(message) ⇒ Object



10
11
12
# File 'lib/fonts_dot_com/auth_param.rb', line 10

def self.create(message)
  self.new(message).compute
end

Instance Method Details

#computeObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fonts_dot_com/auth_param.rb', line 23

def compute
  hasher.update(concatenation)
  @hash = hasher.to_s
  
  # Convert hash from hex to base 64
  @hash64 = [[@hash].pack("H*")].pack("m0")
  @auth   = "#{pub_key}:#{@hash64}"
  @param  = URI.encode(@auth)
  
  return @param
end

#priv_keyObject



39
40
41
# File 'lib/fonts_dot_com/auth_param.rb', line 39

def priv_key
  priv_key = FontsDotCom::Config.private_key
end

#pub_keyObject



35
36
37
# File 'lib/fonts_dot_com/auth_param.rb', line 35

def pub_key
  pub_key = FontsDotCom::Config.public_key
end