sinatra-slack 0.8.0 → 0.8.1

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
  SHA256:
3
- metadata.gz: 1001e651845588b445467b51c39c70088b645578db40e9a3ab8912fbca3627bb
4
- data.tar.gz: 7bfd5bb48ed346097648304703bb55a8976a99af2018788f2bbd683a64b113d8
3
+ metadata.gz: 66dde3da3ae5d04be459e5acc55cc5069d7f48c6a96b6e4a544ae47370cba42f
4
+ data.tar.gz: 4f523cffb4780a06a9a53c7e717c91b61aef670350ab83657fed29fcf8dbed75
5
5
  SHA512:
6
- metadata.gz: c7cd89a308c80e2d57c021e31a52ca345906b1807480eed6dc88ee1fd82a283899650d6c7920ff02b369155ce59e3364b646c6afb1e2abb99e2b54fe896c35ee
7
- data.tar.gz: 95cd9900d8bdc6d890b57319826da7d17b2538d1d12548f922ee2342a5f8127fc94a47d83e9a2e6b451934e15fd6b5698257e8dd917c4523ce88371dbe8f2d80
6
+ metadata.gz: 9e1521ea66b1bf106f9ba8da4377bbae740ec0cdf9f969d80e949f56d29a53b0d2def83e786b3afb1d7f3cb2cffddd86c3384fad269ec37bdd763cb0a9d86102
7
+ data.tar.gz: 4bc88b2b3410bb1b1c15fdbb32102fdaea86accef830bfbc0a03301f7a3f8675eef2985013656483cc69146d018a7352078d7324bc3a241791d5269f2ffe65e8
data/lib/sinatra/slack.rb CHANGED
@@ -24,6 +24,8 @@ module Sinatra
24
24
  set_endpoint(path, quick_reply) do
25
25
  signature = "#{command.command} #{command.text}"
26
26
  command_pattern = self.class.get_pattern(signature)
27
+ raise 'Command not defined' unless command_pattern
28
+
27
29
  request_params = command_pattern.params(signature).values
28
30
 
29
31
  {
@@ -38,6 +40,8 @@ module Sinatra
38
40
  def actions_endpoint(path, quick_reply: '')
39
41
  set_endpoint(path, quick_reply) do
40
42
  action_pattern = self.class.get_pattern(action.name)
43
+ raise 'Action not defined' unless action_pattern
44
+
41
45
  request_params = action_pattern.params(action.name).values || []
42
46
  request_params << action.value
43
47
 
@@ -88,19 +92,18 @@ module Sinatra
88
92
  define_method("#{path}_options", &block)
89
93
 
90
94
  settings.apost(path) do
91
- halt 401, 'Invalid Headers' unless authorized?
95
+ handle_with_rescue do
96
+ halt 401, 'Invalid Headers' unless authorized?
92
97
 
93
- get_options = self.class.instance_method "#{path}_options"
94
- options = get_options.bind(self).call
98
+ get_options = self.class.instance_method "#{path}_options"
99
+ options = get_options.bind(self).call
95
100
 
96
- halt 400 unless options
101
+ halt 400 unless options
97
102
 
98
- options[:quick_reply] = quick_reply
103
+ options[:quick_reply] = quick_reply
99
104
 
100
- handle_request(options)
101
- rescue StandardError => ex
102
- logger.error ex.full_message
103
- channel.send(slack_error_notification)
105
+ handle_request(options)
106
+ end
104
107
  end
105
108
  end
106
109
  end
@@ -35,16 +35,24 @@ module Sinatra
35
35
 
36
36
  def handle_request(request_handler:, request_params:, quick_reply: '...')
37
37
  EM.defer do
38
- deferred_message = request_handler.bind(self).call(*request_params)
39
- channel.send(deferred_message)
40
- rescue StandardError => ex
41
- logger.error ex.full_message
42
- channel.send(slack_error_notification)
38
+ handle_with_rescue do
39
+ deferred_message = request_handler.bind(self).call(*request_params)
40
+ channel.send(deferred_message)
41
+ end
43
42
  end
44
43
 
45
44
  body quick_reply
46
45
  end
47
46
 
47
+ def handle_with_rescue
48
+ return unless block_given?
49
+
50
+ yield
51
+ rescue StandardError => ex
52
+ logger.error ex.full_message
53
+ channel.send(slack_error_notification)
54
+ end
55
+
48
56
  # Checks for Slack defined HTTP headers
49
57
  # and computes the request signature (HMAC). If provided signature
50
58
  # is the same as the computed one, the request is valid.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sinatra
4
4
  module Slack
5
- VERSION = '0.8.0'
5
+ VERSION = '0.8.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nuno Namorado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-05 00:00:00.000000000 Z
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async_sinatra