Skip to content

Commit

Permalink
Added an example
Browse files Browse the repository at this point in the history
New examples folder.  Only has one at the moment: 
an async message send.
  • Loading branch information
maryrosecook committed Jun 7, 2011
1 parent aec6295 commit d24ee51
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/async_message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rubygems'
require 'pusher'
require 'eventmachine'
require 'em-http-request'

# To get these values:
# - Go to https://app.pusherapp.com/
# - Click on Choose App.
# - Click on one of your apps
# - Click API Access
Pusher.app_id = 'your_app_id'
Pusher.key = 'your_key'
Pusher.secret = 'your_secret'


EM.run {
deferrable = Pusher['test_channel'].trigger_async('my_event', 'hi')

deferrable.callback { # called on success
puts "Message sent successfully."
EM.stop
}
deferrable.errback { |error| # called on error
puts "Message could not be sent."
puts error
EM.stop
}
}

0 comments on commit d24ee51

Please sign in to comment.