slack-ruby-client-bhe 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +17 -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 +78 -0
  7. data/.travis.yml +26 -0
  8. data/CHANGELOG.md +79 -0
  9. data/CONTRIBUTING.md +157 -0
  10. data/Gemfile +5 -0
  11. data/LICENSE.md +22 -0
  12. data/README.md +385 -0
  13. data/RELEASING.md +69 -0
  14. data/Rakefile +19 -0
  15. data/UPGRADING.md +26 -0
  16. data/bin/commands.rb +21 -0
  17. data/bin/commands/api.rb +14 -0
  18. data/bin/commands/auth.rb +12 -0
  19. data/bin/commands/channels.rb +149 -0
  20. data/bin/commands/chat.rb +47 -0
  21. data/bin/commands/dnd.rb +47 -0
  22. data/bin/commands/emoji.rb +12 -0
  23. data/bin/commands/files.rb +72 -0
  24. data/bin/commands/groups.rb +167 -0
  25. data/bin/commands/im.rb +53 -0
  26. data/bin/commands/mpim.rb +53 -0
  27. data/bin/commands/oauth.rb +16 -0
  28. data/bin/commands/pins.rb +37 -0
  29. data/bin/commands/reactions.rb +53 -0
  30. data/bin/commands/rtm.rb +15 -0
  31. data/bin/commands/search.rb +40 -0
  32. data/bin/commands/stars.rb +37 -0
  33. data/bin/commands/team.rb +32 -0
  34. data/bin/commands/usergroups.rb +73 -0
  35. data/bin/commands/users.rb +57 -0
  36. data/bin/slack +50 -0
  37. data/examples/hi_real_time/Gemfile +5 -0
  38. data/examples/hi_real_time/hi.gif +0 -0
  39. data/examples/hi_real_time/hi.rb +32 -0
  40. data/examples/hi_real_time_and_web/Gemfile +5 -0
  41. data/examples/hi_real_time_and_web/hi.gif +0 -0
  42. data/examples/hi_real_time_and_web/hi.rb +24 -0
  43. data/examples/hi_real_time_async/Gemfile +5 -0
  44. data/examples/hi_real_time_async/hi.rb +29 -0
  45. data/examples/hi_web/Gemfile +3 -0
  46. data/examples/hi_web/hi.gif +0 -0
  47. data/examples/hi_web/hi.rb +12 -0
  48. data/examples/new_ticket/Gemfile +3 -0
  49. data/examples/new_ticket/new_ticket.rb +25 -0
  50. data/lib/slack-ruby-client.rb +29 -0
  51. data/lib/slack.rb +1 -0
  52. data/lib/slack/config.rb +21 -0
  53. data/lib/slack/messages/formatting.rb +30 -0
  54. data/lib/slack/real_time/api/message.rb +20 -0
  55. data/lib/slack/real_time/api/message_id.rb +14 -0
  56. data/lib/slack/real_time/api/ping.rb +16 -0
  57. data/lib/slack/real_time/api/typing.rb +17 -0
  58. data/lib/slack/real_time/client.rb +152 -0
  59. data/lib/slack/real_time/concurrency.rb +8 -0
  60. data/lib/slack/real_time/concurrency/celluloid.rb +93 -0
  61. data/lib/slack/real_time/concurrency/eventmachine.rb +39 -0
  62. data/lib/slack/real_time/config.rb +55 -0
  63. data/lib/slack/real_time/socket.rb +81 -0
  64. data/lib/slack/version.rb +3 -0
  65. data/lib/slack/web/api/endpoints.rb +53 -0
  66. data/lib/slack/web/api/endpoints/api.rb +24 -0
  67. data/lib/slack/web/api/endpoints/auth.rb +20 -0
  68. data/lib/slack/web/api/endpoints/channels.rb +220 -0
  69. data/lib/slack/web/api/endpoints/chat.rb +91 -0
  70. data/lib/slack/web/api/endpoints/dnd.rb +64 -0
  71. data/lib/slack/web/api/endpoints/emoji.rb +20 -0
  72. data/lib/slack/web/api/endpoints/files.rb +108 -0
  73. data/lib/slack/web/api/endpoints/groups.rb +247 -0
  74. data/lib/slack/web/api/endpoints/im.rb +85 -0
  75. data/lib/slack/web/api/endpoints/mpim.rb +84 -0
  76. data/lib/slack/web/api/endpoints/oauth.rb +32 -0
  77. data/lib/slack/web/api/endpoints/pins.rb +64 -0
  78. data/lib/slack/web/api/endpoints/presence.rb +23 -0
  79. data/lib/slack/web/api/endpoints/reactions.rb +89 -0
  80. data/lib/slack/web/api/endpoints/rtm.rb +27 -0
  81. data/lib/slack/web/api/endpoints/search.rb +65 -0
  82. data/lib/slack/web/api/endpoints/stars.rb +61 -0
  83. data/lib/slack/web/api/endpoints/team.rb +47 -0
  84. data/lib/slack/web/api/endpoints/usergroups.rb +113 -0
  85. data/lib/slack/web/api/endpoints/users.rb +73 -0
  86. data/lib/slack/web/api/error.rb +14 -0
  87. data/lib/slack/web/api/mixins.rb +3 -0
  88. data/lib/slack/web/api/mixins/channels.id.json +20 -0
  89. data/lib/slack/web/api/mixins/channels.id.rb +26 -0
  90. data/lib/slack/web/api/mixins/groups.id.json +20 -0
  91. data/lib/slack/web/api/mixins/groups.id.rb +26 -0
  92. data/lib/slack/web/api/mixins/users.id.json +20 -0
  93. data/lib/slack/web/api/mixins/users.id.rb +26 -0
  94. data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +13 -0
  95. data/lib/slack/web/api/patches/chat.2.attachments-json.patch +17 -0
  96. data/lib/slack/web/api/schema/group.json +14 -0
  97. data/lib/slack/web/api/schema/method.json +45 -0
  98. data/lib/slack/web/api/tasks/generate.rake +61 -0
  99. data/lib/slack/web/api/templates/command.erb +34 -0
  100. data/lib/slack/web/api/templates/commands.erb +5 -0
  101. data/lib/slack/web/api/templates/endpoints.erb +21 -0
  102. data/lib/slack/web/api/templates/method.erb +49 -0
  103. data/lib/slack/web/client.rb +28 -0
  104. data/lib/slack/web/config.rb +41 -0
  105. data/lib/slack/web/faraday/connection.rb +29 -0
  106. data/lib/slack/web/faraday/request.rb +39 -0
  107. data/lib/slack/web/faraday/response/raise_error.rb +15 -0
  108. data/lib/slack_ruby_client.rb +1 -0
  109. data/screenshots/register-bot.png +0 -0
  110. data/slack-ruby-client.gemspec +31 -0
  111. data/slack.png +0 -0
  112. data/spec/fixtures/slack/web/429_error.yml +83 -0
  113. data/spec/fixtures/slack/web/auth_test_error.yml +48 -0
  114. data/spec/fixtures/slack/web/auth_test_success.yml +57 -0
  115. data/spec/fixtures/slack/web/channels_info.yml +46 -0
  116. data/spec/fixtures/slack/web/groups_info.yml +43 -0
  117. data/spec/fixtures/slack/web/rtm_start.yml +73 -0
  118. data/spec/fixtures/slack/web/users_info.yml +130 -0
  119. data/spec/fixtures/slack/web/users_list.yml +72 -0
  120. data/spec/integration/integration_spec.rb +107 -0
  121. data/spec/slack/config_spec.rb +14 -0
  122. data/spec/slack/messages/formatting_spec.rb +43 -0
  123. data/spec/slack/real_time/api/message_spec.rb +15 -0
  124. data/spec/slack/real_time/api/ping_spec.rb +15 -0
  125. data/spec/slack/real_time/api/typing_spec.rb +15 -0
  126. data/spec/slack/real_time/client_spec.rb +198 -0
  127. data/spec/slack/real_time/concurrency/celluloid_spec.rb +58 -0
  128. data/spec/slack/real_time/concurrency/eventmachine_spec.rb +49 -0
  129. data/spec/slack/slack_spec.rb +58 -0
  130. data/spec/slack/version_spec.rb +7 -0
  131. data/spec/slack/web/api/endpoints/auth_spec.rb +20 -0
  132. data/spec/slack/web/api/endpoints/channels_spec.rb +11 -0
  133. data/spec/slack/web/api/endpoints/chat_spec.rb +33 -0
  134. data/spec/slack/web/api/endpoints/groups_spec.rb +11 -0
  135. data/spec/slack/web/api/endpoints/users_spec.rb +17 -0
  136. data/spec/slack/web/api/error_spec.rb +14 -0
  137. data/spec/slack/web/api/mixins/channels_spec.rb +31 -0
  138. data/spec/slack/web/api/mixins/groups_spec.rb +31 -0
  139. data/spec/slack/web/api/mixins/users_spec.rb +31 -0
  140. data/spec/slack/web/client_spec.rb +134 -0
  141. data/spec/spec_helper.rb +14 -0
  142. data/spec/support/queue_with_timeout.rb +34 -0
  143. data/spec/support/real_time/concurrency/mock.rb +31 -0
  144. data/spec/support/real_time/connected_client.rb +16 -0
  145. data/spec/support/token.rb +10 -0
  146. data/spec/support/vcr.rb +8 -0
  147. metadata +392 -0
