async-slack 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/async-slack.gemspec +1 -1
- data/lib/async/slack/error.rb +33 -0
- data/lib/async/slack/real_time.rb +9 -5
- data/lib/async/slack/representation.rb +9 -27
- data/lib/async/slack/rspec/client.rb +0 -6
- data/lib/async/slack/search.rb +2 -1
- data/lib/async/slack/version.rb +1 -1
- data/spec/async/slack/real_time_spec.rb +1 -1
- data/spec/async/slack_spec.rb +2 -2
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8143c9be22d6019597a9580450dcfc2300621d1583b98532a6ade4468b6f071
|
4
|
+
data.tar.gz: c1f6196fdd510cdd38afa55db8a62f6e8815218d500946ea5aed1280760dc06a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ceab1b01a277eaa787a6f2ce2b7885525627b5ee1022710d9120914e2d30f7b389c79a25b3bf24412ad5f1ca2306ff06e69b987b6e23cd1913f3bed965447c5
|
7
|
+
data.tar.gz: 13131c502414079d4f5f255eb3add17df723b181fa57183d092e509ee201b3c6b29c4c9e233b0a7a58167a25354f189c37a9b0ede4b0c170b0d1240507160b1c
|
data/async-slack.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.add_dependency "async-rest"
|
19
|
+
spec.add_dependency "async-rest", "~> 0.12"
|
20
20
|
spec.add_dependency "async-websocket", "~> 0.13"
|
21
21
|
|
22
22
|
spec.add_development_dependency "async-rspec"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literals: true
|
2
|
+
#
|
3
|
+
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative 'representation'
|
24
|
+
|
25
|
+
module Async
|
26
|
+
module Slack
|
27
|
+
class Error < StandardError
|
28
|
+
end
|
29
|
+
|
30
|
+
class ConnectionError < Error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -24,6 +24,7 @@ require "async/websocket/client"
|
|
24
24
|
require "async/websocket/response"
|
25
25
|
|
26
26
|
require_relative 'representation'
|
27
|
+
require_relative 'error'
|
27
28
|
|
28
29
|
module Async
|
29
30
|
module Slack
|
@@ -32,12 +33,15 @@ module Async
|
|
32
33
|
response = self.post
|
33
34
|
|
34
35
|
parameters = response.read
|
35
|
-
url = parameters[:url]
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
if url = parameters[:url]
|
38
|
+
endpoint = Async::HTTP::Endpoint.parse(url)
|
39
|
+
|
40
|
+
Async::WebSocket::Client.connect(endpoint, **options) do |connection|
|
41
|
+
self.start(connection, &block)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
raise ConnectionError, parameters
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
@@ -21,47 +21,29 @@
|
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
23
|
require 'async/rest/representation'
|
24
|
-
require 'async/rest/wrapper/
|
25
|
-
require 'async/rest/wrapper/url_encoded'
|
24
|
+
require 'async/rest/wrapper/form'
|
26
25
|
|
27
26
|
module Async
|
28
27
|
module Slack
|
29
|
-
class Wrapper < Async::REST::Wrapper::
|
30
|
-
def prepare_request(payload, headers)
|
31
|
-
super(nil, headers)
|
32
|
-
|
33
|
-
if payload
|
34
|
-
headers['content-type'] = Async::REST::Wrapper::URLEncoded::APPLICATION_FORM_URLENCODED
|
35
|
-
|
36
|
-
::Protocol::HTTP::Body::Buffered.new([
|
37
|
-
::Protocol::HTTP::URL.encode(payload)
|
38
|
-
])
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
28
|
+
class Wrapper < Async::REST::Wrapper::Form
|
42
29
|
class Parser < HTTP::Body::Wrapper
|
43
30
|
def join
|
44
|
-
|
31
|
+
value = ::JSON.parse(super, symbolize_names: true)
|
45
32
|
|
46
|
-
if error =
|
47
|
-
raise
|
33
|
+
if error = value[:error]
|
34
|
+
raise Error, error
|
48
35
|
end
|
49
36
|
|
50
|
-
return
|
37
|
+
return value
|
51
38
|
end
|
52
39
|
end
|
53
40
|
|
54
|
-
def
|
55
|
-
|
56
|
-
response.body = Parser.new(body)
|
57
|
-
end
|
41
|
+
def parser_for(response)
|
42
|
+
Parser
|
58
43
|
end
|
59
44
|
end
|
60
45
|
|
61
|
-
class Representation < Async::REST::Representation
|
62
|
-
def initialize(*args, **options)
|
63
|
-
super(*args, wrapper: Wrapper.new, **options)
|
64
|
-
end
|
46
|
+
class Representation < Async::REST::Representation[Wrapper]
|
65
47
|
end
|
66
48
|
end
|
67
49
|
end
|
@@ -37,12 +37,6 @@ module Async
|
|
37
37
|
# You must specify these in order for the tests to run.
|
38
38
|
let(:token) {ENV['SLACK_TOKEN']}
|
39
39
|
let(:channel) {'#testing'}
|
40
|
-
|
41
|
-
let(:connection) {@connection = Async::Slack.connect(token: token)}
|
42
|
-
|
43
|
-
after do
|
44
|
-
@connection&.close
|
45
|
-
end
|
46
40
|
end
|
47
41
|
end
|
48
42
|
end
|
data/lib/async/slack/search.rb
CHANGED
@@ -42,7 +42,7 @@ module Async
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# Was this the last page?
|
45
|
-
break if records.
|
45
|
+
break if records.size < count
|
46
46
|
|
47
47
|
page += 1
|
48
48
|
end
|
@@ -69,6 +69,7 @@ module Async
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def records
|
72
|
+
binding.irb
|
72
73
|
self.value[:messages][:matches]
|
73
74
|
end
|
74
75
|
|
data/lib/async/slack/version.rb
CHANGED
data/spec/async/slack_spec.rb
CHANGED
@@ -29,7 +29,7 @@ RSpec.describe Async::Slack::Client do
|
|
29
29
|
message = client.chat.send_message(channel: channel, text: "The time is #{Time.now}")
|
30
30
|
message.value = nil
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end.wait
|
33
33
|
end
|
34
34
|
|
35
35
|
it "can search for messages" do
|
@@ -37,6 +37,6 @@ RSpec.describe Async::Slack::Client do
|
|
37
37
|
messages = client.search.messages(query: "Hello World").to_a
|
38
38
|
|
39
39
|
expect(messages).to_not be_empty
|
40
|
-
end
|
40
|
+
end.wait
|
41
41
|
end
|
42
42
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-slack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-rest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.12'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.12'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: async-websocket
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/async/slack.rb
|
128
128
|
- lib/async/slack/chat.rb
|
129
129
|
- lib/async/slack/client.rb
|
130
|
+
- lib/async/slack/error.rb
|
130
131
|
- lib/async/slack/real_time.rb
|
131
132
|
- lib/async/slack/representation.rb
|
132
133
|
- lib/async/slack/rspec/client.rb
|
@@ -154,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
155
|
- !ruby/object:Gem::Version
|
155
156
|
version: '0'
|
156
157
|
requirements: []
|
157
|
-
rubygems_version: 3.0.
|
158
|
+
rubygems_version: 3.0.6
|
158
159
|
signing_key:
|
159
160
|
specification_version: 4
|
160
161
|
summary: Build Slack bots and use real time messaging.
|