Module: GVIVE::Encoding

Included in:
Utils
Defined in:
lib/gvive/encoding.rb

Instance Method Summary collapse

Instance Method Details

#auth_token(username, hmac_digest) ⇒ Base64

Base64 encoding of USERNAME:HMAC-DIGEST

Parameters:

  • username (String)
  • hmac_digest (String)

Returns:

  • (Base64)


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

Parameters:

  • api_key (String)
  • request_concat (String)

Returns:

  • (Base64)


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

Parameters:

  • url (String)
  • params (Hash) (defaults to: {})
  • method (String) (defaults to: "GET")


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