slack-ruby-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +6 -0
  6. data/.rubocop_todo.yml +34 -0
  7. data/.travis.yml +6 -0
  8. data/CHANGELOG.md +4 -0
  9. data/CONTRIBUTING.md +139 -0
  10. data/Gemfile +3 -0
  11. data/LICENSE.md +22 -0
  12. data/README.md +123 -0
  13. data/RELEASING.md +67 -0
  14. data/Rakefile +19 -0
  15. data/examples/hi_real_time/Gemfile +3 -0
  16. data/examples/hi_real_time/hi.gif +0 -0
  17. data/examples/hi_real_time/hi.rb +27 -0
  18. data/examples/hi_real_time_and_web/Gemfile +3 -0
  19. data/examples/hi_real_time_and_web/hi.gif +0 -0
  20. data/examples/hi_real_time_and_web/hi.rb +24 -0
  21. data/examples/hi_web/Gemfile +3 -0
  22. data/examples/hi_web/hi.gif +0 -0
  23. data/examples/hi_web/hi.rb +14 -0
  24. data/lib/slack-ruby-client.rb +23 -0
  25. data/lib/slack.rb +1 -0
  26. data/lib/slack/config.rb +17 -0
  27. data/lib/slack/real_time/api/message.rb +20 -0
  28. data/lib/slack/real_time/api/message_id.rb +14 -0
  29. data/lib/slack/real_time/api/ping.rb +16 -0
  30. data/lib/slack/real_time/api/typing.rb +17 -0
  31. data/lib/slack/real_time/client.rb +91 -0
  32. data/lib/slack/real_time/socket.rb +41 -0
  33. data/lib/slack/version.rb +3 -0
  34. data/lib/slack/web/api/endpoints.rb +39 -0
  35. data/lib/slack/web/api/endpoints/api.rb +25 -0
  36. data/lib/slack/web/api/endpoints/auth.rb +21 -0
  37. data/lib/slack/web/api/endpoints/channels.rb +216 -0
  38. data/lib/slack/web/api/endpoints/chat.rb +78 -0
  39. data/lib/slack/web/api/endpoints/emoji.rb +21 -0
  40. data/lib/slack/web/api/endpoints/files.rb +76 -0
  41. data/lib/slack/web/api/endpoints/groups.rb +229 -0
  42. data/lib/slack/web/api/endpoints/im.rb +82 -0
  43. data/lib/slack/web/api/endpoints/oauth.rb +32 -0
  44. data/lib/slack/web/api/endpoints/presence.rb +24 -0
  45. data/lib/slack/web/api/endpoints/rtm.rb +21 -0
  46. data/lib/slack/web/api/endpoints/search.rb +68 -0
  47. data/lib/slack/web/api/endpoints/stars.rb +23 -0
  48. data/lib/slack/web/api/endpoints/users.rb +70 -0
  49. data/lib/slack/web/api/error.rb +8 -0
  50. data/lib/slack/web/api/schema/method.json +45 -0
  51. data/lib/slack/web/api/tasks/generate.rake +37 -0
  52. data/lib/slack/web/api/templates/endpoints.erb +17 -0
  53. data/lib/slack/web/api/templates/method.erb +39 -0
  54. data/lib/slack/web/client.rb +17 -0
  55. data/lib/slack/web/config.rb +36 -0
  56. data/lib/slack/web/faraday/connection.rb +25 -0
  57. data/lib/slack/web/faraday/request.rb +39 -0
  58. data/lib/slack/web/faraday/response/raise_error.rb +14 -0
  59. data/lib/slack_ruby_client.rb +1 -0
  60. data/screenshots/register-bot.png +0 -0
  61. data/slack-ruby-client.gemspec +28 -0
  62. data/spec/fixtures/slack/web/auth_test_error.yml +48 -0
  63. data/spec/fixtures/slack/web/auth_test_success.yml +57 -0
  64. data/spec/fixtures/slack/web/rtm_start.yml +73 -0
  65. data/spec/slack/config_spec.rb +14 -0
  66. data/spec/slack/real_time/api/message_spec.rb +15 -0
  67. data/spec/slack/real_time/api/ping_spec.rb +15 -0
  68. data/spec/slack/real_time/api/typing_spec.rb +15 -0
  69. data/spec/slack/real_time/client_spec.rb +51 -0
  70. data/spec/slack/real_time/socket_spec.rb +42 -0
  71. data/spec/slack/version_spec.rb +7 -0
  72. data/spec/slack/web/api/endpoints/auth_spec.rb +15 -0
  73. data/spec/slack/web/client_spec.rb +31 -0
  74. data/spec/spec_helper.rb +14 -0
  75. data/spec/support/real_time/connected_client.rb +13 -0
  76. data/spec/support/vcr.rb +8 -0
  77. metadata +287 -0
@@ -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
@@ -0,0 +1,4 @@
1
+ .env
2
+ pkg
3
+ Gemfile.lock
4
+ .DS_Store
@@ -0,0 +1,3 @@
1
+ [submodule "lib/slack/web/api/slack-api-docs"]
2
+ path = lib/slack/web/api/slack-api-docs
3
+ url = git@github.com:slackhq/slack-api-docs.git
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/**/*
4
+ - bin/**/*
5
+
6
+ inherit_from: .rubocop_todo.yml
@@ -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
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 2.2
3
+
4
+ git:
5
+ submodules: false
6
+
@@ -0,0 +1,4 @@
1
+ ### 0.1.0 (7/25/2015)
2
+
3
+ * Initial public release with Web and RealTime Messaging API support - [@dblock](https://github.com/dblock).
4
+
@@ -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
+ ![](screenshots/register-bot.png)
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
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -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.
@@ -0,0 +1,123 @@
1
+ Slack Ruby Client
2
+ =================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/slack-ruby-client.svg)](http://badge.fury.io/rb/slack-ruby-client)
5
+ [![Build Status](https://travis-ci.org/dblock/slack-ruby-client.png)](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
+ ![](screenshots/register-bot.png)
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
+ ![](examples/hi_web/hi.gif)
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
+ ![](examples/hi_real_time/hi.gif)
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
+ ![](examples/hi_real_time_and_web/hi.gif)
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).
@@ -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
+ ```
@@ -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'