Module: GVIVE::Encoding
- Included in:
- Utils
- Defined in:
- lib/gvive/encoding.rb
Instance Method Summary collapse
-
#auth_token(username, hmac_digest) ⇒ Base64
Base64 encoding of USERNAME:HMAC-DIGEST.
-
#hmac_digest(api_key, request_concat) ⇒ Base64
GVIVE docs states the digest signature as DIGEST = HMAC-SHA256(REQCONCAT, API KEY) The digest result should also be encodeded in Base64 format.
-
#request_concat(url, params = {}, method = "GET") ⇒ Object
From the GVIVE docs this is REQUEST METHOD + ENCODED URL eg.
Instance Method Details
#auth_token(username, hmac_digest) ⇒ Base64
Base64 encoding of USERNAME:HMAC-DIGEST
35 36 37 |
# File 'lib/gvive/encoding.rb', line 35 def auth_token(username, hmac_digest) Base64.strict_encode64("#{username}:#{hmac_digest}") end |
#hmac_digest(api_key, request_concat) ⇒ Base64
GVIVE docs states the digest signature as DIGEST = HMAC-SHA256(REQCONCAT, API KEY) The digest result should also be encodeded in Base64 format
27 28 29 |
# File 'lib/gvive/encoding.rb', line 27 def hmac_digest(api_key, request_concat) Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', api_key, request_concat)) end |
#request_concat(url, params = {}, method = "GET") ⇒ Object
From the GVIVE docs this is REQUEST METHOD + ENCODED URL eg. gvivegh.com:1355/gvivewar/Voter?Vid=123456 becomes https%3A%2F%2Fgvivegh.com%3A1355%2Fgvivewar%2FVoter%3FVid%3D123456 The url encoding must be converted to lowercase
17 18 19 20 |
# File 'lib/gvive/encoding.rb', line 17 def request_concat(url, params={}, method="GET") url_build = CGI.escape("#{url}?#{URI.encode_www_form(params)}").downcase "#{method.upcase}#{url_build}" end |