em-pusher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +35 -0
- data/lib/em-pusher.rb +1 -0
- data/lib/em/pusher.rb +67 -0
- metadata +120 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Chris Gaffney
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= em-pusher
|
2
|
+
|
3
|
+
An EventMachine client for pusherapp.com
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
$ gem install em-pusher
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
require 'em-pusher'
|
12
|
+
|
13
|
+
EventMachine.run do
|
14
|
+
# All of these options are required
|
15
|
+
pusher = EventMachine::Pusher.new(
|
16
|
+
:app_id => 1845,
|
17
|
+
:auth_key => 'your secret token',
|
18
|
+
:auth_secret => 'secret_key_from_pusher',
|
19
|
+
:channel => 'updates'
|
20
|
+
)
|
21
|
+
|
22
|
+
pusher.trigger('counts', { :tickers => %w(aapl goog) })
|
23
|
+
end
|
24
|
+
|
25
|
+
== Note on Patches/Pull Requests
|
26
|
+
|
27
|
+
* Fork the project.
|
28
|
+
* Make your feature addition or bug fix.
|
29
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
30
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
|
31
|
+
* Send me a pull request. Bonus points for topic branches.
|
32
|
+
|
33
|
+
== Copyright
|
34
|
+
|
35
|
+
See LICENSE for details.
|
data/lib/em-pusher.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'em/pusher'
|
data/lib/em/pusher.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
require 'em-http'
|
3
|
+
require 'hmac-sha2'
|
4
|
+
require 'digest/md5'
|
5
|
+
|
6
|
+
class EventMachine::Pusher < EventMachine::HttpRequest
|
7
|
+
AUTH_VERSION = '1.0'
|
8
|
+
|
9
|
+
# Initialize a new client, each client is associated with only one channel
|
10
|
+
# at a time.
|
11
|
+
#
|
12
|
+
# === Required options
|
13
|
+
# [:app_id]
|
14
|
+
# ID specific to your application
|
15
|
+
# [:auth_key]
|
16
|
+
# Application key provided by pusherapp.com
|
17
|
+
# [:auth_secret]
|
18
|
+
# Application secret provided by pusherapp.com
|
19
|
+
# [:channel]
|
20
|
+
# Channel that updates will be posted to
|
21
|
+
#
|
22
|
+
def initialize(config)
|
23
|
+
@app_id = config[:app_id]
|
24
|
+
@auth_key = config[:auth_key]
|
25
|
+
@auth_secret = config[:auth_secret]
|
26
|
+
@channel = config[:channel]
|
27
|
+
|
28
|
+
super("http://api.pusherapp.com/apps/#{@app_id}/channels/#{@channel}/events")
|
29
|
+
end
|
30
|
+
|
31
|
+
# Trigger +event+ on the client side with the given name. The +data+ parameter
|
32
|
+
# is converted to JSON and parsed on the other end.
|
33
|
+
#
|
34
|
+
# ==== Examples
|
35
|
+
#
|
36
|
+
# # Send the counts event updating how many users there are
|
37
|
+
# pusher.trigger('counts', :users => 5)
|
38
|
+
#
|
39
|
+
# # Send an update and check to see if it succeeded
|
40
|
+
# post = pusher.trigger('users', :user => { :name => 'Mary' })
|
41
|
+
# post.callback do
|
42
|
+
# # Ensure it worked
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
def trigger(event, data)
|
46
|
+
body = Yajl::Encoder.encode(data)
|
47
|
+
digest = Digest::MD5.hexdigest(body)
|
48
|
+
timestamp = Time.now.to_i
|
49
|
+
|
50
|
+
signature =
|
51
|
+
"POST\n/apps/#{@app_id}/channels/#{@channel}/events\nauth_key=#{@auth_key}&" +
|
52
|
+
"auth_timestamp=#{timestamp}&auth_version=#{AUTH_VERSION}&" +
|
53
|
+
"body_md5=#{digest}&name=#{event}"
|
54
|
+
|
55
|
+
self.post(
|
56
|
+
:query => {
|
57
|
+
'auth_key' => @auth_key,
|
58
|
+
'auth_timestamp' => timestamp,
|
59
|
+
'body_md5' => digest,
|
60
|
+
'name' => event,
|
61
|
+
'auth_version' => AUTH_VERSION,
|
62
|
+
'auth_signature' => HMAC::SHA256.hexdigest(@auth_secret, signature)
|
63
|
+
},
|
64
|
+
:body => body
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-pusher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Chris Gaffney
|
14
|
+
- Brian Ryckbost
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-07-11 00:00:00 -04:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: yajl-ruby
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 15
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 7
|
34
|
+
- 6
|
35
|
+
version: 0.7.6
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: em-http-request
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
- 2
|
50
|
+
- 10
|
51
|
+
version: 0.2.10
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: ruby-hmac
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 15
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
- 4
|
66
|
+
- 0
|
67
|
+
version: 0.4.0
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id003
|
70
|
+
description:
|
71
|
+
email:
|
72
|
+
- gaffneyc@gmail.com
|
73
|
+
- brian@collectiveidea.com
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files: []
|
79
|
+
|
80
|
+
files:
|
81
|
+
- lib/em/pusher.rb
|
82
|
+
- lib/em-pusher.rb
|
83
|
+
- LICENSE
|
84
|
+
- README.rdoc
|
85
|
+
has_rdoc: true
|
86
|
+
homepage: http://github.com/gaffneyc/em-pusher
|
87
|
+
licenses: []
|
88
|
+
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
requirements: []
|
113
|
+
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.3.7
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: EventMachine client for pusherapp.com
|
119
|
+
test_files: []
|
120
|
+
|