peertransfer_chat 0.2.1 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5bbdac3d964c554f5b08d7820a9e9ee13a0b3587
4
- data.tar.gz: 0432d40850c197488c997af30216a80e833e0bff
2
+ SHA256:
3
+ metadata.gz: 9c28b8b6798c36f859bf9fa63d12fcfb372ad3c5d2bf8bbfaad56283687fdf22
4
+ data.tar.gz: a8660d1c881f00574c989093cbd9785b546ba338d3af408863c04d975f327d0b
5
5
  SHA512:
6
- metadata.gz: 184a0c1249dc3bd4ba6c97a681bf53c486933ed47a9c58ea5f341f0ab44108ce532ee54d669ee76d52f0da1c7301059cca1fe070b1ae619d9b435ba7913637f9
7
- data.tar.gz: 3794ea9a639eecefcd1502659802c2373500e660daf3822c71c6eec0725493ee04ac3df074b84381f0be231cc192b21d13be585a0af0f5d37588d3db71d76328
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.team = team_name
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 'slackr'
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
- slack = Slackr.connect(team, api_token, slack_opts)
24
- slack.upload(filename, { 'channels' => channel_id}.merge(opts))
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
- slack = Slackr.connect(team, incoming_token, slack_opts)
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 team
35
- config.team
39
+ def client
40
+ @client ||= Slack::Web::Client.new(token: api_token)
36
41
  end
37
42
 
38
- def incoming_token
39
- config.incoming_token
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 channel_id
47
- config.channel_id
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 = [:team, :channel, :incoming_token, :username, :api_token, :channel_id]
3
+ SETTINGS = [:channel, :username, :api_token]
4
4
 
5
5
  attr_accessor(*SETTINGS)
6
6
 
7
7
  def valid?
8
- @team && @channel && @incoming_token && @username
8
+ @api_token && @channel && @username
9
9
  end
10
10
  end
11
11
 
@@ -1,3 +1,3 @@
1
1
  class PeertransferChat
2
- VERSION = "0.2.1"
2
+ VERSION = '1.0.0'
3
3
  end
@@ -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 = ['peerTransfer tech']
10
- spec.email = ['tech@peertransfer.com']
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 'slackr', '0.0.6'
22
+ spec.add_runtime_dependency 'slack-ruby-client', '~> 0.14'
23
23
 
24
- spec.add_development_dependency 'bundler', '~> 1.6'
25
- spec.add_development_dependency 'simplecov'
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(Slackr) }
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(:opts) { { 'channel' => team_channel, 'username' => team_username } }
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(Slackr).to receive(:connect).
21
- with(team_name, team_token, opts).
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 '.say' do
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(:say).with('hello')
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(Slackr).to receive(:connect).
39
- with(team_name, team_token, opts).
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.team = team_name
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 '.say' do
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(:say).with('hello')
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
@@ -1,49 +1,59 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PeertransferChat::Client do
4
- let(:slack_client) { instance_double(Slackr) }
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(Slackr).to receive(:connect).
29
- with(team_name, api_token, opts).
24
+ allow(Slack::Web::Client).to receive(:new).
25
+ with(token: api_token).
30
26
  and_return(slack_client)
31
27
 
32
- expect(slack_client).to receive(:upload).with('/foo/bar.bin', { 'channels' => 'C026VKGP7' })
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 '.say' do
47
+ describe '.speak' do
39
48
  it 'speaks something to a channel' do
40
- allow(Slackr).to receive(:connect).
41
- with(team_name, team_token, opts).
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
@@ -1,16 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PeertransferChat::Config do
4
- let(:team_name) { 'a team' }
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.team = team_name
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.team).to eq('a team')
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.team = team_name
38
- config.incoming_token = team_token
35
+ config.api_token = api_token
39
36
  config.channel = team_channel
40
37
  end
41
38
  end
@@ -1,9 +1,5 @@
1
- require 'simplecov'
2
1
  require 'coveralls'
3
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
4
- SimpleCov.start do
5
- add_filter '/spec/'
6
- add_filter '/vendor/'
7
- end
2
+
3
+ Coveralls.wear!
8
4
 
9
5
  require 'peertransfer_chat'
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.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - peerTransfer tech
8
- autorequire:
7
+ - Flywire Engineering
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-27 00:00:00.000000000 Z
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: slackr
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: '1.6'
34
- type: :development
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: '1.6'
26
+ version: '0.14'
41
27
  - !ruby/object:Gem::Dependency
42
- name: simplecov
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
- - tech@peertransfer.com
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
- rubyforge_project:
107
- rubygems_version: 2.6.14.1
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: