slack-api 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cc40fc79197f3f36d7830a78ae180c1164388ce
4
- data.tar.gz: bcee43066b00c2f7e7b34acfd3851f12cf38653c
3
+ metadata.gz: d98e9d118812d8f110c8172eaa3458c983bc1bd7
4
+ data.tar.gz: 98b72bbd4cb361934c653d7cb771ea82fa6dce30
5
5
  SHA512:
6
- metadata.gz: 2c7f59b4a155b6794a954073247268ada9ba3f4fd1158f22aab835d3f559ee5a01e3a82a40433c7921da81e5708f19c126b35a21e5b31b3985459fe15433d118
7
- data.tar.gz: 150295b2ffc0ff7371e193cdc6e7b87b5c8efa0315e3bdbe75084fcf079a8f63c4545a3bc7ed5f76ba07a2d6c2555974c701f60bc13787dfb9dd24636c953324
6
+ metadata.gz: 8e8ee8eb9bcb66fbcee0e41b949117eef8348d0f371cdb27202f81e11f0e0fb16aff665341a12293e1f75097871f2f1a8929ced333b3d95d82a8eeabf651fa62
7
+ data.tar.gz: c606c98d7f298ea5915bab37eff480bdbb46fb80017f32885d42475ceab13d9868db290bb0b2da31946fe36545b3f3bcca41c4fa3827f6b2d385af8add93c474
@@ -0,0 +1,3 @@
1
+ [submodule "slack-api-docs"]
2
+ path = slack-api-docs
3
+ url = git@github.com:slackhq/slack-api-docs.git
data/Rakefile CHANGED
@@ -1 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
+ require_relative "./lib/generators/tasks/generate"
@@ -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,76 @@
1
+ require 'json-schema'
2
+ require 'erubis'
3
+
4
+ namespace :api do
5
+ desc "update"
6
+ task :update do
7
+ Dir.chdir root
8
+ sh "git submodule update --init --recursive"
9
+ sh "git submodule foreach git pull origin master"
10
+ Rake::Task["api:generate"].execute
11
+ sh "git add lib/slack/endpoint.rb"
12
+ sh "git add lib/slack/endpoint/"
13
+ sh "git add slack-api-docs"
14
+ sh "git commit -m 'rake api:update'"
15
+ end
16
+
17
+ desc "Generate"
18
+ task :generate do
19
+ jsons = File.expand_path 'slack-api-docs/methods/*.json', root
20
+ schema_path = File.expand_path "lib/generators/schema.json", root
21
+ schema = JSON.parse(File.read(schema_path))
22
+
23
+ data = Dir.glob(jsons).each_with_object({}) do |path, result|
24
+ name = File.basename(path, ".json")
25
+ prefix, name = name.split(".")
26
+ next if prefix == "rtm"
27
+ result[prefix] ||= {}
28
+
29
+ parsed = JSON.parse(File.read(path))
30
+ JSON::Validator.validate(schema, parsed, :insert_defaults => true)
31
+
32
+ result[prefix][name] = parsed
33
+
34
+ end
35
+
36
+ generate_methods(data)
37
+ generate_endpoint(data)
38
+ end
39
+
40
+ desc "Cleanup"
41
+ task :clean do
42
+ outdir = File.expand_path "lib/slack/endpoint", root
43
+ FileUtils.rm_rf outdir
44
+
45
+ outpath = File.expand_path "lib/slack/endpoint.rb", root
46
+ FileUtils.rm_rf outpath
47
+ end
48
+
49
+ def generate_endpoint(data)
50
+ templete_path = File.expand_path 'lib/generators/templates/endpoint.rb.erb', root
51
+ templete = Erubis::Eruby.new(File.read(templete_path))
52
+
53
+ outpath = File.expand_path "lib/slack/endpoint.rb", root
54
+ FileUtils.rm_rf outpath
55
+ File.write outpath, templete.result(files: data.keys)
56
+ end
57
+
58
+ def generate_methods(data)
59
+ templete_path = File.expand_path 'lib/generators/templates/method.rb.erb', root
60
+ templete = Erubis::Eruby.new(File.read(templete_path))
61
+
62
+ outdir = File.expand_path "lib/slack/endpoint", root
63
+ FileUtils.rm_rf outdir
64
+ FileUtils.mkdir outdir
65
+ data.each_with_index do |(group, names), index|
66
+ printf "%2d/%2d %10s %s\n", index, data.size, group, names.keys
67
+
68
+ outpath = File.expand_path "#{group}.rb", outdir
69
+ File.write outpath, templete.result(group: group, names: names)
70
+ end
71
+ end
72
+
73
+ def root
74
+ File.expand_path '../../../..', __FILE__
75
+ end
76
+ end
@@ -0,0 +1,13 @@
1
+ # This file was auto-generated by lib/generators/tasks/generate.rb
2
+ #
3
+ <% files.each do |f| %>
4
+ require_relative 'endpoint/<%= f %>'
5
+ <% end %>
6
+
7
+ module Slack
8
+ module Endpoint
9
+ <% files.each do |f| %>
10
+ include <%= f.capitalize %>
11
+ <% end %>
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # This file was auto-generated by lib/generators/tasks/generate.rb
2
+
3
+ module Slack
4
+ module Endpoint
5
+ module <%= group.capitalize %>
6
+ <% names.each do |name, data| %>
7
+ #
8
+ # <%= data["desc"] %>
9
+ #
10
+ <% data["args"].each do |arg_name, arg_v| %>
11
+ # @option options [<%= arg_v["type"] %>] :<%= arg_name %>
12
+ <% arg_v["desc"].lines.each do |l| %>
13
+ # <%= l.strip %>
14
+ <% end %>
15
+ <% end %>
16
+ # @see https://api.slack.com/methods/<%= group %>.<%= name %>
17
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/<%= group %>.<%= name %>.md
18
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/<%= group %>.<%= name %>.json
19
+ def <%= group %>_<%= name %>(options={})
20
+ <% data["args"].select{|k,v| v["required"]}.each do |arg_name, arg_v| %>
21
+ throw ArgumentError.new("Required arguments :<%= arg_name %> missing") if options[:<%= arg_name %>].nil?
22
+ <% end %>
23
+ post("<%= group %>.<%= name %>", options)
24
+ end
25
+
26
+ <% end %>
27
+ end
28
+ end
29
+ end
@@ -1,8 +1,8 @@
1
- require "slack/error"
2
- require "slack/configuration"
3
- require "slack/api"
4
- require "slack/client"
5
- require "slack/version"
1
+ require_relative "slack/error"
2
+ require_relative "slack/configuration"
3
+ require_relative "slack/api"
4
+ require_relative "slack/client"
5
+ require_relative "slack/version"
6
6
 
