Created
January 10, 2013 10:31
-
-
Save oriolgual/4501083 to your computer and use it in GitHub Desktop.
Testing Pusher Webhooks with rspec_api_documentation
This file contains hidden or 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 'spec_helper' | |
require 'rspec_api_documentation/dsl' | |
resource "Pusher Webhooks" do | |
let(:user) { Fabricate(:user) } | |
let(:channel) { YOUR_CHANNEL_NAME } | |
post '/api/pusher_webhook' do | |
let(:pusher_key) { YOUR_PUSHER_KEY } | |
let(:pusher_secret) { YOUR_PUSHER_SECRET } | |
let(:raw_post) do | |
{ | |
'time_ms' => Time.now.to_i, | |
'events' => [ | |
'name' => 'member_added', | |
'channel' => channel, | |
'user_id' => user.id | |
] | |
}.to_json | |
end | |
let(:pusher_signature) do | |
digest = OpenSSL::Digest::SHA256.new | |
OpenSSL::HMAC.hexdigest(digest, pusher_secret, raw_post) | |
end | |
parameter :name, 'The name of the event that triggered the webhook' | |
parameter :channel, 'The name of the channel where the event happened' | |
parameter :user_id, 'The id of the User that entered the channel' | |
header "X_PUSHER_KEY", :pusher_key | |
header "X_PUSHER_SIGNATURE", :pusher_signature | |
header 'Content-Type', 'application/json' | |
example_request 'User enters a call channel' do | |
status.should == 200 | |
# add other assertions | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment