Class: ScaleEngineAPI::Request
- Inherits:
-
Object
- Object
- ScaleEngineAPI::Request
- Defined in:
- lib/scaleengine/request.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(path = "", query = {}) ⇒ Request
constructor
A new instance of Request.
- #method_missing(method, *args) ⇒ Object
- #prepare_request ⇒ Object
- #request_signature ⇒ Object
- #send ⇒ Object
Constructor Details
#initialize(path = "", query = {}) ⇒ Request
Returns a new instance of Request.
8 9 10 11 |
# File 'lib/scaleengine/request.rb', line 8 def initialize(path = "", query = {}) @path = path @query = query end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/scaleengine/request.rb', line 19 def method_missing(method, *args) query_new = query query_new[:command] += ".#{method}" params = args[0].is_a?(Hash) ? args[0] : {} params.delete(:command) params.keys.each do |x| query_new[x] = params[x] end Request.new(path, query_new) end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/scaleengine/request.rb', line 6 def path @path end |
#query ⇒ Object
Returns the value of attribute query.
6 7 8 |
# File 'lib/scaleengine/request.rb', line 6 def query @query end |
Instance Method Details
#prepare_request ⇒ Object
32 33 34 35 36 |
# File 'lib/scaleengine/request.rb', line 32 def prepare_request query[:timestamp] = Time.now.to_i query[:signature] = Base64.strict_encode64(request_signature) body = {:json => JSON.generate(query), :multipart => true} end |
#request_signature ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/scaleengine/request.rb', line 38 def request_signature params = query json_params = JSON.generate(params) # Compute new SHA256 HMAC digest = OpenSSL::Digest::SHA256.new OpenSSL::HMAC.digest(digest, Configuration.secret_key, json_params) end |