7
7
  module Slack
8
8
  extend Configuration
@@ -1,12 +1,14 @@
1
1
  require File.expand_path('../connection', __FILE__)
2
2
  require File.expand_path('../request', __FILE__)
3
3
  require File.expand_path('../configuration', __FILE__)
4
+ require File.expand_path('../endpoint', __FILE__)
5
+ require File.expand_path('../realtime/client', __FILE__)
4
6
 
5
7
  module Slack
6
8
  # @private
7
9
  class API
8
10
  # @private
9
- attr_accessor *Configuration::VALID_OPTIONS_KEYS
11
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
10
12
 
11
13
  # Creates a new API
12
14
  def initialize(options={})
@@ -18,5 +20,11 @@ module Slack
18
20
 
19
21
  include Connection
20
22
  include Request
23
+ include Endpoint
24
+
25
+ def realtime
26
+ url = post("rtm.start")["url"]
27
+ RealTime::Client.new(url)
28
+ end
21
29
  end
22
30
  end
@@ -1,17 +1,4 @@
1
1
  module Slack
2
2
  class Client < API
3
- METHODS = %w(users.info users.list channels.history channels.join
4
- channels.mark channels.list files.upload files.list
5
- im.history im.list groups.history groups.list
6
- search.all search.files search.messages
7
- chat.postMessage auth.test)
8
-
9
- def respond_to?(method)
10
- return METHODS.include?(method.id2name.gsub("_", ".")) || super
11
- end
12
-
13
- def method_missing(action, *args)
14
- post(action.id2name.gsub("_", "."), *args)
15
- end
16
3
  end
17
4
  end
