chatops-controller 3.1.1 → 4.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
  SHA256:
3
- metadata.gz: bfa9aaf207f8e2c9d248c44161d4cdcfeb40b3d57d7615118225b05764d0f376
4
- data.tar.gz: 705859bc646744e42768e68798a70221f38c3b7e03bac19920d8faa23b8473db
3
+ metadata.gz: 8597b8cef3aa55e16d0ed7f906dafaa1a0bd696de64f242e0ea3c41198b3be1a
4
+ data.tar.gz: 596ace61f59f6839ed2da67f8567fbe2d0ef02782652a6824ec2e3d584b8b0c5
5
5
  SHA512:
6
- metadata.gz: 660ac4d838d2cbc0277cba86c0dccf405165b63ab01a9f732d78be1d3807aa923432110486fba0f3bb11fc9e1bc65eb82997cb69842e3c49dfef49431046e9f1
7
- data.tar.gz: 2ecef6d65a13c27a6b1d7f287b4967893761aa520ce58dc5e37884e880427e3f0c9cfc04a4ac4a8029728572cd2adfdd8b2a7cc7ff1ff2cb0372731a4e3a8cf3
6
+ metadata.gz: ca8640d6f9531fa1af6887a0725e3237e3d52d9837d19d1ccfe542e8216525cfb187d2b794314ce9e53e9794c460016d6a5b1f7058abe374ac8ccde50d11ca9b
7
+ data.tar.gz: d1a43adf71fb993fea5b2678dfc96029031c953053237c6bf3203569ef181a61f26708ebd0283868dae8684bb83c060c3457da0b7ce1077463d0e6c10651a316
@@ -27,10 +27,7 @@ module Chatops
27
27
  end
28
28
 
29
29
  def process(*args)
30
- scrubbed_params = jsonrpc_params.except(
31
- :user, :mention_slug, :method, :controller, :action, :params, :room_id)
32
-
33
- scrubbed_params.each { |k, v| params[k] = v }
30
+ setup_params!
34
31
 
35
32
  if params[:chatop].present?
36
33
  params[:action] = params[:chatop]
@@ -40,7 +37,7 @@ module Chatops
40
37
  end
41
38
  end
42
39
 
43
- super *args
40
+ super(*args)
44
41
  rescue AbstractController::ActionNotFound
45
42
  return jsonrpc_method_not_found
46
43
  end
@@ -52,8 +49,27 @@ module Chatops
52
49
 
53
50
  protected
54
51
 
52
+ def setup_params!
53
+ json_body.each do |key, value|
54
+ next if params.has_key? key
55
+ params[key] = value
56
+ end
57
+
58
+ @jsonrpc_params = params.delete(:params) if params.has_key? :params
59
+
60
+ self.params = params.permit(:action, :chatop, :controller, :id, :mention_slug, :method, :room_id, :user)
61
+ end
62
+
55
63
  def jsonrpc_params
56
- params["params"] || {}
64
+ @jsonrpc_params ||= ActionController::Parameters.new
65
+ end
66
+
67
+ def json_body
68
+ hash = {}
69
+ if request.content_type =~ %r/\Aapplication\/json\Z/i
70
+ hash = ActiveSupport::JSON.decode(request.raw_post) || {}
71
+ end
72
+ hash.with_indifferent_access
57
73
  end
58
74
 
59
75
  # `options` supports any of the optional fields documented
@@ -50,14 +50,14 @@ module Chatops::Controller::TestCaseHelpers
50
50
 
51
51
  named_params, command = extract_named_params(message)
52
52
 
53
- matcher = matchers.find { |matcher| matcher["regex"].match(command) }
53
+ matcher = matchers.find { |m| m["regex"].match(command) }
54
54
 
55
55
  raise NoMatchingCommandRegex.new("No command matches '#{command}'") unless matcher
56
56
 
57
57
  match_data = matcher["regex"].match(command)
58
58
  jsonrpc_params = named_params.dup
59
59
  matcher["params"].each do |param|
60
- jsonrpc_params[param] = match_data[param.to_sym]
60
+ jsonrpc_params[param] ||= match_data[param.to_sym]
61
61
  end
62
62
  jsonrpc_params.merge!(user: user, room_id: room_id, mention_slug: user)
63
63
  chatop matcher["name"].to_sym, jsonrpc_params
@@ -1,3 +1,3 @@
1
1
  module ChatopsController
2
- VERSION = "3.1.1"
2
+ VERSION = "4.0.0"
3
3
  end
@@ -14,8 +14,8 @@ describe ActionController::Base, type: :controller do
14
14
  chatop :wcid,
15
15
  /(?:where can i deploy|wcid)(?: (?<app>\S+))?/,
16
16
  "where can i deploy?" do
17
- return jsonrpc_invalid_params("I need nope, sorry") if params[:app] == "nope"
18
- jsonrpc_success "You can deploy #{params["app"]} just fine."
17
+ return jsonrpc_invalid_params("I need nope, sorry") if jsonrpc_params[:app] == "nope"
18
+ jsonrpc_success "You can deploy #{jsonrpc_params["app"]} just fine."
19
19
  end
20
20
 
21
21
  chatop :foobar,
@@ -35,7 +35,7 @@ describe ActionController::Base, type: :controller do
35
35
  end
36
36
 
37
37
  def ensure_app_given
38
- return jsonrpc_invalid_params("I need an app, every time") unless params[:app].present?
38
+ return jsonrpc_invalid_params("I need an app, every time") unless jsonrpc_params[:app].present?
39
39
  end
40
40
  end
41
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatops-controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Lavender
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-09-14 00:00:00.000000000 Z
13
+ date: 2018-09-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails