Class: Bluekai::Request
- Inherits:
-
Object
- Object
- Bluekai::Request
- Defined in:
- lib/bluekai/request.rb
Instance Attribute Summary collapse
-
#api_private_key ⇒ Object
Returns the value of attribute api_private_key.
-
#api_user_key ⇒ Object
Returns the value of attribute api_user_key.
Instance Method Summary collapse
-
#initialize(method, path, query, body, domain) ⇒ Request
constructor
A new instance of Request.
- #run ⇒ Object
-
#signature ⇒ Object
HMAC-SHA256(Secret key, HTTP_METHOD + URI_PATH + QUERY_ARG_VALUES + POST_DATA).
Constructor Details
#initialize(method, path, query, body, domain) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 |
# File 'lib/bluekai/request.rb', line 8 def initialize(method, path, query, body, domain) @method = method.upcase @path = path @query = query @body = body @domain = domain end |
Instance Attribute Details
#api_private_key ⇒ Object
Returns the value of attribute api_private_key.
6 7 8 |
# File 'lib/bluekai/request.rb', line 6 def api_private_key @api_private_key end |
#api_user_key ⇒ Object
Returns the value of attribute api_user_key.
6 7 8 |
# File 'lib/bluekai/request.rb', line 6 def api_user_key @api_user_key end |
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 |
# File 'lib/bluekai/request.rb', line 16 def run response = http_request fail Bluekai::RequestFailed, response.body unless response.code.start_with?('2') return :success if response.body.nil? || response.body.strip.empty? JSON.parse(response.body, symbolize_names: true) end |
#signature ⇒ Object
HMAC-SHA256(Secret key, HTTP_METHOD + URI_PATH + QUERY_ARG_VALUES + POST_DATA)
24 25 26 27 28 |
# File 'lib/bluekai/request.rb', line 24 def signature digest = OpenSSL::Digest.new('sha256') hmac = OpenSSL::HMAC.digest(digest, api_private_key, string_to_sign) CGI.escape(Base64.strict_encode64(hmac)) end |