Created
February 18, 2014 17:07
-
-
Save buccolo/9075142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
require 'json' | |
require 'openssl' | |
HUB_URL = "http://localhost:4000/push" | |
STORE_ID = "5180e2507575e48dd0000001" | |
STORE_SECRET_KEY = "1234567890" | |
timestamp = Time.now.utc().to_i - 4600 | |
json_payload = JSON.generate({ | |
orders: [ { id: 'R1234', status: 'cancelled' } ] | |
}) | |
data = "#{json_payload}#{timestamp}" | |
SHA1 = OpenSSL::Digest::Digest.new('sha1') | |
access_token = OpenSSL::HMAC.hexdigest(SHA1, STORE_SECRET_KEY, data) | |
response = HTTParty.post(HUB_URL, { | |
body: json_payload, | |
headers: { | |
'X-Hub-Store' => STORE_ID, | |
'X-Hub-Access-Token1' => access_token, | |
'X-Hub-Timestamp' => timestamp.to_s | |
} | |
}) | |
puts response.code # 202 | |
puts response.body # {"orders":1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment