peertransfer_chat 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -5
- data/lib/peertransfer_chat/client.rb +16 -18
- data/lib/peertransfer_chat/config.rb +2 -2
- data/lib/peertransfer_chat/version.rb +1 -1
- data/peertransfer_chat.gemspec +5 -6
- data/spec/integration/client_spec.rb +14 -16
- data/spec/lib/client_spec.rb +26 -16
- data/spec/lib/config_spec.rb +4 -7
- data/spec/spec_helper.rb +2 -6
- metadata +18 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9c28b8b6798c36f859bf9fa63d12fcfb372ad3c5d2bf8bbfaad56283687fdf22
|
4
|
+
data.tar.gz: a8660d1c881f00574c989093cbd9785b546ba338d3af408863c04d975f327d0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31aa7028b318466037262af551f3f54e32584cb55659a2a8fa8bfbf6f84f4b821dc1a02e9f107510d05a0e15321ac3914c7af0ca22a60fdff5ac943a303fb418
|
7
|
+
data.tar.gz: 80ac78dbdbf6b67e73adfd9b23dfa8c0aadb2d70e34bbdfe653cac50f4c968a11d37ecc0a470a7346866ed45f99778b3aee9ada95a18a8d6262876e45fc67a1d
|
data/README.md
CHANGED
@@ -29,8 +29,7 @@ Configure the chat client:
|
|
29
29
|
|
30
30
|
```ruby
|
31
31
|
PeertransferChat.configure do |config|
|
32
|
-
config.
|
33
|
-
config.incoming_token = team_token
|
32
|
+
config.api_token = api_token
|
34
33
|
config.channel = team_channel
|
35
34
|
config.username = team_username
|
36
35
|
end
|
@@ -48,9 +47,6 @@ PeertransferChat::Client.upload('/path/to/a/file.txt')
|
|
48
47
|
```
|
49
48
|
|
50
49
|
## Slack settings description
|
51
|
-
- `team` Your team
|
52
50
|
- `channel` Channel name
|
53
51
|
- `api_token` This token comes from your user https://api.slack.com/web
|
54
52
|
- `rtm_token` Real time messaging, you can find it in integration -> bot -> token
|
55
|
-
- `incomming_token` Incoming web hook token, you can create one in integration -> incomming webhooks
|
56
|
-
- `channel_id` Channel id you can find it in the code of your slack team web page
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'slack-ruby-client'
|
2
2
|
|
3
3
|
class PeertransferChat
|
4
4
|
class Client
|
@@ -20,38 +20,36 @@ class PeertransferChat
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def upload(filename, opts = {})
|
23
|
-
|
24
|
-
|
23
|
+
client.files_upload(
|
24
|
+
channels: channel,
|
25
|
+
as_user: true,
|
26
|
+
file: Faraday::UploadIO.new(filename, 'image/png'),
|
27
|
+
title: 'output.txt',
|
28
|
+
filename: filename,
|
29
|
+
initial_comment: 'Attachment'
|
30
|
+
)
|
25
31
|
end
|
26
32
|
|
27
33
|
def speak(message)
|
28
|
-
|
29
|
-
slack.say(message)
|
34
|
+
client.chat_postMessage(channel: channel, text: message, as_user: true, username: username)
|
30
35
|
end
|
31
36
|
|
32
37
|
private
|
33
38
|
|
34
|
-
def
|
35
|
-
|
39
|
+
def client
|
40
|
+
@client ||= Slack::Web::Client.new(token: api_token)
|
36
41
|
end
|
37
42
|
|
38
|
-
def
|
39
|
-
config.
|
43
|
+
def channel
|
44
|
+
config.channel
|
40
45
|
end
|
41
46
|
|
42
47
|
def api_token
|
43
48
|
config.api_token
|
44
49
|
end
|
45
50
|
|
46
|
-
def
|
47
|
-
config.
|
48
|
-
end
|
49
|
-
|
50
|
-
def slack_opts
|
51
|
-
{
|
52
|
-
'channel' => config.channel,
|
53
|
-
'username' => config.username
|
54
|
-
}
|
51
|
+
def username
|
52
|
+
config.username
|
55
53
|
end
|
56
54
|
|
57
55
|
def config
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class PeertransferChat
|
2
2
|
class Config
|
3
|
-
SETTINGS = [:
|
3
|
+
SETTINGS = [:channel, :username, :api_token]
|
4
4
|
|
5
5
|
attr_accessor(*SETTINGS)
|
6
6
|
|
7
7
|
def valid?
|
8
|
-
@
|
8
|
+
@api_token && @channel && @username
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
data/peertransfer_chat.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'peertransfer_chat/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'peertransfer_chat'
|
8
8
|
spec.version = PeertransferChat::VERSION
|
9
|
-
spec.authors = ['
|
10
|
-
spec.email = ['
|
9
|
+
spec.authors = ['Flywire Engineering']
|
10
|
+
spec.email = ['engineering@flywire.com']
|
11
11
|
spec.summary = %q{A common interface to our chat system}
|
12
12
|
spec.description = %q{A common interface to our chat system}
|
13
13
|
|
@@ -19,9 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = Dir['spec/*.rb'] + Dir['spec/**/*.rb']
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_runtime_dependency '
|
22
|
+
spec.add_runtime_dependency 'slack-ruby-client', '~> 0.14'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler'
|
25
|
-
spec.add_development_dependency '
|
26
|
-
spec.add_development_dependency 'coveralls'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
27
26
|
end
|
@@ -1,32 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe PeertransferChat::Client do
|
4
|
-
let(:slack_client) { instance_spy(
|
5
|
-
let(:team_name) { 'a team' }
|
6
|
-
let(:team_token) { 'a token' }
|
4
|
+
let(:slack_client) { instance_spy(Slack::Web::Client) }
|
7
5
|
let(:team_channel) { 'a channel' }
|
8
6
|
let(:team_username) { 'a username' }
|
9
|
-
let(:
|
7
|
+
let(:api_token) { 'a_api_token' }
|
10
8
|
|
11
9
|
context 'with class configuration' do
|
12
10
|
before do
|
13
11
|
PeertransferChat.configure do |c|
|
14
|
-
c.team = team_name
|
15
|
-
c.incoming_token = team_token
|
16
12
|
c.channel = team_channel
|
17
13
|
c.username = team_username
|
14
|
+
c.api_token = api_token
|
18
15
|
end
|
19
16
|
|
20
|
-
allow(
|
21
|
-
with(
|
17
|
+
allow(Slack::Web::Client).to receive(:new).
|
18
|
+
with(token: api_token).
|
22
19
|
and_return(slack_client)
|
23
20
|
end
|
24
21
|
|
25
|
-
describe '.
|
22
|
+
describe '.speak' do
|
26
23
|
it 'speaks something to a channel' do
|
27
24
|
described_class.speak('hello')
|
28
25
|
|
29
|
-
expect(slack_client).to have_received(:
|
26
|
+
expect(slack_client).to have_received(:chat_postMessage).
|
27
|
+
with(channel: team_channel, text: 'hello', as_user: true, username: team_username)
|
30
28
|
|
31
29
|
PeertransferChat.reset!
|
32
30
|
end
|
@@ -35,25 +33,25 @@ describe PeertransferChat::Client do
|
|
35
33
|
|
36
34
|
context 'with instance configuration' do
|
37
35
|
before do
|
38
|
-
allow(
|
39
|
-
with(
|
36
|
+
allow(Slack::Web::Client).to receive(:new).
|
37
|
+
with(token: api_token).
|
40
38
|
and_return(slack_client)
|
41
39
|
end
|
42
40
|
|
43
41
|
let(:client) do
|
44
42
|
PeertransferChat::Client.new do |c|
|
45
|
-
c.
|
46
|
-
c.incoming_token = team_token
|
43
|
+
c.api_token = api_token
|
47
44
|
c.channel = team_channel
|
48
45
|
c.username = team_username
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
52
|
-
describe '.
|
49
|
+
describe '.speak' do
|
53
50
|
it 'speaks something to a channel' do
|
54
51
|
client.speak('hello')
|
55
52
|
|
56
|
-
expect(slack_client).to have_received(:
|
53
|
+
expect(slack_client).to have_received(:chat_postMessage).
|
54
|
+
with(channel: team_channel, text: 'hello', as_user: true, username: team_username)
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
data/spec/lib/client_spec.rb
CHANGED
@@ -1,49 +1,59 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe PeertransferChat::Client do
|
4
|
-
let(:slack_client) {
|
5
|
-
let(:team_name) { 'a team' }
|
6
|
-
let(:team_token) { 'a token' }
|
4
|
+
let(:slack_client) { instance_spy(Slack::Web::Client) }
|
7
5
|
let(:api_token) { 'an api token' }
|
8
6
|
let(:team_channel) { 'a channel' }
|
9
7
|
let(:team_username) { 'a username' }
|
10
|
-
let(:opts) { { 'channel' => team_channel, 'username' => team_username } }
|
11
8
|
|
12
9
|
before do
|
13
10
|
allow(PeertransferChat).to receive(:config).and_return(
|
14
11
|
double(
|
15
12
|
PeertransferChat::Config,
|
16
|
-
team: team_name,
|
17
|
-
incoming_token: team_token,
|
18
13
|
channel: team_channel,
|
19
14
|
username: team_username,
|
20
|
-
channel_id: 'C026VKGP7',
|
21
15
|
api_token: api_token
|
22
16
|
)
|
23
17
|
)
|
24
18
|
end
|
25
19
|
|
26
20
|
describe '.upload' do
|
21
|
+
let(:filename) { '/foo/bar.bin' }
|
22
|
+
|
27
23
|
it 'uploads image to a channel' do
|
28
|
-
allow(
|
29
|
-
with(
|
24
|
+
allow(Slack::Web::Client).to receive(:new).
|
25
|
+
with(token: api_token).
|
30
26
|
and_return(slack_client)
|
31
27
|
|
32
|
-
|
28
|
+
file_io = instance_double(Faraday::UploadIO)
|
29
|
+
|
30
|
+
allow(Faraday::UploadIO).to receive(:new).with(filename, 'image/png').
|
31
|
+
and_return(file_io)
|
32
|
+
|
33
|
+
described_class.upload(filename)
|
34
|
+
|
35
|
+
expect(slack_client).to have_received(:files_upload). with(
|
36
|
+
channels: team_channel,
|
37
|
+
as_user: true,
|
38
|
+
file: file_io,
|
39
|
+
title: 'output.txt',
|
40
|
+
filename: filename,
|
41
|
+
initial_comment: 'Attachment'
|
42
|
+
)
|
33
43
|
|
34
|
-
described_class.upload('/foo/bar.bin')
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
38
|
-
describe '.
|
47
|
+
describe '.speak' do
|
39
48
|
it 'speaks something to a channel' do
|
40
|
-
allow(
|
41
|
-
with(
|
49
|
+
allow(Slack::Web::Client).to receive(:new).
|
50
|
+
with(token: api_token).
|
42
51
|
and_return(slack_client)
|
43
52
|
|
44
|
-
expect(slack_client).to receive(:say).with('hello')
|
45
|
-
|
46
53
|
described_class.speak('hello')
|
54
|
+
|
55
|
+
expect(slack_client).to have_received(:chat_postMessage).
|
56
|
+
with(channel: team_channel, text: 'hello', as_user: true, username: team_username)
|
47
57
|
end
|
48
58
|
end
|
49
59
|
end
|
data/spec/lib/config_spec.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe PeertransferChat::Config do
|
4
|
-
let(:
|
5
|
-
let(:team_token) { 'a token' }
|
4
|
+
let(:api_token) { 'a token' }
|
6
5
|
let(:team_channel) { 'a channel' }
|
7
6
|
let(:team_username) { 'a username' }
|
8
7
|
|
9
8
|
context 'when configured' do
|
10
9
|
before do
|
11
10
|
PeertransferChat.configure do |config|
|
12
|
-
config.
|
13
|
-
config.incoming_token = team_token
|
11
|
+
config.api_token = api_token
|
14
12
|
config.channel = team_channel
|
15
13
|
config.username = team_username
|
16
14
|
end
|
@@ -27,15 +25,14 @@ describe PeertransferChat::Config do
|
|
27
25
|
end
|
28
26
|
|
29
27
|
it 'stores config' do
|
30
|
-
expect(PeertransferChat.config.
|
28
|
+
expect(PeertransferChat.config.api_token).to eq(api_token)
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
32
|
context 'not configured' do
|
35
33
|
before do
|
36
34
|
PeertransferChat.configure do |config|
|
37
|
-
config.
|
38
|
-
config.incoming_token = team_token
|
35
|
+
config.api_token = api_token
|
39
36
|
config.channel = team_channel
|
40
37
|
end
|
41
38
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,45 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peertransfer_chat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Flywire Engineering
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.6
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.6
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
14
|
+
name: slack-ruby-client
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
19
|
+
version: '0.14'
|
20
|
+
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
26
|
+
version: '0.14'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
28
|
+
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - ">="
|
@@ -56,19 +42,19 @@ dependencies:
|
|
56
42
|
name: coveralls
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
47
|
+
version: '0.8'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
54
|
+
version: '0.8'
|
69
55
|
description: A common interface to our chat system
|
70
56
|
email:
|
71
|
-
-
|
57
|
+
- engineering@flywire.com
|
72
58
|
executables: []
|
73
59
|
extensions: []
|
74
60
|
extra_rdoc_files: []
|
@@ -85,10 +71,10 @@ files:
|
|
85
71
|
- spec/lib/client_spec.rb
|
86
72
|
- spec/lib/config_spec.rb
|
87
73
|
- spec/spec_helper.rb
|
88
|
-
homepage:
|
74
|
+
homepage:
|
89
75
|
licenses: []
|
90
76
|
metadata: {}
|
91
|
-
post_install_message:
|
77
|
+
post_install_message:
|
92
78
|
rdoc_options: []
|
93
79
|
require_paths:
|
94
80
|
- lib
|
@@ -103,9 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
89
|
- !ruby/object:Gem::Version
|
104
90
|
version: '0'
|
105
91
|
requirements: []
|
106
|
-
|
107
|
-
|
108
|
-
signing_key:
|
92
|
+
rubygems_version: 3.0.3
|
93
|
+
signing_key:
|
109
94
|
specification_version: 4
|
110
95
|
summary: A common interface to our chat system
|
111
96
|
test_files:
|