slack-ruby-client 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb40a47e675fcf0265b109933983e54e11b6c9df574d355debde7c8ec5430148
4
- data.tar.gz: 3e32b46f06a4e0d28db8e2bcdd329b57b1d719adadc8e8fcc246f45e6128c59e
3
+ metadata.gz: 7a9bf266ef0726336ea6cdd36426970d5a21663646cf066e72a74a23b4c175d6
4
+ data.tar.gz: e36dd13202ddfe6bb65cc2bfde27f8ac27350da4114dfdf9545d1c6f2d0f0611
5
5
  SHA512:
6
- metadata.gz: 53da5f288963057384831ff33711031fa866aad91f3857eeaae312e303640a60316459ddd20f18940d145aa4b9cf57cd7c8fdff9dee82ecb912b809f85db49cd
7
- data.tar.gz: f235bb2ea8e6b5e64d247e2727d50618d54e9af471a4fd73c0e02bf43d0d70dda712b5e973c8033ecebd20501843eb6eb11eaf57cd53c1f71b4b45fd411b03f5
6
+ metadata.gz: 5ab13f62322d8f5b9f3b6723a003fc7303806b03f42a68d53eaf2bf12d6f96375d895c03ce6a4657cd26f74ce2c137fb04c4b88946ff0e3c5dbd8076ea285ee2
7
+ data.tar.gz: cf23b660a516ce28249b8de57e814bd997e828f712c467db46c28a6ea9be64827cf82d594369df686b4ab3c00c4a4968a40f83308b73d49b19469d667c385551
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-08-20 08:24:54 -0400 using RuboCop version 0.58.2.
3
+ # on 2018-08-27 13:29:57 +0200 using RuboCop version 0.58.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
data/.travis.yml CHANGED
@@ -18,6 +18,8 @@ matrix:
18
18
  env: CONCURRENCY=celluloid-io
19
19
  - rvm: 2.4.1
20
20
  env: CONCURRENCY=faye-websocket
21
+ - rvm: 2.5
22
+ env: CONCURRENCY=async-websocket
21
23
  allow_failures:
22
24
  - rvm: ruby-head
