Class: FontsDotCom::AuthParam
- Inherits:
-
Object
- Object
- FontsDotCom::AuthParam
- Defined in:
- lib/fonts_dot_com/auth_param.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#concatenation ⇒ Object
Returns the value of attribute concatenation.
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#hash64 ⇒ Object
Returns the value of attribute hash64.
-
#hasher ⇒ Object
Returns the value of attribute hasher.
-
#message ⇒ Object
Returns the value of attribute message.
-
#param ⇒ Object
Returns the value of attribute param.
Class Method Summary collapse
-
.create(message) ⇒ Object
Returns properly-encoded md5 HMAC per www.fonts.com/web-fonts/developers/api/authorizationparameter.
Instance Method Summary collapse
- #compute ⇒ Object
-
#initialize(message) ⇒ AuthParam
constructor
A new instance of AuthParam.
- #priv_key ⇒ Object
- #pub_key ⇒ Object
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() = @digest = OpenSSL::Digest.new('md5') @hasher = OpenSSL::HMAC.new(priv_key, @digest) @concatenation = "#{pub_key}|#{message}" end |
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
14 15 16 |
# File 'lib/fonts_dot_com/auth_param.rb', line 14 def auth @auth end |
#concatenation ⇒ Object
Returns the value of attribute concatenation.
14 15 16 |
# File 'lib/fonts_dot_com/auth_param.rb', line 14 def concatenation @concatenation end |
#digest ⇒ Object
Returns the value of attribute digest.
14 15 16 |
# File 'lib/fonts_dot_com/auth_param.rb', line 14 def digest @digest end |
#hash ⇒ Object
Returns the value of attribute hash.
14 15 16 |
# File 'lib/fonts_dot_com/auth_param.rb', line 14 def hash @hash end |
#hash64 ⇒ Object
Returns the value of attribute hash64.
14 15 16 |
# File 'lib/fonts_dot_com/auth_param.rb', line 14 def hash64 @hash64 end |
#hasher ⇒ Object
Returns the value of attribute hasher.
14 15 16 |
# File 'lib/fonts_dot_com/auth_param.rb', line 14 def hasher @hasher end |
#message ⇒ Object
Returns the value of attribute message.
14 15 16 |
# File 'lib/fonts_dot_com/auth_param.rb', line 14 def end |
#param ⇒ Object
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
Returns properly-encoded md5 HMAC per www.fonts.com/web-fonts/developers/api/authorizationparameter
10 11 12 |
# File 'lib/fonts_dot_com/auth_param.rb', line 10 def self.create() self.new().compute end |
Instance Method Details
#compute ⇒ Object
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_key ⇒ Object
39 40 41 |
# File 'lib/fonts_dot_com/auth_param.rb', line 39 def priv_key priv_key = FontsDotCom::Config.private_key end |
#pub_key ⇒ Object
35 36 37 |
# File 'lib/fonts_dot_com/auth_param.rb', line 35 def pub_key pub_key = FontsDotCom::Config.public_key end |