Module: Emailage::Signature
- Defined in:
- lib/emailage/signature.rb
Class Method Summary collapse
-
.concatenate_request_elements(method, url, query) ⇒ Object
9.1.3.
-
.create(method, url, params, hmac_key) ⇒ String
oauth.net/core/1.0/#signing_process Using HTTP GET parameters option.
-
.hmac_sha1(base_string, hmac_key) ⇒ Object
9.2.
-
.normalize_query_parameters(params) ⇒ Object
9.1.1.
Class Method Details
.concatenate_request_elements(method, url, query) ⇒ Object
9.1.3. Concatenate Request Elements
16 17 18 |
# File 'lib/emailage/signature.rb', line 16 def concatenate_request_elements(method, url, query) [method.to_s.upcase, url, query].map {|e| CGI.escape(e)}.join '&' end |
.create(method, url, params, hmac_key) ⇒ String
oauth.net/core/1.0/#signing_process Using HTTP GET parameters option.
35 36 37 38 39 40 41 |
# File 'lib/emailage/signature.rb', line 35 def create(method, url, params, hmac_key) query = normalize_query_parameters(params) base_string = concatenate_request_elements(method, url, query) digest = hmac_sha1(base_string, hmac_key) # 9.2.1. Generating Signature Base64.strict_encode64 digest end |
.hmac_sha1(base_string, hmac_key) ⇒ Object
9.2. HMAC-SHA1
21 22 23 |
# File 'lib/emailage/signature.rb', line 21 def hmac_sha1(base_string, hmac_key) OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), hmac_key, base_string) end |
.normalize_query_parameters(params) ⇒ Object
9.1.1. Normalize Request Parameters
11 12 13 |
# File 'lib/emailage/signature.rb', line 11 def normalize_query_parameters(params) params.sort.map {|k,v| [CGI.escape(k.to_s), ERB::Util.url_encode(v.to_s)].join '='}.join '&' end |