slack-ruby-client 0.1.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 +7 -0
- data/.gitignore +4 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +34 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +139 -0
- data/Gemfile +3 -0
- data/LICENSE.md +22 -0
- data/README.md +123 -0
- data/RELEASING.md +67 -0
- data/Rakefile +19 -0
- data/examples/hi_real_time/Gemfile +3 -0
- data/examples/hi_real_time/hi.gif +0 -0
- data/examples/hi_real_time/hi.rb +27 -0
- data/examples/hi_real_time_and_web/Gemfile +3 -0
- data/examples/hi_real_time_and_web/hi.gif +0 -0
- data/examples/hi_real_time_and_web/hi.rb +24 -0
- data/examples/hi_web/Gemfile +3 -0
- data/examples/hi_web/hi.gif +0 -0
- data/examples/hi_web/hi.rb +14 -0
- data/lib/slack-ruby-client.rb +23 -0
- data/lib/slack.rb +1 -0
- data/lib/slack/config.rb +17 -0
- data/lib/slack/real_time/api/message.rb +20 -0
- data/lib/slack/real_time/api/message_id.rb +14 -0
- data/lib/slack/real_time/api/ping.rb +16 -0
- data/lib/slack/real_time/api/typing.rb +17 -0
- data/lib/slack/real_time/client.rb +91 -0
- data/lib/slack/real_time/socket.rb +41 -0
- data/lib/slack/version.rb +3 -0
- data/lib/slack/web/api/endpoints.rb +39 -0
- data/lib/slack/web/api/endpoints/api.rb +25 -0
- data/lib/slack/web/api/endpoints/auth.rb +21 -0
- data/lib/slack/web/api/endpoints/channels.rb +216 -0
- data/lib/slack/web/api/endpoints/chat.rb +78 -0
- data/lib/slack/web/api/endpoints/emoji.rb +21 -0
- data/lib/slack/web/api/endpoints/files.rb +76 -0
- data/lib/slack/web/api/endpoints/groups.rb +229 -0
- data/lib/slack/web/api/endpoints/im.rb +82 -0
- data/lib/slack/web/api/endpoints/oauth.rb +32 -0
- data/lib/slack/web/api/endpoints/presence.rb +24 -0
- data/lib/slack/web/api/endpoints/rtm.rb +21 -0
- data/lib/slack/web/api/endpoints/search.rb +68 -0
- data/lib/slack/web/api/endpoints/stars.rb +23 -0
- data/lib/slack/web/api/endpoints/users.rb +70 -0
- data/lib/slack/web/api/error.rb +8 -0
- data/lib/slack/web/api/schema/method.json +45 -0
- data/lib/slack/web/api/tasks/generate.rake +37 -0
- data/lib/slack/web/api/templates/endpoints.erb +17 -0
- data/lib/slack/web/api/templates/method.erb +39 -0
- data/lib/slack/web/client.rb +17 -0
- data/lib/slack/web/config.rb +36 -0
- data/lib/slack/web/faraday/connection.rb +25 -0
- data/lib/slack/web/faraday/request.rb +39 -0
- data/lib/slack/web/faraday/response/raise_error.rb +14 -0
- data/lib/slack_ruby_client.rb +1 -0
- data/screenshots/register-bot.png +0 -0
- data/slack-ruby-client.gemspec +28 -0
- data/spec/fixtures/slack/web/auth_test_error.yml +48 -0
- data/spec/fixtures/slack/web/auth_test_success.yml +57 -0
- data/spec/fixtures/slack/web/rtm_start.yml +73 -0
- data/spec/slack/config_spec.rb +14 -0
- data/spec/slack/real_time/api/message_spec.rb +15 -0
- data/spec/slack/real_time/api/ping_spec.rb +15 -0
- data/spec/slack/real_time/api/typing_spec.rb +15 -0
- data/spec/slack/real_time/client_spec.rb +51 -0
- data/spec/slack/real_time/socket_spec.rb +42 -0
- data/spec/slack/version_spec.rb +7 -0
- data/spec/slack/web/api/endpoints/auth_spec.rb +15 -0
- data/spec/slack/web/client_spec.rb +31 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/real_time/connected_client.rb +13 -0
- data/spec/support/vcr.rb +8 -0
- metadata +287 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bfc38c6f34626b363ad4323f0fab5a791e77ca3b
|
4
|
+
data.tar.gz: dc37a02ec0492a1191f7fe1f495b704be45e344d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b37c6b2289f5337239d52b199cbf0b224f1a7d8f4c510de22295ca2686f04f15aab992eead738cc69799e63230accdea1636ca9e3e2d9e9723f9ee3985f7e2c
|
7
|
+
data.tar.gz: 5441b5ebb561df58e6233b7444f154f76bd6227b7657c4d402eb444ca709954315e771dbfc99683e481a606b3897f4a14f41bc3e91f79d81380dcee61b03086d
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-07-25 14:51:14 -0400 using RuboCop version 0.32.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 77
|
9
|
+
# Configuration parameters: AllowURI, URISchemes.
|
10
|
+
Metrics/LineLength:
|
11
|
+
Max: 153
|
12
|
+
|
13
|
+
# Offense count: 3
|
14
|
+
# Configuration parameters: CountComments.
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Max: 16
|
17
|
+
|
18
|
+
# Offense count: 26
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
# Offense count: 1
|
23
|
+
# Configuration parameters: Exclude.
|
24
|
+
Style/FileName:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
# Offense count: 9
|
28
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
29
|
+
Style/MethodName:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
# Offense count: 2
|
33
|
+
Style/ModuleFunction:
|
34
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
# Contributing to Slack
|
2
|
+
|
3
|
+
This project is work of [many contributors](https://github.com/dblock/slack-ruby-client/graphs/contributors).
|
4
|
+
|
5
|
+
You're encouraged to submit [pull requests](https://github.com/dblock/slack-ruby-client/pulls), [propose features and discuss issues](https://github.com/dblock/slack-ruby-client/issues).
|
6
|
+
|
7
|
+
In the examples below, substitute your Github username for `contributor` in URLs.
|
8
|
+
|
9
|
+
## Fork the Project
|
10
|
+
|
11
|
+
Fork the [project on Github](https://github.com/dblock/slack-ruby-client) and check out your copy.
|
12
|
+
|
13
|
+
```
|
14
|
+
git clone https://github.com/contributor/slack-ruby-client.git
|
15
|
+
cd slack-ruby-client
|
16
|
+
git remote add upstream https://github.com/dblock/slack-ruby-client.git
|
17
|
+
```
|
18
|
+
|
19
|
+
## Bundle Install and Test
|
20
|
+
|
21
|
+
Ensure that you can build the project and run tests.
|
22
|
+
|
23
|
+
```
|
24
|
+
bundle install
|
25
|
+
bundle exec rake
|
26
|
+
```
|
27
|
+
|
28
|
+
## Run Slack in Development
|
29
|
+
|
30
|
+
Create a private slack group for yourself.
|
31
|
+
|
32
|
+
Create a new Bot Integration under [services/new/bot](http://slack.com/services/new/bot).
|
33
|
+
|
34
|
+

|
35
|
+
|
36
|
+
On the next screen, note the API token.
|
37
|
+
|
38
|
+
Run `SLACK_API_TOKEN=<your API token> foreman start`.
|
39
|
+
|
40
|
+
You can also create a `.env` file with `SLACK_API_TOKEN=<your API token>` and just run `foreman start`.
|
41
|
+
|
42
|
+
## Create a Topic Branch
|
43
|
+
|
44
|
+
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
45
|
+
|
46
|
+
```
|
47
|
+
git checkout master
|
48
|
+
git pull upstream master
|
49
|
+
git checkout -b my-feature-branch
|
50
|
+
```
|
51
|
+
|
52
|
+
## Write Tests
|
53
|
+
|
54
|
+
Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build.
|
55
|
+
Add to [spec](spec).
|
56
|
+
|
57
|
+
We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
|
58
|
+
|
59
|
+
## Write Code
|
60
|
+
|
61
|
+
Implement your feature or bug fix.
|
62
|
+
|
63
|
+
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop).
|
64
|
+
Run `bundle exec rubocop` and fix any style issues highlighted.
|
65
|
+
|
66
|
+
Make sure that `bundle exec rake` completes without errors.
|
67
|
+
|
68
|
+
## Write Documentation
|
69
|
+
|
70
|
+
Document any external behavior in the [README](README.md).
|
71
|
+
|
72
|
+
## Update Changelog
|
73
|
+
|
74
|
+
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*.
|
75
|
+
Make it look like every other line, including your name and link to your Github account.
|
76
|
+
|
77
|
+
## Commit Changes
|
78
|
+
|
79
|
+
Make sure git knows your name and email address:
|
80
|
+
|
81
|
+
```
|
82
|
+
git config --global user.name "Your Name"
|
83
|
+
git config --global user.email "contributor@example.com"
|
84
|
+
```
|
85
|
+
|
86
|
+
Writing good commit logs is important. A commit log should describe what changed and why.
|
87
|
+
|
88
|
+
```
|
89
|
+
git add ...
|
90
|
+
git commit
|
91
|
+
```
|
92
|
+
|
93
|
+
## Push
|
94
|
+
|
95
|
+
```
|
96
|
+
git push origin my-feature-branch
|
97
|
+
```
|
98
|
+
|
99
|
+
## Make a Pull Request
|
100
|
+
|
101
|
+
Go to https://github.com/contributor/slack-ruby-client and select your feature branch.
|
102
|
+
Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
103
|
+
|
104
|
+
## Rebase
|
105
|
+
|
106
|
+
If you've been working on a change for a while, rebase with upstream/master.
|
107
|
+
|
108
|
+
```
|
109
|
+
git fetch upstream
|
110
|
+
git rebase upstream/master
|
111
|
+
git push origin my-feature-branch -f
|
112
|
+
```
|
113
|
+
|
114
|
+
## Update CHANGELOG Again
|
115
|
+
|
116
|
+
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
117
|
+
|
118
|
+
```
|
119
|
+
* [#123](https://github.com/dblock/slack-ruby-client/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
120
|
+
```
|
121
|
+
|
122
|
+
Amend your previous commit and force push the changes.
|
123
|
+
|
124
|
+
```
|
125
|
+
git commit --amend
|
126
|
+
git push origin my-feature-branch -f
|
127
|
+
```
|
128
|
+
|
129
|
+
## Check on Your Pull Request
|
130
|
+
|
131
|
+
Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
|
132
|
+
|
133
|
+
## Be Patient
|
134
|
+
|
135
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
|
136
|
+
|
137
|
+
## Thank You
|
138
|
+
|
139
|
+
Please do know that we really appreciate and value your time and work. We love you, really.
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2015 Daniel Doubrovkine, Artsy and Contributors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
Slack Ruby Client
|
2
|
+
=================
|
3
|
+
|
4
|
+
[](http://badge.fury.io/rb/slack-ruby-client)
|
5
|
+
[](https://travis-ci.org/dblock/slack-ruby-client)
|
6
|
+
|
7
|
+
A Ruby client for the Slack [Web](https://api.slack.com/web) and [RealTime Messaging](https://api.slack.com/rtm) APIs.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add to Gemfile.
|
12
|
+
|
13
|
+
```
|
14
|
+
gem 'slack-ruby-client'
|
15
|
+
```
|
16
|
+
|
17
|
+
Run `bundle install`.
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Create a New Bot Integration
|
22
|
+
|
23
|
+
This is something done in Slack, under [integrations](https://artsy.slack.com/services). Create a [new bot](https://artsy.slack.com/services/new/bot), and note its API token.
|
24
|
+
|
25
|
+

|
26
|
+
|
27
|
+
### Use the API Token
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Slack.configure do |config|
|
31
|
+
config.token = ENV['SLACK_API_TOKEN']
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
### Web Client
|
36
|
+
|
37
|
+
The Slack Web API allows you to build applications that interact with Slack. For example, send messages with [chat_PostMessage](https://api.slack.com/methods/chat.postMessage).
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
client = Slack::Web::Client.new
|
41
|
+
|
42
|
+
client.auth_test
|
43
|
+
|
44
|
+
general_channel = client.channels_list['channels'].detect { |c| c['name'] == 't3' }
|
45
|
+
|
46
|
+
client.chat_postMessage(channel: general_channel['id'], text: 'Hello World', as_user: true)
|
47
|
+
```
|
48
|
+
|
49
|
+
See a fully working example in [examples/hi_web](examples/hi_web/hi.rb).
|
50
|
+
|
51
|
+

|
52
|
+
|
53
|
+
Refer to the [Slack Web API Method Reference](https://api.slack.com/methods) for the list of all available functions.
|
54
|
+
|
55
|
+
### RealTime Client
|
56
|
+
|
57
|
+
The Real Time Messaging API is a WebSocket-based API that allows you to receive events from Slack in real time and send messages as user.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
client = Slack::RealTime::Client.new
|
61
|
+
|
62
|
+
client.on :hello do
|
63
|
+
puts 'Successfully connected.'
|
64
|
+
end
|
65
|
+
|
66
|
+
client.on :message do |data|
|
67
|
+
case data['text']
|
68
|
+
when 'bot hi' then
|
69
|
+
client.message channel: data['channel'], text: "Hi <@#{data['user']}>!"
|
70
|
+
when /^bot/ then
|
71
|
+
client.message channel: data['channel'], text: "Sorry <@#{data['user']}>, what?"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
client.start!
|
76
|
+
```
|
77
|
+
|
78
|
+
You can also send typing indicators.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
client.typing channel: data['channel']
|
82
|
+
```
|
83
|
+
|
84
|
+
See a fullly working example in [examples/hi_real_time](examples/hi_real_time/hi.rb).
|
85
|
+
|
86
|
+

|
87
|
+
|
88
|
+
### Combinging RealTime and Web Clients
|
89
|
+
|
90
|
+
Since the web client is used to obtain the RealTime client's WebSocket URL, you can continue using the web client in combination with the RealTime client.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
client = Slack::RealTime::Client.new
|
94
|
+
|
95
|
+
client.on :message do |data|
|
96
|
+
case data['text']
|
97
|
+
when 'bot hi' then
|
98
|
+
client.web_client.chat_postMessage channel: data['channel'], text: "Hi <@#{data['user']}>!"
|
99
|
+
when /^bot/ then
|
100
|
+
client.web_client.chat_postMessage channel: data['channel'], text: "Sorry <@#{data['user']}>, what?"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
client.start!
|
105
|
+
```
|
106
|
+
|
107
|
+
See a fullly working example in [examples/hi_real_time_and_web](examples/hi_real_time_and_web/hi.rb).
|
108
|
+
|
109
|
+

|
110
|
+
|
111
|
+
## History
|
112
|
+
|
113
|
+
This gem is based on [slack-ruby-gem](https://github.com/aki017/slack-ruby-gem), but it more clearly separates the Web and RTM APIs, is more thoroughly tested and is in active development.
|
114
|
+
|
115
|
+
## Contributing
|
116
|
+
|
117
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
118
|
+
|
119
|
+
## Copyright and License
|
120
|
+
|
121
|
+
Copyright (c) 2015, Daniel Doubrovkine, Artsy and [Contributors](CHANGELOG.md).
|
122
|
+
|
123
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
data/RELEASING.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Releasing SlackRubyClient
|
2
|
+
|
3
|
+
There're no particular rules about when to release slack-ruby-client. Release bug fixes frequenty, features not so frequently and breaking API changes rarely.
|
4
|
+
|
5
|
+
### Release
|
6
|
+
|
7
|
+
Run tests, check that all tests succeed locally.
|
8
|
+
|
9
|
+
```
|
10
|
+
bundle install
|
11
|
+
rake
|
12
|
+
```
|
13
|
+
|
14
|
+
Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/slack-ruby-client) for all supported platforms.
|
15
|
+
|
16
|
+
Increment the version, modify [lib/slack/version.rb](lib/slack/version.rb).
|
17
|
+
|
18
|
+
* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.2.1` to `0.2.2`).
|
19
|
+
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.2.1` to `0.3.0`).
|
20
|
+
|
21
|
+
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
22
|
+
|
23
|
+
```
|
24
|
+
### 0.2.2 (7/10/2015)
|
25
|
+
```
|
26
|
+
|
27
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
28
|
+
|
29
|
+
Commit your changes.
|
30
|
+
|
31
|
+
```
|
32
|
+
git add CHANGELOG.md lib/slack/version.rb
|
33
|
+
git commit -m "Preparing for release, 0.2.2."
|
34
|
+
git push origin master
|
35
|
+
```
|
36
|
+
|
37
|
+
Release.
|
38
|
+
|
39
|
+
```
|
40
|
+
$ rake release
|
41
|
+
|
42
|
+
slack-ruby-client 0.2.2 built to pkg/slack-ruby-client-0.2.2.gem.
|
43
|
+
Tagged v0.2.2.
|
44
|
+
Pushed git commits and tags.
|
45
|
+
Pushed slack-ruby-client 0.2.2 to rubygems.org.
|
46
|
+
```
|
47
|
+
|
48
|
+
### Prepare for the Next Version
|
49
|
+
|
50
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
51
|
+
|
52
|
+
```
|
53
|
+
Next Release
|
54
|
+
============
|
55
|
+
|
56
|
+
* Your contribution here.
|
57
|
+
```
|
58
|
+
|
59
|
+
Increment the third version number in [lib/slack/version.rb](lib/slack/version.rb).
|
60
|
+
|
61
|
+
Comit your changes.
|
62
|
+
|
63
|
+
```
|
64
|
+
git add CHANGELOG.md lib/slack/version.rb
|
65
|
+
git commit -m "Preparing for next development iteration, 0.2.3."
|
66
|
+
git push origin master
|
67
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
Bundler.setup :default, :development
|
6
|
+
|
7
|
+
require 'rspec/core'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
11
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rubocop/rake_task'
|
15
|
+
RuboCop::RakeTask.new
|
16
|
+
|
17
|
+
task default: [:rubocop, :spec]
|
18
|
+
|
19
|
+
load 'slack/web/api/tasks/generate.rake'
|