@@ -0,0 +1,33 @@
1
+ # This file was auto-generated by lib/generators/tasks/generate.rb
2
+ #
3
+ require_relative 'endpoint/api'
4
+ require_relative 'endpoint/auth'
5
+ require_relative 'endpoint/channels'
6
+ require_relative 'endpoint/chat'
7
+ require_relative 'endpoint/emoji'
8
+ require_relative 'endpoint/files'
9
+ require_relative 'endpoint/groups'
10
+ require_relative 'endpoint/im'
11
+ require_relative 'endpoint/oauth'
12
+ require_relative 'endpoint/presence'
13
+ require_relative 'endpoint/search'
14
+ require_relative 'endpoint/stars'
15
+ require_relative 'endpoint/users'
16
+
17
+ module Slack
18
+ module Endpoint
19
+ include Api
20
+ include Auth
21
+ include Channels
22
+ include Chat
23
+ include Emoji
24
+ include Files
25
+ include Groups
26
+ include Im
27
+ include Oauth
28
+ include Presence
29
+ include Search
30
+ include Stars
31
+ include Users
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ # This file was auto-generated by lib/generators/tasks/generate.rb
2
+
3
+ module Slack
4
+ module Endpoint
5
+ module Api
6
+ #
7
+ # Checks API calling code.
8
+ #
9
+ # @option options [Object] :error
10
+ # Error response to return
11
+ # @option options [Object] :foo
12
+ # example property to return
13
+ # @see https://api.slack.com/methods/api.test
14
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/api.test.md
15
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/api.test.json
16
+ def api_test(options={})
17
+ post("api.test", options)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # This file was auto-generated by lib/generators/tasks/generate.rb
2
+
3
+ module Slack
4
+ module Endpoint
5
+ module Auth
6
+ #
7
+ # Checks authentication & identity.
8
+ #
9
+ # @see https://api.slack.com/methods/auth.test
10
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/auth.test.md
11
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/auth.test.json
12
+ def auth_test(options={})
13
+ post("auth.test", options)
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,213 @@
1
+ # This file was auto-generated by lib/generators/tasks/generate.rb
2
+
3
+ module Slack
4
+ module Endpoint
5
+ module Channels
6
+ #
7
+ # Archives a channel.
8
+ #
9
+ # @option options [channel] :channel
10
+ # Channel to archive
11
+ # @see https://api.slack.com/methods/channels.archive
12
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.archive.md
13
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.archive.json
14
+ def channels_archive(options={})
15
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
16
+ post("channels.archive", options)
17
+ end
18
+
19
+ #
20
+ # Creates a channel.
21
+ #
22
+ # @option options [Object] :name
23
+ # Name of channel to create
24
+ # @see https://api.slack.com/methods/channels.create
25
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.create.md
26
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.create.json
27
+ def channels_create(options={})
28
+ throw ArgumentError.new("Required arguments :name missing") if options[:name].nil?
29
+ post("channels.create", options)
30
+ end
31
+
32
+ #
33
+ # Fetches history of messages and events from a channel.
34
+ #
35
+ # @option options [channel] :channel
36
+ # Channel to fetch history for.
37
+ # @option options [timestamp] :latest
38
+ # Latest message timestamp to include in results.
39
+ # @option options [timestamp] :oldest
40
+ # Oldest message timestamp to include in results.
41
+ # @option options [Object] :count
42
+ # Number of messages to return, between 1 and 1000.
43
+ # @see https://api.slack.com/methods/channels.history
44
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.history.md
45
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.history.json
46
+ def channels_history(options={})
47
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
48
+ post("channels.history", options)
49
+ end
50
+
51
+ #
52
+ # Gets information about a channel.
53
+ #
54
+ # @option options [channel] :channel
55
+ # Channel to get info on
56
+ # @see https://api.slack.com/methods/channels.info
57
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.info.md
58
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.info.json
59
+ def channels_info(options={})
60
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
61
+ post("channels.info", options)
62
+ end
63
+
64
+ #
65
+ # Invites a user to a channel.
66
+ #
67
+ # @option options [channel] :channel
68
+ # Channel to invite user to.
69
+ # @option options [user] :user
70
+ # User to invite to channel.
71
+ # @see https://api.slack.com/methods/channels.invite
72
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.invite.md
73
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.invite.json
74
+ def channels_invite(options={})
75
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
76
+ throw ArgumentError.new("Required arguments :user missing") if options[:user].nil?
77
+ post("channels.invite", options)
78
+ end
79
+
80
+ #
81
+ # Joins a channel, creating it if needed.
82
+ #
83
+ # @option options [Object] :name
84
+ # Name of channel to join
85
+ # @see https://api.slack.com/methods/channels.join
86
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.join.md
87
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.join.json
88
+ def channels_join(options={})
89
+ throw ArgumentError.new("Required arguments :name missing") if options[:name].nil?
90
+ post("channels.join", options)
91
+ end
92
+
93
+ #
94
+ # Removes a user from a channel.
95
+ #
96
+ # @option options [channel] :channel
97
+ # Channel to remove user from.
98
+ # @option options [user] :user
99
+ # User to remove from channel.
100
+ # @see https://api.slack.com/methods/channels.kick
101
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.kick.md
102
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.kick.json
103
+ def channels_kick(options={})
104
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
105
+ throw ArgumentError.new("Required arguments :user missing") if options[:user].nil?
106
+ post("channels.kick", options)
107
+ end
108
+
109
+ #
110
+ # Leaves a channel.
111
+ #
112
+ # @option options [channel] :channel
113
+ # Channel to leave
114
+ # @see https://api.slack.com/methods/channels.leave
115
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.leave.md
116
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.leave.json
117
+ def channels_leave(options={})
118
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
119
+ post("channels.leave", options)
120
+ end
121
+
122
+ #
123
+ # Lists all channels in a Slack team.
124
+ #
125
+ # @option options [Object] :exclude_archived
126
+ # Don't return archived channels.
127
+ # @see https://api.slack.com/methods/channels.list
128
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.list.md
129
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.list.json
130
+ def channels_list(options={})
131
+ post("channels.list", options)
132
+ end
133
+
134
+ #
135
+ # Sets the read cursor in a channel.
136
+ #
137
+ # @option options [channel] :channel
138
+ # Channel to set reading cursor in.
139
+ # @option options [timestamp] :ts
140
+ # Timestamp of the most recently seen message.
141
+ # @see https://api.slack.com/methods/channels.mark
142
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.mark.md
143
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.mark.json
144
+ def channels_mark(options={})
145
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
146
+ throw ArgumentError.new("Required arguments :ts missing") if options[:ts].nil?
147
+ post("channels.mark", options)
148
+ end
149
+
150
+ #
151
+ # Renames a channel.
152
+ #
153
+ # @option options [channel] :channel
154
+ # Channel to rename
155
+ # @option options [Object] :name
156
+ # New name for channel.
157
+ # @see https://api.slack.com/methods/channels.rename
158
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.rename.md
159
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.rename.json
160
+ def channels_rename(options={})
161
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
162
+ throw ArgumentError.new("Required arguments :name missing") if options[:name].nil?
163
+ post("channels.rename", options)
164
+ end
165
+
166
+ #
167
+ # Sets the purpose for a channel.
168
+ #
169
+ # @option options [channel] :channel
170
+ # Channel to set the purpose of
171
+ # @option options [Object] :purpose
172
+ # The new purpose
173
+ # @see https://api.slack.com/methods/channels.setPurpose
174
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.setPurpose.md
175
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.setPurpose.json
176
+ def channels_setPurpose(options={})
177
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
178
+ throw ArgumentError.new("Required arguments :purpose missing") if options[:purpose].nil?
179
+ post("channels.setPurpose", options)
180
+ end
181
+
182
+ #
183
+ # Sets the topic for a channel.
184
+ #
185
+ # @option options [channel] :channel
186
+ # Channel to set the topic of
187
+ # @option options [Object] :topic
188
+ # The new topic
189
+ # @see https://api.slack.com/methods/channels.setTopic
190
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.setTopic.md
191
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.setTopic.json
192
+ def channels_setTopic(options={})
193
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
194
+ throw ArgumentError.new("Required arguments :topic missing") if options[:topic].nil?
195
+ post("channels.setTopic", options)
196
+ end
197
+
198
+ #
199
+ # Unarchives a channel.
200
+ #
201
+ # @option options [channel] :channel
202
+ # Channel to unarchive
203
+ # @see https://api.slack.com/methods/channels.unarchive
204
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.unarchive.md
205
+ # @see https://github.com/slackhq/slack-api-docs/blob/master/methods/channels.unarchive.json
206
+ def channels_unarchive(options={})
207
+ throw ArgumentError.new("Required arguments :channel missing") if options[:channel].nil?
208
+ post("channels.unarchive", options)
209
+ end
210
+
211
+ end
212
+ end
213
+ end