Skip to content

Commit 2692773

Browse files
jwrightdblock
authored andcommitted
Adds views.publish method (#303)
1 parent 2175a02 commit 2692773

File tree

16 files changed

+165
-18
lines changed

16 files changed

+165
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [#293](https://github.com/slack-ruby/slack-ruby-client/pull/293): Rubocop auto-correct and comprehensive todo - [@jcraigk](https://github.com/jcraigk).
44
* [#297](https://github.com/slack-ruby/slack-ruby-client/pull/297): Various Rubocop fixes - [@jcraigk](https://github.com/jcraigk).
55
* [#298](https://github.com/slack-ruby/slack-ruby-client/pull/298): Add `admin.apps`, `admin.app.requests` and `views` endpoints - [@jmanian](https://github.com/jmanian).
6+
* [#302](https://github.com/slack-ruby/slack-ruby-client/pull/302): Add `oauth.v2.access` and `views.published` endpoints - [@jwright](https://github.com/jwright).
67
* Your contribution here.
78

89
### 0.14.4 (2019/7/28)

bin/commands.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
require 'commands/migration'
2828
require 'commands/mpim'
2929
require 'commands/oauth'
30+
require 'commands/oauth_v2'
3031
require 'commands/pins'
3132
require 'commands/reactions'
3233
require 'commands/reminders'

bin/commands/oauth_v2.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
# This file was auto-generated by lib/tasks/web.rake
3+
4+
desc 'OauthV2 methods.'
5+
command 'oauth_v2' do |g|
6+
g.desc 'Exchanges a temporary OAuth verifier code for an access token.'
7+
g.long_desc %( Exchanges a temporary OAuth verifier code for an access token. )
8+
g.command 'access' do |c|
9+
c.flag 'code', desc: 'The code param returned via the OAuth callback.'
10+
c.flag 'client_id', desc: 'Issued when you created your application.'
11+
c.flag 'client_secret', desc: 'Issued when you created your application.'
12+
c.flag 'redirect_uri', desc: 'This must match the originally submitted URI (if one was sent).'
13+
c.action do |_global_options, options, _args|
14+
puts JSON.dump($client.oauth_v2_access(options))
15+
end
16+
end
17+
end

bin/commands/reactions.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
g.desc 'Adds a reaction to an item.'
77
g.long_desc %( Adds a reaction to an item. )
88
g.command 'add' do |c|
9-
c.flag 'name', desc: 'Reaction (emoji) name.'
109
c.flag 'channel', desc: 'Channel where the message to add reaction to was posted.'
11-
c.flag 'file', desc: "File to add reaction to. Now that file threads work the way you'd expect, this argument is deprecated. Specify the timestamp and channel of the message associated with a file instead."
12-
c.flag 'file_comment', desc: "File comment to add reaction to. Now that file threads work the way you'd expect, this argument is deprecated. Specify the timestamp and channel of the message associated with a file instead."
10+
c.flag 'name', desc: 'Reaction (emoji) name.'
1311
c.flag 'timestamp', desc: 'Timestamp of the message to add reaction to.'
1412
c.action do |_global_options, options, _args|
1513
puts JSON.dump($client.reactions_add(options))

bin/commands/views.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,28 @@
77
g.long_desc %( Open a view for a user. )
88
g.command 'open' do |c|
99
c.flag 'trigger_id', desc: 'Exchange a trigger to post to the user.'
10-
c.flag 'view', desc: 'The view payload. This must be a JSON-encoded string.'
10+
c.flag 'view', desc: 'A view payload. This must be a JSON-encoded string.'
1111
c.action do |_global_options, options, _args|
1212
puts JSON.dump($client.views_open(options))
1313
end
1414
end
1515

16+
g.desc 'Publish a static view for a User.'
17+
g.long_desc %( Publish a static view for a User. )
18+
g.command 'publish' do |c|
19+
c.flag 'user_id', desc: 'id of the user you want publish a view to.'
20+
c.flag 'view', desc: 'A view payload. This must be a JSON-encoded string.'
21+
c.flag 'hash', desc: 'A string that represents view state to protect against possible race conditions.'
22+
c.action do |_global_options, options, _args|
23+
puts JSON.dump($client.views_publish(options))
24+
end
25+
end
26+
1627
g.desc 'Push a view onto the stack of a root view.'
1728
g.long_desc %( Push a view onto the stack of a root view. )
1829
g.command 'push' do |c|
1930
c.flag 'trigger_id', desc: 'Exchange a trigger to post to the user.'
20-
c.flag 'view', desc: 'The view payload. This must be a JSON-encoded string.'
31+
c.flag 'view', desc: 'A view payload. This must be a JSON-encoded string.'
2132
c.action do |_global_options, options, _args|
2233
puts JSON.dump($client.views_push(options))
2334
end
@@ -26,7 +37,7 @@
2637
g.desc 'Update an existing view.'
2738
g.long_desc %( Update an existing view. )
2839
g.command 'update' do |c|
29-
c.flag 'view', desc: 'The view payload. This must be a JSON-encoded string.'
40+
c.flag 'view', desc: 'A view payload This must be a JSON-encoded string.'
3041
c.flag 'external_id', desc: 'A unique identifier of the view set by the developer. Must be unique for all views on a team. Max length of 255 characters. Either view_id or external_id is required.'
3142
c.flag 'hash', desc: 'A string that represents view state to protect against possible race conditions.'
3243
c.flag 'view_id', desc: 'A unique identifier of the view to be updated. Either view_id or external_id is required.'

lib/slack/web/api/endpoints.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
require_relative 'endpoints/migration'
2828
require_relative 'endpoints/mpim'
2929
require_relative 'endpoints/oauth'
30+
require_relative 'endpoints/oauth_v2'
3031
require_relative 'endpoints/pins'
3132
require_relative 'endpoints/reactions'
3233
require_relative 'endpoints/reminders'
@@ -77,6 +78,7 @@ module Endpoints
7778
include Migration
7879
include Mpim
7980
include Oauth
81+
include OauthV2
8082
include Pins
8183
include Reactions
8284
include Reminders
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
# This file was auto-generated by lib/tasks/web.rake
3+
4+
module Slack
5+
module Web
6+
module Api
7+
module Endpoints
8+
module OauthV2
9+
#
10+
# Exchanges a temporary OAuth verifier code for an access token.
11+
#
12+
# @option options [Object] :code
13+
# The code param returned via the OAuth callback.
14+
# @option options [Object] :client_id
15+
# Issued when you created your application.
16+
# @option options [Object] :client_secret
17+
# Issued when you created your application.
18+
# @option options [Object] :redirect_uri
19+
# This must match the originally submitted URI (if one was sent).
20+
# @see https://api.slack.com/methods/oauth.v2.access
21+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/oauth.v2/oauth.v2.access.json
22+
def oauth_v2_access(options = {})
23+
throw ArgumentError.new('Required arguments :code missing') if options[:code].nil?
24+
post('oauth.v2.access', options)
25+
end
26+
end
27+
end
28+
end
29+
end
30+
end

lib/slack/web/api/endpoints/pins.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Pins
1717
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/pins/pins.add.json
1818
def pins_add(options = {})
1919
throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
20+
throw ArgumentError.new('Required arguments :timestamp missing') if options[:timestamp].nil?
2021
options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
2122
post('pins.add', options)
2223
end

lib/slack/web/api/endpoints/reactions.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@ module Reactions
99
#
1010
# Adds a reaction to an item.
1111
#
12-
# @option options [Object] :name
13-
# Reaction (emoji) name.
1412
# @option options [channel] :channel
1513
# Channel where the message to add reaction to was posted.
16-
# @option options [file] :file
17-
# File to add reaction to. Now that file threads work the way you'd expect, this argument is deprecated. Specify the timestamp and channel of the message associated with a file instead.
18-
# @option options [Object] :file_comment
19-
# File comment to add reaction to. Now that file threads work the way you'd expect, this argument is deprecated. Specify the timestamp and channel of the message associated with a file instead.
14+
# @option options [Object] :name
15+
# Reaction (emoji) name.
2016
# @option options [Object] :timestamp
2117
# Timestamp of the message to add reaction to.
2218
# @see https://api.slack.com/methods/reactions.add
2319
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/reactions/reactions.add.json
2420
def reactions_add(options = {})
21+
throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
2522
throw ArgumentError.new('Required arguments :name missing') if options[:name].nil?
23+
throw ArgumentError.new('Required arguments :timestamp missing') if options[:timestamp].nil?
2624
options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
2725
post('reactions.add', options)
2826
end

lib/slack/web/api/endpoints/views.rb

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Views
1212
# @option options [Object] :trigger_id
1313
# Exchange a trigger to post to the user.
1414
# @option options [Object] :view
15-
# The view payload. This must be a JSON-encoded string.
15+
# A view payload. This must be a JSON-encoded string.
1616
# @see https://api.slack.com/methods/views.open
1717
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/views/views.open.json
1818
def views_open(options = {})
@@ -26,13 +26,35 @@ def views_open(options = {})
2626
post('views.open', options)
2727
end
2828

29+
#
30+
# Publish a static view for a User.
31+
#
32+
# @option options [Object] :user_id
33+
# id of the user you want publish a view to.
34+
# @option options [Object] :view
35+
# A view payload. This must be a JSON-encoded string.
36+
# @option options [Object] :hash
37+
# A string that represents view state to protect against possible race conditions.
38+
# @see https://api.slack.com/methods/views.publish
39+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/views/views.publish.json
40+
def views_publish(options = {})
41+
throw ArgumentError.new('Required arguments :user_id missing') if options[:user_id].nil?
42+
throw ArgumentError.new('Required arguments :view missing') if options[:view].nil?
43+
if options.key?(:view)
44+
view = options[:view]
45+
view = JSON.dump(view) unless view.is_a?(String)
46+
options = options.merge(view: view)
47+
end
48+
post('views.publish', options)
49+
end
50+
2951
#
3052
# Push a view onto the stack of a root view.
3153
#
3254
# @option options [Object] :trigger_id
3355
# Exchange a trigger to post to the user.
3456
# @option options [Object] :view
35-
# The view payload. This must be a JSON-encoded string.
57+
# A view payload. This must be a JSON-encoded string.
3658
# @see https://api.slack.com/methods/views.push
3759
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/views/views.push.json
3860
def views_push(options = {})
@@ -50,7 +72,7 @@ def views_push(options = {})
5072
# Update an existing view.
5173
#
5274
# @option options [Object] :view
53-
# The view payload. This must be a JSON-encoded string.
75+
# A view payload This must be a JSON-encoded string.
5476
# @option options [Object] :external_id
5577
# A unique identifier of the view set by the developer. Must be unique for all views on a team. Max length of 255 characters. Either view_id or external_id is required.
5678
# @option options [Object] :hash

0 commit comments

Comments
 (0)