Class: App42::Client::RestUtil
- Inherits:
-
Object
- Object
- App42::Client::RestUtil
- Defined in:
- lib/app42/client/rest_util.rb
Instance Method Summary collapse
-
#compute_hmac(secret_key, sorted_params) ⇒ Object
Encoding and decoding of the queries are done using the Hmac Algorithm.
-
#get_timestamp_utc ⇒ Object
Finds the current time.
-
#sign(secret_key, params) ⇒ Object
It signs the request that has to be sent in the Hmac format.
-
#sort_convert_table(table) ⇒ Object
This method sorts all the values that are stored in the table.
Instance Method Details
#compute_hmac(secret_key, sorted_params) ⇒ Object
Encoding and decoding of the queries are done using the Hmac Algorithm.
58 59 60 61 62 |
# File 'lib/app42/client/rest_util.rb', line 58 def compute_hmac(secret_key, sorted_params) signature = Base64.encode64(HMAC::SHA1::digest(secret_key, sorted_params)).strip computed_hmac = CGI.escape(signature) computed_hmac end |
#get_timestamp_utc ⇒ Object
Finds the current time
15 16 17 18 |
# File 'lib/app42/client/rest_util.rb', line 15 def = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") return .freeze end |
#sign(secret_key, params) ⇒ Object
It signs the request that has to be sent in the Hmac format.
28 29 30 31 32 |
# File 'lib/app42/client/rest_util.rb', line 28 def sign secret_key, params sorted_params = sort_convert_table(params) signature = compute_hmac(secret_key, sorted_params) signature end |
#sort_convert_table(table) ⇒ Object
This method sorts all the values that are stored in the table.
41 42 43 44 45 46 47 48 |
# File 'lib/app42/client/rest_util.rb', line 41 def sort_convert_table(table) sorted_params = "" table.sort {|a,b| a[0] <=> b[0]}.each{ |key, val| sorted_params << key sorted_params << val } sorted_params end |