23
25
  - rvm: jruby-head
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.13.0 (Next)
2
+
3
+ * [#219](https://github.com/slack-ruby/slack-ruby-client/pull/219): Added support for `async-websocket` - [@dblock](https://github.com/dblock), [@ioquatix](https://github.com/ioquatix).
4
+ * [#224](https://github.com/slack-ruby/slack-ruby-client/pull/224): Celluloid async support now uses a thread per client - [@dblock](https://github.com/dblock).
5
+ * [#224](https://github.com/slack-ruby/slack-ruby-client/pull/224): Attempt to shutdown EventMachine if a reactor wasn't already running on start - [@dblock](https://github.com/dblock).
6
+ * Your contribution here.
7
+
1
8
  ### 0.12.0 (8/20/2018)
2
9
 
3
10
  * [#216](https://github.com/slack-ruby/slack-ruby-client/pull/216): Handle `Errno::ECONNRESET` and empty buffer reads with celluloid-io - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -18,7 +18,7 @@ A Ruby client for the Slack [Web](https://api.slack.com/web) and [RealTime Messa
18
18
 
19
19
  ## Stable Release
20
20
 
21
- You're reading the documentation for the **stable** release of slack-ruby-client, 0.12.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
21
+ You're reading the documentation for the **stable** release of slack-ruby-client, v0.13.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
22
22
 
23
23
  ## Installation
24
24
 
@@ -28,11 +28,10 @@ Add to Gemfile.
28
28
  gem 'slack-ruby-client'
29
29
  ```
30
30
 
31
- If you're going to be using the RealTime client, add either `eventmachine` and `faye-websocket` or `celluloid-io`. See below for more information about concurrency.
31
+ If you're going to be using the RealTime client, add either `async-websocket`, `eventmachine` and `faye-websocket` or `celluloid-io`. See below for more information about concurrency. We recommend you use `async-websocket`.
32
32
 
33
33
  ```
34
- gem 'eventmachine'
35
- gem 'faye-websocket'
34
+ gem 'async-websocket'
36
35
  ```
37
36
 
38
37
  Run `bundle install`.
@@ -374,11 +373,11 @@ See [#134](https://github.com/slack-ruby/slack-ruby-client/issues/134) for a dis
374
373
 
375
374
  #### Concurrency
376
375
 
377
- `Slack::RealTime::Client` needs help from a concurrency library and supports [Faye::WebSocket](https://github.com/faye/faye-websocket-ruby) with [Eventmachine](https://github.com/eventmachine/eventmachine) and [Celluloid](https://github.com/celluloid/celluloid). It will auto-detect one or the other depending on the gems in your Gemfile, but you can also set concurrency explicitly.
376
+ `Slack::RealTime::Client` needs help from a concurrency library and supports [Async](https://github.com/socketry/async), [Faye::WebSocket](https://github.com/faye/faye-websocket-ruby) with [Eventmachine](https://github.com/eventmachine/eventmachine) and [Celluloid](https://github.com/celluloid/celluloid). It will auto-detect one or the other depending on the gems in your Gemfile, but you can also set concurrency explicitly.
378
377
 
379
378
  ```ruby
380
379
  Slack::RealTime.configure do |config|
381
- config.concurrency = Slack::RealTime::Concurrency::Eventmachine
380
+ config.concurrency = Slack::RealTime::Concurrency::Async
382
381
  end
383
382
  ```
384
383
 
@@ -390,6 +389,16 @@ client = Slack::RealTime::Client.new
390
389
  client.start_async
391
390
  ```
392
391
 
392
+ ##### Async
393
+
394
+ This is the recommended library. Add `async-websocket` to your Gemfile.
395
+
396
+ ```
397
+ gem 'async-websocket'
398
+ ```
399
+
400
+ See a fully working example in [examples/hi_real_time_async_async](examples/hi_real_time_async_async/hi.rb).
401
+
393
402
  ##### Faye::Websocket with Eventmachine
394
403
 
395
404
  Add the following to your Gemfile.
data/UPGRADING.md CHANGED
@@ -1,6 +1,22 @@
1
1
  Upgrading Slack-Ruby-Client
2
2
  ===========================
3
3
 
4
+ ### Upgrading to >= 0.13.0
5
+
6
+ #### Recommended Async Library
7
+
8
+ The RealTime client now supports [async-websocket](https://github.com/socketry/async-websocket), which is actively maintained and is now the recommended library.
9
+
10
+ See [#219](https://github.com/slack-ruby/slack-ruby-client/pull/219) for implementation details.
11
+
12
+ #### Async Library Threading and Reactor Changes
13
+
14
+ The RealTime celluloid-io implementation now uses a `Thread` per client. Previous versions used an `Actor`.
15
+
16
+ The faye-websocket implementation with EventMachine will attempt to shutdown EventMachine via `EventMachine.stop` upon shutdown if a reactor wasn't already running.
17
+
18
+ See [#224](https://github.com/slack-ruby/slack-ruby-client/pull/224) for more information.
19
+
4
20
  ### Upgrading to >= 0.9.0
5
21
 
6
22
  #### Changes in How the RTM Client Connects
@@ -37,7 +53,7 @@ Slack::RealTime::Client.config do |config|
37
53
  end
38
54
  ```
39
55
 
40
- See [#136](https://github.com/slack-ruby/slack-ruby-client/pull/136) for more details.
56
+ See [#136](https://github.com/slack-ruby/slack-ruby-client/pull/136) for more information.
41
57
 
42
58
  ### Upgrading to >= 0.6.0
43
59
 
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'slack-ruby-client', path: '../..'
4
+
5
+ gem 'async-websocket'
6
+ gem 'foreman'
@@ -0,0 +1,2 @@
1
+ console: bundle exec ruby hi.rb
2
+
@@ -0,0 +1,37 @@
1
+ require 'slack-ruby-client'
2
+ require 'async'
3
+
4
+ raise 'Missing ENV[SLACK_API_TOKENS]!' unless ENV.key?('SLACK_API_TOKENS')
5
+
6
+ $stdout.sync = true
7
+ logger = Logger.new($stdout)
8
+ logger.level = Logger::DEBUG
9
+
10
+ threads = []
11
+
12
+ ENV['SLACK_API_TOKENS'].split.each do |token|
13
+ logger.info "Starting #{token[0..12]} ..."
14
+
15
+ client = Slack::RealTime::Client.new(token: token)
16
+
17
+ client.on :hello do
18
+ logger.info "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
19
+ end
20
+
21
+ client.on :message do |data|
22
+ logger.info data
23
+
24
+ client.typing channel: data.channel
25
+
26
+ case data.text
27
+ when /hi/ then
28
+ client.message channel: data.channel, text: "Hi <@#{data.user}>!"
29
+ else
30
+ client.message channel: data.channel, text: "Sorry <@#{data.user}>, what?"
31
+ end
32
+ end
33
+
34
+ threads << client.start_async
35
+ end
36
+
37
+ threads.each(&:join)
@@ -1,6 +1,7 @@
1
1
  module Slack
2
2
  module RealTime
3
3
  module Concurrency
4
+ autoload :Async, 'slack/real_time/concurrency/async'
4
5
  autoload :Eventmachine, 'slack/real_time/concurrency/eventmachine'
5
6
  autoload :Celluloid, 'slack/real_time/concurrency/celluloid'
6
7
  end
@@ -0,0 +1,67 @@
1
+ require 'async/websocket'
2
+
3
+ module Slack
4
+ module RealTime
5
+ module Concurrency
6
+ module Async
7
+ class Client < ::Async::WebSocket::Client
8
+ extend ::Forwardable
9
+ def_delegators :@driver, :on, :text, :binary, :emit
10
+ end
11
+
12
+ class Socket < Slack::RealTime::Socket
13
+ attr_reader :client
14
+
15
+ def start_async(client)
16
+ Thread.new do
17
+ ::Async::Reactor.run do
18
+ client.run_loop
19
+ end
20
+ end
21
+ end
22
+
23
+ def connect!
24
+ super
25
+ run_loop
26
+ end
27
+
28
+ def close
29
+ @closing = true
30
+ @driver.close if @driver
31
+ super
32
+ end
33
+
34
+ def run_loop
35
+ @closing = false
36
+ while @driver && @driver.next_event
37
+ # $stderr.puts event.inspect
38
+ end
39
+ end
40
+
41
+ protected
42
+
43
+ def build_ssl_context
44
+ OpenSSL::SSL::SSLContext.new(:TLSv1_2_client).tap do |ctx|
45
+ ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER)
46
+ end
47
+ end
48
+
49
+ def build_endpoint
50
+ endpoint = ::Async::IO::Endpoint.tcp(addr, port)
51
+ endpoint = ::Async::IO::SSLEndpoint.new(endpoint, ssl_context: build_ssl_context) if secure?
52
+ endpoint
53
+ end
54
+
55
+ def connect_socket
56
+ build_endpoint.connect
57
+ end
58
+
59
+ def connect
60
+ @socket = connect_socket
61
+ @driver = Client.new(@socket, url)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -68,12 +68,9 @@ module Slack
68
68
  end
69
69
 
70
70
  def start_async(client)
71
- @client = client
72
- Actor.new(future.run_client_loop)
73
- end
74
-
75
- def run_client_loop
76
- @client.run_loop
71
+ Thread.new do
72
+ client.run_loop
73
+ end
77
74
  end
78
75
 
79
76
  def connected?
@@ -82,18 +79,6 @@ module Slack
82
79
 
83
80
  protected
84
81
 
85
- class Actor
86
- attr_reader :future
87
-
88
- def initialize(future)
89
- @future = future
90
- end
91
-
92
- def join
93
- @future.value
94
- end
95
- end
96
-
97
82
  def build_socket
98
83
  socket = ::Celluloid::IO::TCPSocket.new(addr, port)
99
84
  socket = ::Celluloid::IO::SSLSocket.new(socket, build_ssl_context) if secure?
@@ -27,11 +27,17 @@ module Slack
27
27
 
28
28
  class Socket < Slack::RealTime::Socket
29
29
  def start_async(client)
30
- thread = ensure_reactor_running
30
+ @thread = ensure_reactor_running
31
31
 
32
32
  client.run_loop
33
33
 
34
- thread
34
+ @thread
35
+ end
36
+
37
+ def close
38
+ super
39
+ EventMachine.stop if @thread
40
+ @thread = nil
35
41
  end
36
42
 
37
43
  def send_data(message)
@@ -36,7 +36,7 @@ module Slack
36
36
  private
37
37
 
38
38
  def detect_concurrency
39
- %i[Eventmachine Celluloid].each do |concurrency|
39
+ %i[Async Eventmachine Celluloid].each do |concurrency|
40
40
  begin
41
41
  return Slack::RealTime::Concurrency.const_get(concurrency)
42
42
  rescue LoadError, NameError
@@ -44,7 +44,7 @@ module Slack
44
44
  end
45
45
  end
46
46
 
47
- raise NoConcurrencyError, 'Missing concurrency. Add faye-websocket or celluloid-io to your Gemfile.'
47
+ raise NoConcurrencyError, 'Missing concurrency. Add async-websocket, faye-websocket or celluloid-io to your Gemfile.'
48
48
  end
49
49
  end
50
50
 
data/lib/slack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = '0.12.0'.freeze
2
+ VERSION = '0.13.0'.freeze
3
3
  end
@@ -74,6 +74,7 @@ RSpec.describe 'integration test', skip: (!ENV['SLACK_API_TOKEN'] || !ENV['CONCU
74
74
 
75
75
  after do
76
76
  wait_for_server
77
+ connection.join
77
78
  end
78
79
 
79
80
  context 'client connected' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-21 00:00:00.000000000 Z
11
+ date: 2018-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -256,6 +256,9 @@ files:
256
256
  - examples/hi_real_time_and_web/Gemfile
257
257
  - examples/hi_real_time_and_web/hi.gif
258
258
  - examples/hi_real_time_and_web/hi.rb
259
+ - examples/hi_real_time_async_async/Gemfile
260
+ - examples/hi_real_time_async_async/Procfile
261
+ - examples/hi_real_time_async_async/hi.rb
259
262
  - examples/hi_real_time_async_celluloid/Gemfile
260
263
  - examples/hi_real_time_async_celluloid/Procfile
261
264
  - examples/hi_real_time_async_celluloid/hi.rb
@@ -281,6 +284,7 @@ files:
281
284
  - lib/slack/real_time/api/typing.rb
282
285
  - lib/slack/real_time/client.rb
283
286
  - lib/slack/real_time/concurrency.rb
287
+ - lib/slack/real_time/concurrency/async.rb
284
288
  - lib/slack/real_time/concurrency/celluloid.rb
285
289
  - lib/slack/real_time/concurrency/eventmachine.rb
286
290
  - lib/slack/real_time/config.rb