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.
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,32 @@
1
+ # This file was auto-generated by lib/slack/web/api/tasks/generate.rake
2
+
3
+ module Slack
4
+ module Web
5
+ module Api
6
+ module Endpoints
7
+ module Oauth
8
+ #
9
+ # Exchanges a temporary OAuth code for an API token.
10
+ #
11
+ # @option options [Object] :client_id
12
+ # Issued when you created your application.
13
+ # @option options [Object] :client_secret
14
+ # Issued when you created your application.
15
+ # @option options [Object] :code
16
+ # The `code` param returned via the OAuth callback.
17
+ # @option options [Object] :redirect_uri
18
+ # This must match the originally submitted URI (if one was sent).
19
+ # @see https://api.slack.com/methods/oauth.access
20
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/oauth.access.md
21
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/oauth.access.json
22
+ def oauth_access(options = {})
23
+ throw ArgumentError.new('Required arguments :client_id missing') if options[:client_id].nil?
24
+ throw ArgumentError.new('Required arguments :client_secret missing') if options[:client_secret].nil?
25
+ throw ArgumentError.new('Required arguments :code missing') if options[:code].nil?
26
+ post('oauth.access', options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ # This file was auto-generated by lib/slack/web/api/tasks/generate.rake
2
+
3
+ module Slack
4
+ module Web
5
+ module Api
6
+ module Endpoints
7
+ module Presence
8
+ #
9
+ # Manually set user presence
10
+ #
11
+ # @option options [Object] :presence
12
+ # Either `active` or `away`
13
+ # @see https://api.slack.com/methods/presence.set
14
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/presence.set.md
15
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/presence.set.json
16
+ def presence_set(options = {})
17
+ throw ArgumentError.new('Required arguments :presence missing') if options[:presence].nil?
18
+ post('presence.set', options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ # This file was auto-generated by lib/slack/web/api/tasks/generate.rake
2
+
3
+ module Slack
4
+ module Web
5
+ module Api
6
+ module Endpoints
7
+ module Rtm
8
+ #
9
+ # Starts a Real Time Messaging session.
10
+ #
11
+ # @see https://api.slack.com/methods/rtm.start
12
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/rtm.start.md
13
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/rtm.start.json
14
+ def rtm_start(options = {})
15
+ post('rtm.start', options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,68 @@
1
+ # This file was auto-generated by lib/slack/web/api/tasks/generate.rake
2
+
3
+ module Slack
4
+ module Web
5
+ module Api
6
+ module Endpoints
7
+ module Search
8
+ #
9
+ # Searches for messages and files matching a query.
10
+ #
11
+ # @option options [Object] :query
12
+ # Search query. May contains booleans, etc.
13
+ # @option options [Object] :sort
14
+ # Return matches sorted by either `score` or `timestamp`.
15
+ # @option options [Object] :sort_dir
16
+ # Change sort direction to ascending (`asc`) or descending (`desc`).
17
+ # @option options [Object] :highlight
18
+ # Pass a value of `1` to enable query highlight markers (see below).
19
+ # @see https://api.slack.com/methods/search.all
20
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/search.all.md
21
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/search.all.json
22
+ def search_all(options = {})
23
+ throw ArgumentError.new('Required arguments :query missing') if options[:query].nil?
24
+ post('search.all', options)
25
+ end
26
+
27
+ #
28
+ # Searches for files matching a query.
29
+ #
30
+ # @option options [Object] :query
31
+ # Search query. May contains booleans, etc.
32
+ # @option options [Object] :sort
33
+ # Return matches sorted by either `score` or `timestamp`.
34
+ # @option options [Object] :sort_dir
35
+ # Change sort direction to ascending (`asc`) or descending (`desc`).
36
+ # @option options [Object] :highlight
37
+ # Pass a value of `1` to enable query highlight markers (see below).
38
+ # @see https://api.slack.com/methods/search.files
39
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/search.files.md
40
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/search.files.json
41
+ def search_files(options = {})
42
+ throw ArgumentError.new('Required arguments :query missing') if options[:query].nil?
43
+ post('search.files', options)
44
+ end
45
+
46
+ #
47
+ # Searches for messages matching a query.
48
+ #
49
+ # @option options [Object] :query
50
+ # Search query. May contains booleans, etc.
51
+ # @option options [Object] :sort
52
+ # Return matches sorted by either `score` or `timestamp`.
53
+ # @option options [Object] :sort_dir
54
+ # Change sort direction to ascending (`asc`) or descending (`desc`).
55
+ # @option options [Object] :highlight
56
+ # Pass a value of `1` to enable query highlight markers (see below).
57
+ # @see https://api.slack.com/methods/search.messages
58
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/search.messages.md
59
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/search.messages.json
60
+ def search_messages(options = {})
61
+ throw ArgumentError.new('Required arguments :query missing') if options[:query].nil?
62
+ post('search.messages', options)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,23 @@
1
+ # This file was auto-generated by lib/slack/web/api/tasks/generate.rake
2
+
3
+ module Slack
4
+ module Web
5
+ module Api
6
+ module Endpoints
7
+ module Stars
8
+ #
9
+ # Lists stars for a user.
10
+ #
11
+ # @option options [user] :user
12
+ # Show stars by this user. Defaults to the authed user.
13
+ # @see https://api.slack.com/methods/stars.list
14
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/stars.list.md
15
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/stars.list.json
16
+ def stars_list(options = {})
17
+ post('stars.list', options)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,70 @@
1
+ # This file was auto-generated by lib/slack/web/api/tasks/generate.rake
2
+
3
+ module Slack
4
+ module Web
5
+ module Api
6
+ module Endpoints
7
+ module Users
8
+ #
9
+ # Gets user presence information.
10
+ #
11
+ # @option options [user] :user
12
+ # User to get presence info on. Defaults to the authed user.
13
+ # @see https://api.slack.com/methods/users.getPresence
14
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.getPresence.md
15
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.getPresence.json
16
+ def users_getPresence(options = {})
17
+ throw ArgumentError.new('Required arguments :user missing') if options[:user].nil?
18
+ post('users.getPresence', options)
19
+ end
20
+
21
+ #
22
+ # Gets information about a user.
23
+ #
24
+ # @option options [user] :user
25
+ # User to get info on
26
+ # @see https://api.slack.com/methods/users.info
27
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.info.md
28
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.info.json
29
+ def users_info(options = {})
30
+ throw ArgumentError.new('Required arguments :user missing') if options[:user].nil?
31
+ post('users.info', options)
32
+ end
33
+
34
+ #
35
+ # Lists all users in a Slack team.
36
+ #
37
+ # @see https://api.slack.com/methods/users.list
38
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.list.md
39
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.list.json
40
+ def users_list(options = {})
41
+ post('users.list', options)
42
+ end
43
+
44
+ #
45
+ # Marks a user as active.
46
+ #
47
+ # @see https://api.slack.com/methods/users.setActive
48
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.setActive.md
49
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.setActive.json
50
+ def users_setActive(options = {})
51
+ post('users.setActive', options)
52
+ end
53
+
54
+ #
55
+ # Manually sets user presence.
56
+ #
57
+ # @option options [Object] :presence
58
+ # Either `auto` or `away`
59
+ # @see https://api.slack.com/methods/users.setPresence
60
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.setPresence.md
61
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/users.setPresence.json
62
+ def users_setPresence(options = {})
63
+ throw ArgumentError.new('Required arguments :presence missing') if options[:presence].nil?
64
+ post('users.setPresence', options)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,8 @@
1
+ module Slack
2
+ module Web
3
+ module Api
4
+ class Error < ::Faraday::Error
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ {
2
+ "type": "object",
3
+ "required": [
4
+ "desc",
5
+ "args",
6
+ "errors"
7
+ ],
8
+ "properties": {
9
+ "desc": {
10
+ "type": "string"
11
+ },
12
+ "args": {
13
+ "type": "object",
14
+ "default": {},
15
+ "patternProperties": {
16
+ "^.+$": {
17
+ "properties": {
18
+ "required": {
19
+ "type": "bool",
20
+ "default": false
21
+ },
22
+ "example": {
23
+ "type": "any",
24
+ "required": false,
25
+ "default": ""
26
+ },
27
+ "type": {
28
+ "type": "any",
29
+ "required": false,
30
+ "default": "Object"
31
+ },
32
+ "desc": {
33
+ "type": "string",
34
+ "required": true
35
+ }
36
+ }
37
+ }
38
+ }
39
+ },
40
+ "errors": {
41
+ "type": "object",
42
+ "default": {}
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,37 @@
1
+ # largely from https://github.com/aki017/slack-ruby-gem
2
+ require 'json-schema'
3
+ require 'erubis'
4
+
5
+ namespace :slack do
6
+ namespace :web do
7
+ namespace :api do
8
+ # update slack-api-docs from https://github.com/slackhq/slack-api-docs
9
+ task :git_update do
10
+ sh 'git submodule update --init --recursive'
11
+ sh 'git submodule foreach git pull origin master'
12
+ end
13
+
14
+ desc 'Update API.'
15
+ task update: [:git_update] do
16
+ method_schema = JSON.parse(File.read('lib/slack/web/api/schema/method.json'))
17
+ data = Dir.glob('lib/slack/web/api/slack-api-docs/methods/*.json').each_with_object({}) do |path, result|
18
+ name = File.basename(path, '.json')
19
+ prefix, name = name.split('.')
20
+ result[prefix] ||= {}
21
+ parsed = JSON.parse(File.read(path))
22
+ JSON::Validator.validate(method_schema, parsed, insert_defaults: true)
23
+ result[prefix][name] = parsed
24
+ end
25
+
26
+ method_template = Erubis::Eruby.new(File.read('lib/slack/web/api/templates/method.erb'))
27
+ data.each_with_index do |(group, names), index|
28
+ printf "%2d/%2d %10s %s\n", index, data.size, group, names.keys
29
+ File.write "lib/slack/web/api/endpoints/#{group}.rb", method_template.result(group: group, names: names)
30
+ end
31
+
32
+ endpoints_template = Erubis::Eruby.new(File.read('lib/slack/web/api/templates/endpoints.erb'))
33
+ File.write 'lib/slack/web/api/endpoints.rb', endpoints_template.result(files: data.keys)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ # This file was auto-generated by lib/slack/web/api/tasks/generate.rake
2
+
3
+ <% files.each do |f| %>
4
+ require 'slack/web/api/endpoints/<%= f %>'
5
+ <% end %>
6
+
7
+ module Slack
8
+ module Web
9
+ module Api
10
+ module Endpoints
11
+ <% files.each do |f| %>
12
+ include <%= f.capitalize %>
13
+ <% end %>
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,39 @@
1
+ # This file was auto-generated by lib/slack/web/api/tasks/generate.rake
2
+
3
+ module Slack
4
+ module Web
5
+ module Api
6
+ module Endpoints
7
+ module <%= group.capitalize %>
8
+ <% names.each_with_index do |(name, data), index| %>
9
+ <% if index > 0 %>
10
+
11
+ <% end %>
12
+ #
13
+ # <%= data["desc"] %>
14
+ #
15
+ <% data["args"].each do |arg_name, arg_v| %>
16
+ # @option options [<%= arg_v["type"] %>] :<%= arg_name %>
17
+ <% arg_v["desc"].lines.each do |l| %>
18
+ <% if l.strip.length > 0 %>
19
+ # <%= l.strip %>
20
+ <% else %>
21
+ #
22
+ <% end %>
23
+ <% end %>
24
+ <% end %>
25
+ # @see https://api.slack.com/methods/<%= group %>.<%= name %>
26
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/<%= group %>.<%= name %>.md
27
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/<%= group %>.<%= name %>.json
28
+ def <%= group %>_<%= name %>(options = {})
29
+ <% data["args"].select{|k,v| v["required"]}.each do |arg_name, arg_v| %>
30
+ throw ArgumentError.new('Required arguments :<%= arg_name %> missing') if options[:<%= arg_name %>].nil?
31
+ <% end %>
32
+ post('<%= group %>.<%= name %>', options)
33
+ end
34
+ <% end %>
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,17 @@
1
+ module Slack
2
+ module Web
3
+ class Client
4
+ include Faraday::Connection
5
+ include Faraday::Request
6
+ include Api::Endpoints
7
+
8
+ attr_accessor(*Config::ATTRIBUTES)
9
+
10
+ def initialize(options = {})
11
+ Slack::Web::Config::ATTRIBUTES.each do |key|
12
+ send("#{key}=", options[key] || Slack::Web.config.send(key))
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ module Slack
2
+ module Web
3
+ module Config
4
+ extend self
5
+
6
+ ATTRIBUTES = [
7
+ :proxy,
8
+ :user_agent,
9
+ :ca_path,
10
+ :ca_file,
11
+ :endpoint
12
+ ]
13
+
14
+ attr_accessor(*Config::ATTRIBUTES)
15
+
16
+ def reset
17
+ self.endpoint = 'https://slack.com/api/'
18
+ self.user_agent = "Slack Ruby Client #{Slack::VERSION}"
19
+ self.ca_path = `openssl version -a | grep OPENSSLDIR | awk '{print $2}'|sed -e 's/\"//g'`
20
+ self.ca_file = "#{ca_path}/ca-certificates.crt"
21
+ end
22
+ end
23
+
24
+ class << self
25
+ def configure
26
+ block_given? ? yield(Config) : Config
27
+ end
28
+
29
+ def config
30
+ Config
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ Slack::Web::Config.reset