eventflit-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +15 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.md +92 -0
- data/Rakefile +7 -0
- data/certs/cacert.pem +3554 -0
- data/eventflit-client.gemspec +30 -0
- data/examples/hello_eventflit.rb +19 -0
- data/examples/hello_eventflit_async.rb +22 -0
- data/examples/hello_eventflit_ssl.rb +19 -0
- data/examples/subscribe_private.rb +20 -0
- data/lib/eventflit-client/channel.rb +56 -0
- data/lib/eventflit-client/channels.rb +35 -0
- data/lib/eventflit-client/socket.rb +244 -0
- data/lib/eventflit-client/version.rb +3 -0
- data/lib/eventflit-client/websocket.rb +99 -0
- data/lib/eventflit-client.rb +22 -0
- data/spec/eventflitclient_spec.rb +181 -0
- data/spec/spec_helper.rb +51 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c629865a4ea4d81e365d7637ab79526d6f8c78ed
|
4
|
+
data.tar.gz: 4a834cd1604769efecbfc728ebb5f2a7d932f494
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e0aa4cc3a4beb0e71315d000f4c52bd271a99aa0291ffd4695807da1eedc0b029db80097851382b2b45cc221d6fe2afead20f1819cb8486cf1a21fcf0c77cb3
|
7
|
+
data.tar.gz: 426e1e6d7f4f0f6a8755d78888245a8e6f793dc22c85dbc24cbe17570948aad3406c98d02c3597e499ed7d008365e1aef28bc9aa9eaab7f26e043f613b859ae7
|
data/.document
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Logan Koester
|
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.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# eventflit-client: Ruby WebSocket client for Eventflit Channels
|
2
|
+
|
3
|
+
`eventflit-client` is a Ruby gem for consuming WebSockets from Eventflit service.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```sh
|
8
|
+
gem install eventflit-client
|
9
|
+
```
|
10
|
+
|
11
|
+
This gem is compatible with jruby
|
12
|
+
|
13
|
+
## Single-Threaded Usage
|
14
|
+
|
15
|
+
The application will pause at `eventflit.connect` and handle events from Eventflit Channels as they happen.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'eventflit-client'
|
19
|
+
cluster = 'cus1' # take this from your app's config in the dashboard
|
20
|
+
eventflit = EventflitClient::Socket.new(YOUR_APPLICATION_KEY, {
|
21
|
+
secure: true,
|
22
|
+
ws_host: "ws-#{cluster}.eventflit.com"
|
23
|
+
})
|
24
|
+
|
25
|
+
# Subscribe to two channels
|
26
|
+
eventflit.subscribe('channel1')
|
27
|
+
eventflit.subscribe('channel2')
|
28
|
+
|
29
|
+
# Subscribe to presence channel
|
30
|
+
eventflit.subscribe('presence-channel3', USER_ID)
|
31
|
+
|
32
|
+
# Subscribe to private channel
|
33
|
+
eventflit.subscribe('private-channel4', USER_ID)
|
34
|
+
|
35
|
+
# Subscribe to presence channel with custom data (user_id is mandatory)
|
36
|
+
eventflit.subscribe('presence-channel5', :user_id => USER_ID, :user_name => 'john')
|
37
|
+
|
38
|
+
# Bind to a global event (can occur on either channel1 or channel2)
|
39
|
+
eventflit.bind('globalevent') do |data|
|
40
|
+
puts data
|
41
|
+
end
|
42
|
+
|
43
|
+
# Bind to a channel event (can only occur on channel1)
|
44
|
+
eventflit['channel1'].bind('channelevent') do |data|
|
45
|
+
puts data
|
46
|
+
end
|
47
|
+
|
48
|
+
eventflit.connect
|
49
|
+
```
|
50
|
+
|
51
|
+
## Asynchronous Usage
|
52
|
+
|
53
|
+
With `eventflit.connect(true)`,
|
54
|
+
the connection to Eventflit Channels will be maintained in its own thread.
|
55
|
+
The connection will remain open in the background as long as your main application thread is running,
|
56
|
+
and you can continue to subscribe/unsubscribe to channels and bind new events.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'eventflit-client'
|
60
|
+
eventflit = EventflitClient::Socket.new(YOUR_APPLICATION_KEY)
|
61
|
+
eventflit.connect(true) # Connect asynchronously
|
62
|
+
|
63
|
+
# Subscribe to two channels
|
64
|
+
eventflit.subscribe('channel1')
|
65
|
+
eventflit.subscribe('channel2')
|
66
|
+
|
67
|
+
# Bind to a global event (can occur on either channel1 or channel2)
|
68
|
+
eventflit.bind('globalevent') do |data|
|
69
|
+
puts data
|
70
|
+
end
|
71
|
+
|
72
|
+
# Bind to a channel event (can only occur on channel1)
|
73
|
+
eventflit['channel1'].bind('channelevent') do |data|
|
74
|
+
puts data
|
75
|
+
end
|
76
|
+
|
77
|
+
loop do
|
78
|
+
sleep(1) # Keep your main thread running
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
## Using native WebSocket implementation
|
83
|
+
|
84
|
+
This gem depends on [the `websocket` gem](https://github.com/imanel/websocket-ruby)
|
85
|
+
which is a pure Ruby implementation of websockets.
|
86
|
+
|
87
|
+
However it can optionally use a native C or Java implementation for a 25% speed
|
88
|
+
increase by including [the `websocket-native` gem](https://github.com/imanel/websocket-ruby-native) in your Gemfile.
|
89
|
+
|
90
|
+
## Copyright and license
|
91
|
+
|
92
|
+
See `LICENSE.txt`.
|