@@ -0,0 +1,17 @@
1
+ ---
2
+ !binary "U0hBMjU2":
3
+ metadata.gz: !binary |-
4
+ MzI5YTYwZDcxZDhiMjExYjgyNGExMDYxZGZlZWFmYzg4OWFkNGYwMzdjODM4
5
+ YTY3MTlhZDU5ZTc0YmMyM2ZjNA==
6
+ data.tar.gz: !binary |-
7
+ MDI2MmUwNWY4M2M0NDUyYWQ1ZmIyYTFjYjlmMTVlOTlkOWU3OTJlZTM3NTQy
8
+ YWQ1ZmM1M2E5OGVmNDZhMTYwNg==
9
+ SHA512:
10
+ metadata.gz: !binary |-
11
+ NzQyNGFjMzM4MzU5ZTllYWQ2MWU3YmY5ZGZkYmY5N2QxNWUyNTFiZDRjNWQ5
12
+ Y2ZiMDI4NTdhZjlkOGEwNjZkNDk3Zjc4ODJjNDc2OTFkM2I5MGU5YWVjMTgw
13
+ MGNmY2Y0ZTlmMTZkMDcxMDAwOWZkNjY1MmQ5Mzg4YmY1ZjkwNWY=
14
+ data.tar.gz: !binary |-
15
+ NjA5ZDgyOWFjODAxY2QxMzBiNjViMzcwNjQ1MzA0ZWMwYWU3ODFmNDllNzM4
16
+ NWI4OThmNDMyOTg4YzUyYjkyMDJmMjY3OWExOGQ4MjgwMmQxZWQ1NjdkNzI1
17
+ YTBiMmNjNWQyNjAwMTkzM2I0MWNjOGJhMjY5ODM2NTg0ODg0ZWE=
@@ -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-ref"]
2
+ path = lib/slack/web/api/slack-api-ref
3
+ url = git@github.com:dblock/slack-api-ref.git
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/**/*
4
+ - lib/slack/web/api/slack-api-ref/**/*
5
+
6
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,78 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-01-22 14:19:14 -0500 using RuboCop version 0.35.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ Lint/HandleExceptions:
11
+ Exclude:
12
+ - 'lib/slack/real_time/concurrency/celluloid.rb'
13
+ - 'spec/slack/real_time/concurrency/celluloid_spec.rb'
14
+ - 'spec/slack/real_time/concurrency/eventmachine_spec.rb'
15
+
16
+ # Offense count: 1
17
+ # Cop supports --auto-correct.
18
+ # Configuration parameters: IgnoreEmptyBlocks.
19
+ Lint/UnusedBlockArgument:
20
+ Exclude:
21
+ - 'lib/slack/messages/formatting.rb'
22
+
23
+ # Offense count: 7
24
+ Metrics/AbcSize:
25
+ Max: 22
26
+
27
+ # Offense count: 1
28
+ # Configuration parameters: CountComments.
29
+ Metrics/ClassLength:
30
+ Max: 112
31
+
32
+ # Offense count: 1
33
+ Metrics/CyclomaticComplexity:
34
+ Max: 7
35
+
36
+ # Offense count: 438
37
+ # Configuration parameters: AllowURI, URISchemes.
38
+ Metrics/LineLength:
39
+ Max: 288
40
+
41
+ # Offense count: 4
42
+ # Configuration parameters: CountComments.
43
+ Metrics/MethodLength:
44
+ Max: 15
45
+
46
+ # Offense count: 46
47
+ # Configuration parameters: Exclude.
48
+ Style/Documentation:
49
+ Enabled: false
50
+
51
+ # Offense count: 1
52
+ # Configuration parameters: Exclude.
53
+ Style/FileName:
54
+ Exclude:
55
+ - 'lib/slack-ruby-client.rb'
56
+
57
+ # Offense count: 86
58
+ # Configuration parameters: AllowedVariables.
59
+ Style/GlobalVars:
60
+ Enabled: false
61
+
62
+ # Offense count: 15
63
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
64
+ Style/MethodName:
65
+ Enabled: false
66
+
67
+ # Offense count: 3
68
+ Style/ModuleFunction:
69
+ Exclude:
70
+ - 'lib/slack/config.rb'
71
+ - 'lib/slack/real_time/config.rb'
72
+ - 'lib/slack/web/config.rb'
73
+
74
+ # Offense count: 2
75
+ # Cop supports --auto-correct.
76
+ Style/SpecialGlobalVars:
77
+ Exclude:
78
+ - 'lib/slack/messages/formatting.rb'
@@ -0,0 +1,26 @@
1
+ language: ruby
2
+
3
+ cache: bundler
4
+
5
+ rvm:
6
+ - 2.2
7
+ - 2.1
8
+ - 2.0
9
+ - rbx-2
10
+ - jruby-19mode
11
+ - ruby-head
12
+ - jruby-head
13
+
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: ruby-head
17
+ - rvm: jruby-head
18
+ - rvm: jruby-19mode
19
+ - rvm: rbx-2
20
+
21
+ git:
22
+ submodules: false
23
+
24
+ env:
25
+ - CONCURRENCY=celluloid-io
26
+ - CONCURRENCY=faye-websocket
@@ -0,0 +1,79 @@
1
+ ### 0.5.4 (1/23/2016)
2
+
3
+ * [#45](https://github.com/dblock/slack-ruby-client/issues/45): Added `channels_id`, `groups_id` and `users_id` - [@dblock](https://github.com/dblock).
4
+ * [#45](https://github.com/dblock/slack-ruby-client/issues/45): Automatically lookup channel, group and user ID in Web API methods when Slack API doesn't accept #channel or @user names - [@dblock](https://github.com/dblock).
5
+ * [#49](https://github.com/dblock/slack-ruby-client/pull/49): Fix: Celluloid `#connected?` method. - [@mikz](https://github.com/mikz), [@kandadaboggu](https://github.com/kandadaboggu).
6
+
7
+ ### 0.5.3 (1/11/2016)
8
+
9
+ * [#47](https://github.com/dblock/slack-ruby-client/pull/47): Fix: default to Celluloid newer API - [@jlyonsmith](https://github.com/jlyonsmith), [@dblock](https://github.com/dblock).
10
+ * Fixed JRuby file encoding regression - [@dblock](https://github.com/dblock).
11
+
12
+ ### 0.5.2 (1/8/2016)
13
+
14
+ * [#41](https://github.com/dblock/slack-ruby-client/issues/41): Added `Slack::Messages::Formatting#unescape` - [@dblock](https://github.com/dblock).
15
+ * Added `files_comments` to Web API - [@dblock](https://github.com/dblock).
16
+
17
+ ### 0.5.1 (1/4/2016)
18
+
19
+ * Added `dnd_teamInfo`, `dnd_setSnooze`, `dnd_info`, `dnd_endSnooze` and `dnd_endDnd` to Web API - [@dblock](https://github.com/dblock).
20
+ * The `files_upload` method now requires both `file` and `filename` to Web API - [@dblock](https://github.com/dblock).
21
+
22
+ ### 0.5.0 (12/7/2015)
23
+
24
+ * Added `usergroups_create`, `usergroups_disable`, `usergroups_enable`, `usergroups_list`, `usergroups_update` and `usergroups_users` to Web API - [@dblock](https://github.com/dblock).
25
+ * Added command-line `slack` client - [@dblock](https://github.com/dblock).
26
+ * [#5](https://github.com/dblock/slack-ruby-client/issues/5): Added Celluloid support - [@mikz](https://github.com/mikz), [@dblock](https://github.com/dblock).
27
+ * [#34](https://github.com/dblock/slack-ruby-client/pull/34): Added `Slack::RealTime::Client#start_async` - [@mikz](https://github.com/mikz), [@dblock](https://github.com/dblock).
28
+ * `Slack::RealTime::Client` supports `:open` and `:close` callbacks - [@dblock](https://github.com/dblock).
29
+ * [#32](https://github.com/dblock/slack-ruby-client/issues/32): Fix: `on_complete: undefined method [] for nil:NilClass` when responding to Slack 400-500 errors - [@dblock](https://github.com/dblock).
30
+ * [#22](https://github.com/dblock/slack-ruby-client/issues/22): Added `Slack::Web::Api::Error#response` - [@dblock](https://github.com/dblock).
31
+ * Added `logger` to `Slack::Web::Client` configuration that logs HTTP requests - [@dblock](https://github.com/dblock).
32
+
33
+ ### 0.4.0 (11/8/2015)
34
+
35
+ * Added `team_integrationLogs` to Web API - [@dblock](https://github.com/dblock).
36
+ * [#11](https://github.com/dblock/slack-ruby-client/pull/11) - Web API `chat_postMessage` errors only if both `attachments` and `text` are missing - [@dblock](https://github.com/dblock).
37
+ * [#20](https://github.com/dblock/slack-ruby-client/issues/20) - Web API `chat_postMessage` will automatically `to_json` attachments - [@dblock](https://github.com/dblock).
38
+ * Added `mpim_aware` to `rtm_start` to Web API - [@dblock](https://github.com/dblock).
39
+ * Added `mpim_close`, `mpim_history`, `mpim_list`, `mpim_mark` and `mpim_open` to Web API - [@dblock](https://github.com/dblock).
40
+ * Added `unreads` to `channels_history`, `groups_history` and `im_history` to Web API - [@dblock](https://github.com/dblock).
41
+ * Added `stars_add` and `stars_remove` to Web API - [@dblock](https://github.com/dblock).
42
+
43
+ ### 0.3.1 (10/16/2015)
44
+
45
+ * Added `stars_list`, `stars_add` and `stars_remove` to Web API - [@dblock](https://github.com/dblock).
46
+ * Added `attachments`, `parse` and `link_names` to `chat_update` in Web API - [@dblock](https://github.com/dblock).
47
+
48
+ ### 0.3.0 (9/1/2015)
49
+
50
+ * Added `team.info` and `accessLogs` to Web API - [@dblock](https://github.com/dblock).
51
+ * Removed obsolete `presence` Web API - [@dblock](https://github.com/dblock).
52
+ * Added `pins_add`, `pins_list` and `pins_remove` from Web API - [@dblock](https://github.com/dblock).
53
+ * Added `presence` to `users_list` in Web API - [@dblock](https://github.com/dblock).
54
+ * Added `groups_info` to Web API - [@dblock](https://github.com/dblock).
55
+ * Added `inclusive` to `groups_history` and `im_history` in Web API - [@dblock](https://github.com/dblock).
56
+ * Added `files_delete` to Web API - [@dblock](https://github.com/dblock).
57
+ * Added `as_user` to `chat_postMessage` in Web API - [@dblock](https://github.com/dblock).
58
+ * Use API reference schema from [github.com/dblock/slack-api-ref](https://github.com/dblock/slack-api-ref) - [@dblock](https://github.com/dblock).
59
+ * Added `reactions_add`, `reactions_list`, `reactions_get` and `reactions_remove` to Web API - [@jakedahn](https://github.com/jakedahn)
60
+
61
+ ### 0.2.1 (8/2/2015)
62
+
63
+ * Set Slack API token via `Slack::RealTime::Client.new(token: 'token')` and `Slack::Web::Client.new(token: 'token')` - [@dblock](https://github.com/dblock).
64
+ * Set Slack API token via `Slack::RealTime::Client.configure` and `Slack::Web::Client.configure` - [@dblock](https://github.com/dblock).
65
+
66
+ ### 0.2.0 (7/31/2015)
67
+
68
+ * [#2](https://github.com/dblock/slack-ruby-client/pull/2): `Slack::RealTime::Socket` now pings frames every 30s, as recommended by Slack - [@samdoiron](https://github.com/samdoiron).
69
+ * [#3](https://github.com/dblock/slack-ruby-client/issues/3): RealTime client WebSocket frame ping frequency is now configurable with `Slack::RealTime::Client.websocket_ping` - [@dblock](https://github.com/dblock).
70
+ * [#3](https://github.com/dblock/slack-ruby-client/issues/3): RealTime client WebSocket proxy is now configurable with `Slack::RealTime::Client.websocket_proxy` - [@dblock](https://github.com/dblock).
71
+ * [#3](https://github.com/dblock/slack-ruby-client/issues/3): Added global `Slack::Web::Client` and `Slack::RealTime::Client` configuration options via `Slack::Web::Client.configure` and `Slack::RealTime::Client.configure` - [@dblock](https://github.com/dblock).
72
+ * Exposed `Slack::RealTime::Client.url`, `team`, `self`, `users`, `channels`, `groups`, `ims` and `bots` - [@dblock](https://github.com/dblock).
73
+ * Default user-agent for `Slack::Web::Client` now includes a slash, eg. _Slack Ruby Client/0.1.1_ - [@dblock](https://github.com/dblock).
74
+ * Fix: set `Slack::Web::Client` connection options for `ca_path`, `ca_file`, and `proxy` - [@dblock](https://github.com/dblock).
75
+
76
+ ### 0.1.0 (7/25/2015)
77
+
78
+ * Initial public release with Web and RealTime Messaging API support - [@dblock](https://github.com/dblock).
79
+
@@ -0,0 +1,157 @@
1
+ # Contributing to Slack-Ruby-Client
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 Examples in Development
29
+
30
+ Sign up for Slack, 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
+ To run [the example in examples/hi_real_time](examples/hi_real_time/hi.rb), open a terminal, cd into _examples/hi_real_time_, run `bundle install`, followed by `SLACK_API_TOKEN=<your API token> bundle exec ruby hi.rb`.
39
+
40
+ ## Contribute Code
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. Add tests to [spec](spec).
55
+
56
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
57
+
58
+ ### Write Code
59
+
60
+ Implement your feature or bug fix.
61
+
62
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). Run `bundle exec rubocop` and fix any style issues highlighted, auto-correct issues when possible with `bundle exec rubocop -a`. To silence generally ingored issues, including line lengths or code complexity metrics, run `bundle exec rubocop --auto-gen-config`.
63
+
64
+ Make sure that `bundle exec rake` completes without errors.
65
+
66
+ ### Update Slack Web API
67
+
68
+ Slack Web API is updated from https://github.com/dblock/slack-api-ref, a maintained, machine-readable version of Slack API Docs, generated by scraping [api.slack.com](https://api.slack.com). To update the Web API from the latest definition run the following Rake task.
69
+
70
+ ```
71
+ rake slack:web:api:update
72
+ ```
73
+
74
+ #### Patching Slack Web API
75
+
76
+ Sometimes it's necessary to patch auto-generated Slack Web API methods. For example, we want to help clients with calling `to_json` on the `attachments` parameter sent to `chat_postMessage`. See [#20](https://github.com/dblock/slack-ruby-client/issues/20).
77
+
78
+ Make a change to a generated file, for example `lib/slack/web/api/endpoints/chat.rb` and generate a patch.
79
+
80
+ ```
81
+ git diff HEAD lib/slack/web/api/endpoints/chat.rb > lib/slack/web/api/patches/chat.1.patch
82
+ ```
83
+
84
+ Run `rake slack:web:api:update` to ensure that the patch is cleanly applied. Implement a test for the added or modified functionality and commit the patch file.
85
+
86
+ ### Write Documentation
87
+
88
+ Document any external behavior in the [README](README.md).
89
+
90
+ ### Update Changelog
91
+
92
+ Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Don't remove *Your contribution here*.
93
+
94
+ Make it look like every other line, including a link to the issue being fixed, your name and link to your Github account.
95
+
96
+ ### Commit Changes
97
+
98
+ Make sure git knows your name and email address:
99
+
100
+ ```
101
+ git config --global user.name "Your Name"
102
+ git config --global user.email "contributor@example.com"
103
+ ```
104
+
105
+ Writing good commit logs is important. A commit log should describe what changed and why.
106
+
107
+ ```
108
+ git add ...
109
+ git commit
110
+ ```
111
+
112
+ ### Push
113
+
114
+ ```
115
+ git push origin my-feature-branch
116
+ ```
117
+
118
+ ### Make a Pull Request
119
+
120
+ Go to https://github.com/contributor/slack-ruby-client and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
121
+
122
+ ### Update CHANGELOG Again
123
+
124
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
125
+
126
+ ```
127
+ * [#123](https://github.com/dblock/slack-ruby-client/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
128
+ ```
129
+
130
+ Amend your previous commit and force push the changes.
131
+
132
+ ```
133
+ git commit --amend
134
+ git push origin my-feature-branch -f
135
+ ```
136
+
137
+ ### Rebase
138
+
139
+ If you've been working on a change for a while, rebase with upstream/master.
140
+
141
+ ```
142
+ git fetch upstream
143
+ git rebase upstream/master
144
+ git push origin my-feature-branch -f
145
+ ```
146
+
147
+ ### Check on Your Pull Request
148
+
149
+ 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.
150
+
151
+ ### Be Patient
152
+
153
+ 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!
154
+
155
+ ## Thank You
156
+
157
+ Please do know that we really appreciate and value your time and work. We love you, really.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem ENV['CONCURRENCY'], require: false if ENV.key?('CONCURRENCY')
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2015-2016 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,385 @@
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.svg?branch=master)](https://travis-ci.org/dblock/slack-ruby-client)
6
+ [![Code Climate](https://codeclimate.com/github/dblock/slack-ruby-client/badges/gpa.svg)](https://codeclimate.com/github/dblock/slack-ruby-client)
7
+
8
+ A Ruby client for the Slack [Web](https://api.slack.com/web) and [RealTime Messaging](https://api.slack.com/rtm) APIs. Comes with a handy command-line client, too.
9
+
10
+ ![](slack.png)
11
+
12
+ ## Useful to Me?
13
+
14
+ * This piece of the puzzle will help you send messages to Slack via the Web API and send and receive messages via the Real Time API.
15
+ * If you're trying to respond to slash commands, just write a basic web application and use this library to call the Slack Web API.
16
+ * If you're trying to build a Real Time bot, use [slack-ruby-bot](https://github.com/dblock/slack-ruby-bot), which uses this library.
17
+ * If you're trying to roll out a full service with Slack button integration to multiple teams, check out [slack-bot-server](https://github.com/dblock/slack-bot-server), which is built on top of slack-ruby-bot, which uses this library.
18
+
19
+ ## Stable Release
20
+
21
+ You're reading the documentation for the **stable** release of slack-ruby-client, 0.5.4. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
22
+
23
+ ## Installation
24
+
25
+ Add to Gemfile.
26
+
27
+ ```
28
+ gem 'slack-ruby-client'
29
+ ```
30
+
31
+ If you're going to be using the RealTime client, add either `eventmachine` and `faye-websocket` or `celluloid-io`. See below for more information about concurrency.
32
+
33
+ ```
34
+ gem 'eventmachine'
35
+ gem 'faye-websocket'
36
+ ```
37
+
38
+ Run `bundle install`.
39
+
40
+ ## Usage
41
+
42
+ ### Create a New Bot Integration
43
+
44
+ This is something done in Slack, under [integrations](https://my.slack.com/services). Create a [new bot](https://my.slack.com/services/new/bot), and note its API token.
45
+
46
+ ![](screenshots/register-bot.png)
47
+
48
+ ### Use the API Token
49
+
50
+ ```ruby
51
+ Slack.configure do |config|
52
+ config.token = ENV['SLACK_API_TOKEN']
53
+ end
54
+ ```
55
+
56
+ This sets a global default token. You can also pass a token into the initializer of both `Slack::Web::Client` and `Slack::RealTime::Client` or configure those separately via `Slack::Web::Config.configure` and `Slack::RealTime::Config.configure`. The instance token will be used over the client type token over the global default.
57
+
58
+ ### Web Client
59
+
60
+ The Slack Web API allows you to build applications that interact with Slack.
61
+
62
+ #### Test Auth
63
+
64
+ ```ruby
65
+ client = Slack::Web::Client.new
66
+ client.auth_test
67
+ ```
68
+
69
+ #### Send Messages
70
+
71
+ Send messages with [chat_PostMessage](https://api.slack.com/methods/chat.postMessage).
72
+
73
+ ```ruby
74
+ client.chat_postMessage(channel: '#general', text: 'Hello World', as_user: true)
75
+ ```
76
+
77
+ See a fully working example in [examples/hi_web](examples/hi_web/hi.rb).
78
+
79
+ ![](examples/hi_web/hi.gif)
80
+
81
+ #### List Channels
82
+
83
+ List channels with [channels_list](https://api.slack.com/methods/channels.list).
84
+
85
+ ```ruby
86
+ channels = client.channels_list['channels']
87
+
88
+ general_channel = channels.detect { |c| c['name'] == 'general' }
89
+ ```
90
+
91
+ #### Upload a File
92
+
93
+ Upload a file with [files_upload](https://api.slack.com/methods/files.upload).
94
+
95
+ ```ruby
96
+ client.files_upload(
97
+ channels: '#general',
98
+ as_user: true,
99
+ file: Faraday::UploadIO.new('/path/to/avatar.jpg', 'image/jpeg'),
100
+ title: 'My Avatar',
101
+ filename: 'avatar.jpg',
102
+ initial_comment: 'Attached a selfie.'
103
+ )
104
+ ```
105
+
106
+ ### Get Channel Info
107
+
108
+ You can use a channel ID or name (prefixed with `#`) in all functions that take a `:channel` argument. Lookup by name is not supported by the Slack API and the `channels_id` method called invokes `channels_list` in order to locate the channel ID.
109
+
110
+ ```ruby
111
+ client.channels_info(channel: 'C04KB5X4D') # calls channels_info
112
+ ```
113
+
114
+ ```ruby
115
+ client.channels_info(channel: '#general') # calls channels_list followed by channels_info
116
+ ```
117
+
118
+ ### Get User Info
119
+
120
+ You can use a user ID or name (prefixed with `@`) in all functions that take a `:user` argument. Lookup by name is not supported by the Slack API and the `users_id` method called invokes `users_list` in order to locate the user ID.
121
+
122
+ ```ruby
123
+ client.users_info(user: 'U092BDCLV') # calls users_info
124
+ ```
125
+
126
+ ```ruby
127
+ client.users_info(user: '@dblock') # calls users_list followed by users_info
128
+ ```
129
+
130
+ #### Other
131
+
132
+ Refer to the [Slack Web API Method Reference](https://api.slack.com/methods) for the list of all available functions.
133
+
134
+ #### Web Client Options
135
+
136
+ You can configure the Web client either globally or via the initializer.
137
+
138
+ ```ruby
139
+ Slack::Web::Client.config do |config|
140
+ config.user_agent = 'Slack Ruby Client/1.0'
141
+ end
142
+ ```
143
+
144
+ ```ruby
145
+ client = Slack::Web::Client.new(user_agent: 'Slack Ruby Client/1.0')
146
+ ```
147
+
148
+ The following settings are supported.
149
+
150
+ setting | description
151
+ -------------|-------------------------------------------------------------------------------------------------
152
+ token | Slack API token.
153
+ user_agent | User-agent, defaults to _Slack Ruby Client/version_.
154
+ proxy | Optional HTTP proxy.
155
+ ca_path | Optional SSL certificates path.
156
+ ca_file | Optional SSL certificates file.
157
+ endpoint | Slack endpoint, default is _https://slack.com/api_.
158
+ logger | Optional `Logger` instance that logs HTTP requests.
159
+
160
+ ### RealTime Client
161
+
162
+ 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.
163
+
164
+ ```ruby
165
+ client = Slack::RealTime::Client.new
166
+
167
+ client.on :hello do
168
+ puts "Successfully connected, welcome '#{client.self['name']}' to the '#{client.team['name']}' team at https://#{client.team['domain']}.slack.com."
169
+ end
170
+
171
+ client.on :message do |data|
172
+ case data['text']
173
+ when 'bot hi' then
174
+ client.message channel: data['channel'], text: "Hi <@#{data['user']}>!"
175
+ when /^bot/ then
176
+ client.message channel: data['channel'], text: "Sorry <@#{data['user']}>, what?"
177
+ end
178
+ end
179
+
180
+ client.start!
181
+ ```
182
+
183
+ You can send typing indicators with `typing`.
184
+
185
+ ```ruby
186
+ client.typing channel: data['channel']
187
+ ```
188
+
189
+ You can send a ping with `ping`.
190
+
191
+ ```ruby
192
+ client.ping
193
+ ```
194
+
195
+ The client exposes the properties of [rtm.start](https://api.slack.com/methods/rtm.start) upon a successful connection.
196
+
197
+ property | description
198
+ ---------|-------------------------------------------------------------------------------------------------
199
+ url | A WebSocket Message Server URL.
200
+ self | Details on the authenticated user.
201
+ team | Details on the authenticated user's team.
202
+ users | A list of user objects, one for every member of the team.
203
+ channels | A list of channel objects, one for every channel visible to the authenticated user.
204
+ groups | A list of group objects, one for every group the authenticated user is in.
205
+ ims | A list of IM objects, one for every direct message channel visible to the authenticated user.
206
+ bots | Details of the integrations set up on this team.
207
+
208
+ You can configure the RealTime client either globally or via the initializer.
209
+
210
+ ```ruby
211
+ Slack::RealTime::Client.config do |config|
212
+ config.websocket_ping = 42
213
+ end
214
+ ```
215
+
216
+ ```ruby
217
+ client = Slack::RealTime::Client.new(websocket_ping: 42)
218
+ ```
219
+
220
+ The following settings are supported.
221
+
222
+ setting | description
223
+ ----------------|-----------------------------------------------------------------------------------------------------
224
+ token | Slack API token.
225
+ websocket_ping | The number of seconds that indicates how often the WebSocket should send ping frames, default is 30.
226
+ websocket_proxy | Connect via proxy, include `:origin` and `:headers`.
227
+
228
+ Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start), configure Web client options via `Slack::Web::Client.configure` as described above.
229
+
230
+ See a fullly working example in [examples/hi_real_time](examples/hi_real_time/hi.rb).
231
+
232
+ ![](examples/hi_real_time/hi.gif)
233
+
234
+ ### Combining RealTime and Web Clients
235
+
236
+ 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.
237
+
238
+ ```ruby
239
+ client = Slack::RealTime::Client.new
240
+
241
+ client.on :message do |data|
242
+ case data['text']
243
+ when 'bot hi' then
244
+ client.web_client.chat_postMessage channel: data['channel'], text: "Hi <@#{data['user']}>!"
245
+ when /^bot/ then
246
+ client.web_client.chat_postMessage channel: data['channel'], text: "Sorry <@#{data['user']}>, what?"
247
+ end
248
+ end
249
+
250
+ client.start!
251
+ ```
252
+
253
+ See a fullly working example in [examples/hi_real_time_and_web](examples/hi_real_time_and_web/hi.rb).
254
+
255
+ ![](examples/hi_real_time_and_web/hi.gif)
256
+
257
+ #### Concurrency
258
+
259
+ `Slack::RealTime::Client` needs help from a concurrency library and supports [Faye::WebSocket](https://github.com/faye/faye-websocket-ruby) with [Eventmachine](https://github.com/eventmachine/eventmachine) and [Celluloid](https://github.com/celluloid/celluloid). It will auto-detect one or the other depending on the gems in your Gemfile, but you can also set concurrency explicitly.
260
+
261
+ ```ruby
262
+ Slack::RealTime.configure do |config|
263
+ config.concurrency = Slack::RealTime::Concurrency::Eventmachine
264
+ end
265
+ ```
266
+
267
+ Use `client.start_async` instead of `client.start!` if you don't want the library to control the event run loop, such as when integrating into other applications that already use Eventmachine or Celluloid. A good example of such application is [slack-bot-server](https://github.com/dblock/slack-bot-server).
268
+
269
+ ```ruby
270
+ client = Slack::RealTime::Client.new
271
+
272
+ EM.run do
273
+ client.start_async
274
+ end
275
+ ```
276
+
277
+ See a fully working example in [examples/hi_real_time_async](examples/hi_real_time_async/hi.rb).
278
+
279
+ ##### Faye::Websocket with Eventmachine
280
+
281
+ Add the following to your Gemfile.
282
+
283
+ ```
284
+ gem 'faye-websocket'
285
+ ```
286
+
287
+ ##### Celluloid
288
+
289
+ Add the following to your Gemfile.
290
+
291
+ ```
292
+ gem 'celluloid-io'
293
+ ```
294
+
295
+ ### Message Parsing
296
+
297
+ All text in Slack uses the same [system of escaping](https://api.slack.com/docs/formatting): chat messages, direct messages, file comments, etc. Use [Slack::Messages::Formatting](lib/slack/messages/formatting.rb) to unescape incoming messages. This comes handy, for example, you want to treat all input to a real time bot as plain text.
298
+
299
+ ```ruby
300
+ Slack::Messages::Formatting.unescape('Hello &amp; &lt;world&gt;'))
301
+ # => 'Hello & <world>'
302
+ Slack::Messages::Formatting.unescape('Hey <@U024BE7LH|bob>, did you see my file?'))
303
+ # => 'Hey @bob, did you see my file?'
304
+ Slack::Messages::Formatting.unescape('Hey <@U02BEFY4U>'))
305
+ # => 'Hey @U02BEFY4U'
306
+ Slack::Messages::Formatting.unescape('This message contains a URL <http://foo.com/>'))
307
+ # => 'This message contains a URL http://foo.com/'
308
+ Slack::Messages::Formatting.unescape('So does this one: <http://www.foo.com|www.foo.com>'))
309
+ # => 'So does this one: www.foo.com'
310
+ Slack::Messages::Formatting.unescape('<mailto:bob@example.com|Bob>'))
311
+ # => 'Bob'
312
+ Slack::Messages::Formatting.unescape('Hello <@U123|bob>, say hi to <!everyone> in <#C1234|general>'))
313
+ # => 'Hello @bob, say hi to @everyone in #general'
314
+ Slack::Messages::Formatting.unescape('Hello <@U123|bob> &gt; file.txt'))
315
+ # => 'Hello @bob > file.txt'
316
+ Slack::Messages::Formatting.unescape('“hello”'))
317
+ # => '"hello"'
318
+ Slack::Messages::Formatting.unescape('‘hello’'))
319
+ # => "'hello'"
320
+ ```
321
+
322
+ ### Command-Line Client
323
+
324
+ The slack command-line client returns JSON data from the Slack API.
325
+
326
+ #### Authenticate with Slack
327
+
328
+ ```
329
+ $ slack --slack-api-token=[token] auth test
330
+ {"ok":true,"url":"...","team":"...","user":"...","team_id":"...","user_id":"..."}
331
+ ```
332
+
333
+ #### Send a Message
334
+
335
+ ```
336
+ export SLACK_API_TOKEN=...
337
+ $ slack chat postMessage --text="hello world" --channel="#general"
338
+ {"ok":true,"channel":"...","ts":"...","message":{"text":"hello world","username":"bot","type":"message","subtype":"bot_message","ts":"..."}}
339
+ ```
340
+
341
+ #### Get Channel Id
342
+
343
+ ```
344
+ $ slack channels id --channel=#general
345
+ {"ok":true,"channel":{"id":"C04KB5X4D"}}
346
+ ```
347
+
348
+ #### Get Channel Info
349
+
350
+ ```
351
+ $ slack channels info --channel=#general
352
+ {"ok":true,"channel":{"id":"C04KB5X4D","name":"general", ...}}
353
+ ```
354
+
355
+ #### List Users
356
+
357
+ Combine with [jq](http://stedolan.github.io/jq), a command-line JSON parser.
358
+
359
+ ```
360
+ $ slack users list | jq '.members | map({(.id): .name})'
361
+ [
362
+ {
363
+ "U04KB5WQR": "dblock"
364
+ },
365
+ {
366
+ "U07518DTL": "rubybot"
367
+ }
368
+ ]
369
+ ```
370
+
371
+ See `slack help` for a complete command-line reference.
372
+
373
+ ## History
374
+
375
+ 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.
376
+
377
+ ## Contributing
378
+
379
+ See [CONTRIBUTING](CONTRIBUTING.md).
380
+
381
+ ## Copyright and License
382
+
383
+ Copyright (c) 2015-2016, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
384
+
385
+ This project is licensed under the [MIT License](LICENSE.md).