bullet_train-outgoing_webhooks 1.0.0 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +11 -26
  4. data/Rakefile +5 -11
  5. data/app/assets/config/bullet_train_outgoing_webhooks_manifest.js +0 -0
  6. data/app/controllers/account/webhooks/outgoing/deliveries_controller.rb +79 -0
  7. data/app/controllers/account/webhooks/outgoing/delivery_attempts_controller.rb +80 -0
  8. data/app/controllers/account/webhooks/outgoing/endpoints_controller.rb +79 -0
  9. data/app/controllers/api/v1/webhooks/outgoing/deliveries_endpoint.rb +63 -0
  10. data/app/controllers/api/v1/webhooks/outgoing/delivery_attempts_endpoint.rb +65 -0
  11. data/app/controllers/api/v1/webhooks/outgoing/endpoints_endpoint.rb +119 -0
  12. data/app/jobs/webhooks/outgoing/delivery_job.rb +7 -0
  13. data/{lib → app}/models/concerns/webhooks/outgoing/issuing_model.rb +6 -14
  14. data/{lib → app}/models/concerns/webhooks/outgoing/team_support.rb +0 -0
  15. data/{lib → app}/models/webhooks/outgoing/delivery.rb +18 -1
  16. data/{lib → app}/models/webhooks/outgoing/delivery_attempt.rb +17 -1
  17. data/{lib → app}/models/webhooks/outgoing/endpoint.rb +15 -5
  18. data/{lib → app}/models/webhooks/outgoing/event.rb +3 -3
  19. data/{lib → app}/models/webhooks/outgoing/event_type.rb +4 -6
  20. data/{lib → app}/models/webhooks/outgoing.rb +0 -3
  21. data/app/models/webhooks.rb +5 -0
  22. data/app/serializers/api/v1/webhooks/outgoing/delivery_attempt_serializer.rb +16 -0
  23. data/app/serializers/api/v1/webhooks/outgoing/delivery_serializer.rb +14 -0
  24. data/app/serializers/api/v1/webhooks/outgoing/endpoint_serializer.rb +14 -0
  25. data/app/views/account/webhooks/outgoing/deliveries/_breadcrumbs.html.erb +8 -0
  26. data/app/views/account/webhooks/outgoing/deliveries/_delivery.json.jbuilder +10 -0
  27. data/app/views/account/webhooks/outgoing/deliveries/_form.html.erb +21 -0
  28. data/app/views/account/webhooks/outgoing/deliveries/_index.html.erb +73 -0
  29. data/app/views/account/webhooks/outgoing/deliveries/_menu_item.html.erb +10 -0
  30. data/app/views/account/webhooks/outgoing/deliveries/_success_indicator.html.erb +7 -0
  31. data/app/views/account/webhooks/outgoing/deliveries/edit.html.erb +12 -0
  32. data/app/views/account/webhooks/outgoing/deliveries/index.html.erb +6 -0
  33. data/app/views/account/webhooks/outgoing/deliveries/index.json.jbuilder +1 -0
  34. data/app/views/account/webhooks/outgoing/deliveries/new.html.erb +12 -0
  35. data/app/views/account/webhooks/outgoing/deliveries/show.html.erb +37 -0
  36. data/app/views/account/webhooks/outgoing/deliveries/show.json.jbuilder +1 -0
  37. data/app/views/account/webhooks/outgoing/delivery_attempts/_breadcrumbs.html.erb +8 -0
  38. data/app/views/account/webhooks/outgoing/delivery_attempts/_delivery_attempt.json.jbuilder +12 -0
  39. data/app/views/account/webhooks/outgoing/delivery_attempts/_form.html.erb +22 -0
  40. data/app/views/account/webhooks/outgoing/delivery_attempts/_index.html.erb +69 -0
  41. data/app/views/account/webhooks/outgoing/delivery_attempts/_menu_item.html.erb +10 -0
  42. data/app/views/account/webhooks/outgoing/delivery_attempts/_success_indicator.html.erb +7 -0
  43. data/app/views/account/webhooks/outgoing/delivery_attempts/edit.html.erb +12 -0
  44. data/app/views/account/webhooks/outgoing/delivery_attempts/index.html.erb +6 -0
  45. data/app/views/account/webhooks/outgoing/delivery_attempts/index.json.jbuilder +1 -0
  46. data/app/views/account/webhooks/outgoing/delivery_attempts/new.html.erb +12 -0
  47. data/app/views/account/webhooks/outgoing/delivery_attempts/show.html.erb +32 -0
  48. data/app/views/account/webhooks/outgoing/delivery_attempts/show.json.jbuilder +1 -0
  49. data/app/views/account/webhooks/outgoing/endpoints/_breadcrumbs.html.erb +8 -0
  50. data/app/views/account/webhooks/outgoing/endpoints/_endpoint.json.jbuilder +10 -0
  51. data/app/views/account/webhooks/outgoing/endpoints/_form.html.erb +21 -0
  52. data/app/views/account/webhooks/outgoing/endpoints/_index.html.erb +62 -0
  53. data/app/views/account/webhooks/outgoing/endpoints/_menu_item.html.erb +10 -0
  54. data/app/views/account/webhooks/outgoing/endpoints/edit.html.erb +12 -0
  55. data/app/views/account/webhooks/outgoing/endpoints/index.html.erb +6 -0
  56. data/app/views/account/webhooks/outgoing/endpoints/index.json.jbuilder +1 -0
  57. data/app/views/account/webhooks/outgoing/endpoints/new.html.erb +12 -0
  58. data/app/views/account/webhooks/outgoing/endpoints/show.html.erb +42 -0
  59. data/app/views/account/webhooks/outgoing/endpoints/show.json.jbuilder +1 -0
  60. data/config/locales/en/webhooks/outgoing/deliveries.en.yml +112 -0
  61. data/config/locales/en/webhooks/outgoing/delivery_attempts.en.yml +122 -0
  62. data/config/locales/en/webhooks/outgoing/endpoints.en.yml +108 -0
  63. data/config/locales/en/webhooks/outgoing/events.en.yml +10 -0
  64. data/config/routes.rb +18 -0
  65. data/db/migrate/20180420013127_create_webhooks_outgoing_endpoints.rb +10 -0
  66. data/db/migrate/20180420013505_create_webhooks_outgoing_endpoint_event_types.rb +10 -0
  67. data/db/migrate/20180420013852_create_webhooks_outgoing_event_types.rb +9 -0
  68. data/db/migrate/20180420014623_create_webhooks_outgoing_events.rb +12 -0
  69. data/db/migrate/20180420021016_create_webhooks_outgoing_deliveries.rb +11 -0
  70. data/db/migrate/20180420022027_add_team_to_webhooks_outgoing_events.rb +5 -0
  71. data/db/migrate/20180420165345_create_webhooks_outgoing_delivery_attempts.rb +11 -0
  72. data/db/migrate/20180420172112_add_error_message_to_webhooks_outgoing_delivery_attempt.rb +6 -0
  73. data/db/migrate/20181012234232_add_name_to_webhooks_outgoing_endpoints.rb +5 -0
  74. data/db/migrate/20181013030208_add_delivered_at_to_webhooks_outgoing_deliveries.rb +5 -0
  75. data/db/migrate/20181013165056_add_uuid_to_webhooks_outgoing_events.rb +5 -0
  76. data/db/migrate/20181013174539_add_payload_to_webhooks_outgoing_events.rb +5 -0
  77. data/db/migrate/20181013192951_add_attempt_number_to_webhooks_outgoing_delivery_attempts.rb +5 -0
  78. data/db/migrate/20210805060451_change_body_to_data_on_webhooks_outgoing_events.rb +5 -0
  79. data/db/migrate/20211126230846_add_event_type_ids_to_webhooks_outgoing_endpoints.rb +5 -0
  80. data/db/migrate/20211126230847_migrate_event_type_ids_on_webhooks_outgoing_endpoints.rb +8 -0
  81. data/db/migrate/20211127013539_remove_event_type_from_webhooks_outgoing_events.rb +5 -0
  82. data/db/migrate/20211127013800_add_new_event_type_id_to_webhooks_outgoing_events.rb +5 -0
  83. data/db/migrate/20211127014001_migrate_event_types_on_webhooks_outgoing_events.rb +10 -0
  84. data/db/migrate/20211127015712_drop_webhooks_outgoing_endpoint_event_types.rb +9 -0
  85. data/db/migrate/20211127015713_drop_webhooks_outgoing_event_types.rb +9 -0
  86. data/lib/bullet_train/outgoing_webhooks/engine.rb +13 -0
  87. data/lib/bullet_train/outgoing_webhooks/version.rb +1 -3
  88. data/lib/bullet_train/outgoing_webhooks.rb +2 -17
  89. data/lib/tasks/bullet_train/outgoing_webhooks_tasks.rake +4 -0
  90. metadata +97 -60
  91. data/.standard.yml +0 -2
  92. data/CHANGELOG.md +0 -5
  93. data/CODE_OF_CONDUCT.md +0 -84
  94. data/Gemfile +0 -12
  95. data/Gemfile.lock +0 -193
  96. data/LICENSE.txt +0 -21
  97. data/bin/console +0 -15
  98. data/bin/setup +0 -8
  99. data/lib/models/concerns/webhooks/outgoing/has_uuid.rb +0 -21
  100. data/lib/models/webhooks.rb +0 -2
  101. data/sig/bullet_train/outgoing_webhooks.rbs +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '07187a561c9a79ccbf549abeebb9698b0153fe826cc83a508250ae80b9cf9410'
4
- data.tar.gz: 50778e5e8d25388c414bae632db09c364a2612f8f089a54eddbf13c0bd570fdd
3
+ metadata.gz: e4186cf970999d91997f2410efeba593f422788cec8452978544796176d7ea47
4
+ data.tar.gz: 9700fff07690d45d249e966e29cd233f894b0f77fbffbc4cacf47a637ebb7be6
5
5
  SHA512:
6
- metadata.gz: 2ec9dab63edb091f2776fef944ade249d31e85bc79106ba5bbbc0fdcbffdcd8db8acb596815aa4b393a8cd84c9029d08f86b9ca5e62d836ba817877671a21aac
7
- data.tar.gz: e2a23369f030b68a7aa23411ed4c9281b6b4afd4ddf86cc33003bd3168dab82441b7017044fbbfa757f93a164d50c77ef22f8a5fda8829f15888ad5b51f413a7
6
+ metadata.gz: 7b971859d534310367961541028daef0b95286d02d1bbe202ac954228ed092dacf6180277193d8b4822547838c20d3d60a7efb0eab1e56160eecf48fe7ac6606
7
+ data.tar.gz: 268648e2e285ca1398f4b526529c6a7de6a8e8efd461e73fc68003dd579fb75a335a77d3b461efd9d46b906aebc93bdd0f3fdbd6f8191dd60774deada233c491
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Andrew Culver
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,43 +1,28 @@
1
1
  # BulletTrain::OutgoingWebhooks
2
+ Short description and motivation.
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bullet_train/outgoing_webhooks`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
4
+ ## Usage
5
+ How to use my plugin.
6
6
 
7
7
  ## Installation
8
-
9
8
  Add this line to your application's Gemfile:
10
9
 
11
10
  ```ruby
12
- gem 'bullet_train-outgoing_webhooks'
11
+ gem "bullet_train-outgoing_webhooks"
13
12
  ```
14
13
 
15
14
  And then execute:
16
-
17
- $ bundle install
15
+ ```bash
16
+ $ bundle
17
+ ```
18
18
 
19
19
  Or install it yourself as:
20
-
21
- $ gem install bullet_train-outgoing_webhooks
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
20
+ ```bash
21
+ $ gem install bullet_train-outgoing_webhooks
22
+ ```
32
23
 
33
24
  ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bullet_train-outgoing_webhooks. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/bullet_train-outgoing_webhooks/blob/main/CODE_OF_CONDUCT.md).
25
+ Contribution directions go here.
36
26
 
37
27
  ## License
38
-
39
28
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the BulletTrain::OutgoingWebhooks project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bullet_train-outgoing_webhooks/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,14 +1,8 @@
1
- # frozen_string_literal: true
1
+ require "bundler/setup"
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
10
- end
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
11
5
 
12
- require "standard/rake"
6
+ load "rails/tasks/statistics.rake"
13
7
 
14
- task default: %i[test standard]
8
+ require "bundler/gem_tasks"
@@ -0,0 +1,79 @@
1
+ class Account::Webhooks::Outgoing::DeliveriesController < Account::ApplicationController
2
+ account_load_and_authorize_resource :delivery, through: :endpoint, through_association: :deliveries
3
+
4
+ # GET /account/webhooks/outgoing/endpoints/:endpoint_id/deliveries
5
+ # GET /account/webhooks/outgoing/endpoints/:endpoint_id/deliveries.json
6
+ def index
7
+ # if you only want these objects shown on their parent's show page, uncomment this:
8
+ redirect_to [:account, @endpoint]
9
+ end
10
+
11
+ # GET /account/webhooks/outgoing/deliveries/:id
12
+ # GET /account/webhooks/outgoing/deliveries/:id.json
13
+ def show
14
+ end
15
+
16
+ # GET /account/webhooks/outgoing/endpoints/:endpoint_id/deliveries/new
17
+ def new
18
+ end
19
+
20
+ # GET /account/webhooks/outgoing/deliveries/:id/edit
21
+ def edit
22
+ end
23
+
24
+ # POST /account/webhooks/outgoing/endpoints/:endpoint_id/deliveries
25
+ # POST /account/webhooks/outgoing/endpoints/:endpoint_id/deliveries.json
26
+ def create
27
+ respond_to do |format|
28
+ if @delivery.save
29
+ format.html { redirect_to [:account, @endpoint, :deliveries], notice: I18n.t("webhooks/outgoing/deliveries.notifications.created") }
30
+ format.json { render :show, status: :created, location: [:account, @delivery] }
31
+ else
32
+ format.html { render :new, status: :unprocessable_entity }
33
+ format.json { render json: @delivery.errors, status: :unprocessable_entity }
34
+ end
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT /account/webhooks/outgoing/deliveries/:id
39
+ # PATCH/PUT /account/webhooks/outgoing/deliveries/:id.json
40
+ def update
41
+ respond_to do |format|
42
+ if @delivery.update(delivery_params)
43
+ format.html { redirect_to [:account, @delivery], notice: I18n.t("webhooks/outgoing/deliveries.notifications.updated") }
44
+ format.json { render :show, status: :ok, location: [:account, @delivery] }
45
+ else
46
+ format.html { render :edit, status: :unprocessable_entity }
47
+ format.json { render json: @delivery.errors, status: :unprocessable_entity }
48
+ end
49
+ end
50
+ end
51
+
52
+ # DELETE /account/webhooks/outgoing/deliveries/:id
53
+ # DELETE /account/webhooks/outgoing/deliveries/:id.json
54
+ def destroy
55
+ @delivery.destroy
56
+ respond_to do |format|
57
+ format.html { redirect_to [:account, @endpoint, :deliveries], notice: I18n.t("webhooks/outgoing/deliveries.notifications.destroyed") }
58
+ format.json { head :no_content }
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ # Never trust parameters from the scary internet, only allow the white list through.
65
+ def delivery_params
66
+ strong_params = params.require(:webhooks_outgoing_delivery).permit(
67
+ :event_id,
68
+ :endpoint_url,
69
+ :delivered_at,
70
+ # 🚅 super scaffolding will insert new fields above this line.
71
+ # 🚅 super scaffolding will insert new arrays above this line.
72
+ )
73
+
74
+ assign_date_and_time(strong_params, :delivered_at)
75
+ # 🚅 super scaffolding will insert processing for new fields above this line.
76
+
77
+ strong_params
78
+ end
79
+ end
@@ -0,0 +1,80 @@
1
+ class Account::Webhooks::Outgoing::DeliveryAttemptsController < Account::ApplicationController
2
+ account_load_and_authorize_resource :delivery_attempt, through: :delivery, through_association: :delivery_attempts
3
+
4
+ # GET /account/webhooks/outgoing/deliveries/:delivery_id/delivery_attempts
5
+ # GET /account/webhooks/outgoing/deliveries/:delivery_id/delivery_attempts.json
6
+ def index
7
+ # if you only want these objects shown on their parent's show page, uncomment this:
8
+ redirect_to [:account, @delivery]
9
+ end
10
+
11
+ # GET /account/webhooks/outgoing/delivery_attempts/:id
12
+ # GET /account/webhooks/outgoing/delivery_attempts/:id.json
13
+ def show
14
+ end
15
+
16
+ # GET /account/webhooks/outgoing/deliveries/:delivery_id/delivery_attempts/new
17
+ def new
18
+ end
19
+
20
+ # GET /account/webhooks/outgoing/delivery_attempts/:id/edit
21
+ def edit
22
+ end
23
+
24
+ # POST /account/webhooks/outgoing/deliveries/:delivery_id/delivery_attempts
25
+ # POST /account/webhooks/outgoing/deliveries/:delivery_id/delivery_attempts.json
26
+ def create
27
+ respond_to do |format|
28
+ if @delivery_attempt.save
29
+ format.html { redirect_to [:account, @delivery, :delivery_attempts], notice: I18n.t("webhooks/outgoing/delivery_attempts.notifications.created") }
30
+ format.json { render :show, status: :created, location: [:account, @delivery_attempt] }
31
+ else
32
+ format.html { render :new, status: :unprocessable_entity }
33
+ format.json { render json: @delivery_attempt.errors, status: :unprocessable_entity }
34
+ end
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT /account/webhooks/outgoing/delivery_attempts/:id
39
+ # PATCH/PUT /account/webhooks/outgoing/delivery_attempts/:id.json
40
+ def update
41
+ respond_to do |format|
42
+ if @delivery_attempt.update(delivery_attempt_params)
43
+ format.html { redirect_to [:account, @delivery_attempt], notice: I18n.t("webhooks/outgoing/delivery_attempts.notifications.updated") }
44
+ format.json { render :show, status: :ok, location: [:account, @delivery_attempt] }
45
+ else
46
+ format.html { render :edit, status: :unprocessable_entity }
47
+ format.json { render json: @delivery_attempt.errors, status: :unprocessable_entity }
48
+ end
49
+ end
50
+ end
51
+
52
+ # DELETE /account/webhooks/outgoing/delivery_attempts/:id
53
+ # DELETE /account/webhooks/outgoing/delivery_attempts/:id.json
54
+ def destroy
55
+ @delivery_attempt.destroy
56
+ respond_to do |format|
57
+ format.html { redirect_to [:account, @delivery, :delivery_attempts], notice: I18n.t("webhooks/outgoing/delivery_attempts.notifications.destroyed") }
58
+ format.json { head :no_content }
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ # Never trust parameters from the scary internet, only allow the white list through.
65
+ def delivery_attempt_params
66
+ strong_params = params.require(:webhooks_outgoing_delivery_attempt).permit(
67
+ :response_code,
68
+ :response_body,
69
+ :response_message,
70
+ :error_message,
71
+ :attempt_number,
72
+ # 🚅 super scaffolding will insert new fields above this line.
73
+ # 🚅 super scaffolding will insert new arrays above this line.
74
+ )
75
+
76
+ # 🚅 super scaffolding will insert processing for new fields above this line.
77
+
78
+ strong_params
79
+ end
80
+ end
@@ -0,0 +1,79 @@
1
+ class Account::Webhooks::Outgoing::EndpointsController < Account::ApplicationController
2
+ account_load_and_authorize_resource :endpoint, through: :team, through_association: :webhooks_outgoing_endpoints
3
+
4
+ # GET /account/teams/:team_id/webhooks/outgoing/endpoints
5
+ # GET /account/teams/:team_id/webhooks/outgoing/endpoints.json
6
+ def index
7
+ # if you only want these objects shown on their parent's show page, uncomment this:
8
+ # redirect_to [:account, @team]
9
+ end
10
+
11
+ # GET /account/webhooks/outgoing/endpoints/:id
12
+ # GET /account/webhooks/outgoing/endpoints/:id.json
13
+ def show
14
+ end
15
+
16
+ # GET /account/teams/:team_id/webhooks/outgoing/endpoints/new
17
+ def new
18
+ end
19
+
20
+ # GET /account/webhooks/outgoing/endpoints/:id/edit
21
+ def edit
22
+ end
23
+
24
+ # POST /account/teams/:team_id/webhooks/outgoing/endpoints
25
+ # POST /account/teams/:team_id/webhooks/outgoing/endpoints.json
26
+ def create
27
+ respond_to do |format|
28
+ if @endpoint.save
29
+ format.html { redirect_to [:account, @team, :webhooks_outgoing_endpoints], notice: I18n.t("webhooks/outgoing/endpoints.notifications.created") }
30
+ format.json { render :show, status: :created, location: [:account, @endpoint] }
31
+ else
32
+ format.html { render :new, status: :unprocessable_entity }
33
+ format.json { render json: @endpoint.errors, status: :unprocessable_entity }
34
+ end
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT /account/webhooks/outgoing/endpoints/:id
39
+ # PATCH/PUT /account/webhooks/outgoing/endpoints/:id.json
40
+ def update
41
+ respond_to do |format|
42
+ if @endpoint.update(endpoint_params)
43
+ format.html { redirect_to [:account, @endpoint], notice: I18n.t("webhooks/outgoing/endpoints.notifications.updated") }
44
+ format.json { render :show, status: :ok, location: [:account, @endpoint] }
45
+ else
46
+ format.html { render :edit, status: :unprocessable_entity }
47
+ format.json { render json: @endpoint.errors, status: :unprocessable_entity }
48
+ end
49
+ end
50
+ end
51
+
52
+ # DELETE /account/webhooks/outgoing/endpoints/:id
53
+ # DELETE /account/webhooks/outgoing/endpoints/:id.json
54
+ def destroy
55
+ @endpoint.destroy
56
+ respond_to do |format|
57
+ format.html { redirect_to [:account, @team, :webhooks_outgoing_endpoints], notice: I18n.t("webhooks/outgoing/endpoints.notifications.destroyed") }
58
+ format.json { head :no_content }
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ # Never trust parameters from the scary internet, only allow the white list through.
65
+ def endpoint_params
66
+ strong_params = params.require(:webhooks_outgoing_endpoint).permit(
67
+ :name,
68
+ :url,
69
+ # 🚅 super scaffolding will insert new fields above this line.
70
+ event_type_ids: [],
71
+ # 🚅 super scaffolding will insert new arrays above this line.
72
+ )
73
+
74
+ assign_select_options(strong_params, :event_type_ids)
75
+ # 🚅 super scaffolding will insert processing for new fields above this line.
76
+
77
+ strong_params
78
+ end
79
+ end
@@ -0,0 +1,63 @@
1
+ class Api::V1::Webhooks::Outgoing::DeliveriesEndpoint < Api::V1::Root
2
+ helpers do
3
+ params :endpoint_id do
4
+ requires :endpoint_id, type: Integer, allow_blank: false, desc: "Endpoint ID"
5
+ end
6
+
7
+ params :id do
8
+ requires :id, type: Integer, allow_blank: false, desc: "Delivery ID"
9
+ end
10
+
11
+ params :delivery do
12
+ optional :event_id, type: String, desc: Api.heading(:event_id)
13
+ optional :endpoint_url, type: String, desc: Api.heading(:endpoint_url)
14
+ optional :delivered_at, type: DateTime, desc: Api.heading(:delivered_at)
15
+ # 🚅 super scaffolding will insert new fields above this line.
16
+ # 🚅 super scaffolding will insert new arrays above this line.
17
+
18
+ # 🚅 super scaffolding will insert processing for new fields above this line.
19
+ end
20
+ end
21
+
22
+ resource "webhooks/outgoing/endpoints", desc: Api.title(:collection_actions) do
23
+ after_validation do
24
+ load_and_authorize_api_resource Webhooks::Outgoing::Delivery
25
+ end
26
+
27
+ #
28
+ # INDEX
29
+ #
30
+
31
+ desc Api.title(:index), &Api.index_desc
32
+ params do
33
+ use :endpoint_id
34
+ end
35
+ oauth2
36
+ paginate per_page: 100
37
+ get "/:endpoint_id/deliveries" do
38
+ @paginated_deliveries = paginate @deliveries
39
+ render @paginated_deliveries, serializer: Api.serializer
40
+ end
41
+ end
42
+
43
+ resource "webhooks/outgoing/deliveries", desc: Api.title(:member_actions) do
44
+ after_validation do
45
+ load_and_authorize_api_resource Webhooks::Outgoing::Delivery
46
+ end
47
+
48
+ #
49
+ # SHOW
50
+ #
51
+
52
+ desc Api.title(:show), &Api.show_desc
53
+ params do
54
+ use :id
55
+ end
56
+ oauth2
57
+ route_param :id do
58
+ get do
59
+ render @delivery, serializer: Api.serializer
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,65 @@
1
+ class Api::V1::Webhooks::Outgoing::DeliveryAttemptsEndpoint < Api::V1::Root
2
+ helpers do
3
+ params :delivery_id do
4
+ requires :delivery_id, type: Integer, allow_blank: false, desc: "Delivery ID"
5
+ end
6
+
7
+ params :id do
8
+ requires :id, type: Integer, allow_blank: false, desc: "Delivery Attempt ID"
9
+ end
10
+
11
+ params :delivery_attempt do
12
+ optional :response_code, type: String, desc: Api.heading(:response_code)
13
+ optional :response_body, type: String, desc: Api.heading(:response_body)
14
+ optional :response_message, type: String, desc: Api.heading(:response_message)
15
+ optional :error_message, type: String, desc: Api.heading(:error_message)
16
+ optional :attempt_number, type: String, desc: Api.heading(:attempt_number)
17
+ # 🚅 super scaffolding will insert new fields above this line.
18
+ # 🚅 super scaffolding will insert new arrays above this line.
19
+
20
+ # 🚅 super scaffolding will insert processing for new fields above this line.
21
+ end
22
+ end
23
+
24
+ resource "webhooks/outgoing/deliveries", desc: Api.title(:collection_actions) do
25
+ after_validation do
26
+ load_and_authorize_api_resource Webhooks::Outgoing::DeliveryAttempt
27
+ end
28
+
29
+ #
30
+ # INDEX
31
+ #
32
+
33
+ desc Api.title(:index), &Api.index_desc
34
+ params do
35
+ use :delivery_id
36
+ end
37
+ oauth2
38
+ paginate per_page: 100
39
+ get "/:delivery_id/delivery_attempts" do
40
+ @paginated_delivery_attempts = paginate @delivery_attempts
41
+ render @paginated_delivery_attempts, serializer: Api.serializer
42
+ end
43
+ end
44
+
45
+ resource "webhooks/outgoing/delivery_attempts", desc: Api.title(:member_actions) do
46
+ after_validation do
47
+ load_and_authorize_api_resource Webhooks::Outgoing::DeliveryAttempt
48
+ end
49
+
50
+ #
51
+ # SHOW
52
+ #
53
+
54
+ desc Api.title(:show), &Api.show_desc
55
+ params do
56
+ use :id
57
+ end
58
+ oauth2
59
+ route_param :id do
60
+ get do
61
+ render @delivery_attempt, serializer: Api.serializer
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,119 @@
1
+ class Api::V1::Webhooks::Outgoing::EndpointsEndpoint < Api::V1::Root
2
+ helpers do
3
+ params :team_id do
4
+ requires :team_id, type: Integer, allow_blank: false, desc: "Team ID"
5
+ end
6
+
7
+ params :id do
8
+ requires :id, type: Integer, allow_blank: false, desc: "Endpoint ID"
9
+ end
10
+
11
+ params :endpoint do
12
+ optional :name, type: String, desc: Api.heading(:name)
13
+ optional :url, type: String, desc: Api.heading(:url)
14
+ # 🚅 super scaffolding will insert new fields above this line.
15
+ optional :event_type_ids, type: Array, desc: Api.heading(:event_type_ids)
16
+ # 🚅 super scaffolding will insert new arrays above this line.
17
+
18
+ # 🚅 super scaffolding will insert processing for new fields above this line.
19
+ end
20
+ end
21
+
22
+ resource "teams", desc: Api.title(:collection_actions) do
23
+ after_validation do
24
+ load_and_authorize_api_resource Webhooks::Outgoing::Endpoint
25
+ end
26
+
27
+ #
28
+ # INDEX
29
+ #
30
+
31
+ desc Api.title(:index), &Api.index_desc
32
+ params do
33
+ use :team_id
34
+ end
35
+ oauth2
36
+ paginate per_page: 100
37
+ get "/:team_id/webhooks/outgoing/endpoints" do
38
+ @paginated_endpoints = paginate @endpoints
39
+ render @paginated_endpoints, serializer: Api.serializer
40
+ end
41
+
42
+ #
43
+ # CREATE
44
+ #
45
+
46
+ desc Api.title(:create), &Api.create_desc
47
+ params do
48
+ use :team_id
49
+ use :endpoint
50
+ end
51
+ route_setting :api_resource_options, permission: :create
52
+ oauth2 "write"
53
+ post "/:team_id/webhooks/outgoing/endpoints" do
54
+ if @endpoint.save
55
+ render @endpoint, serializer: Api.serializer
56
+ else
57
+ record_not_saved @endpoint
58
+ end
59
+ end
60
+ end
61
+
62
+ resource "webhooks/outgoing/endpoints", desc: Api.title(:member_actions) do
63
+ after_validation do
64
+ load_and_authorize_api_resource Webhooks::Outgoing::Endpoint
65
+ end
66
+
67
+ #
68
+ # SHOW
69
+ #
70
+
71
+ desc Api.title(:show), &Api.show_desc
72
+ params do
73
+ use :id
74
+ end
75
+ oauth2
76
+ route_param :id do
77
+ get do
78
+ render @endpoint, serializer: Api.serializer
79
+ end
80
+ end
81
+
82
+ #
83
+ # UPDATE
84
+ #
85
+
86
+ desc Api.title(:update), &Api.update_desc
87
+ params do
88
+ use :id
89
+ use :endpoint
90
+ end
91
+ route_setting :api_resource_options, permission: :update
92
+ oauth2 "write"
93
+ route_param :id do
94
+ put do
95
+ if @endpoint.update(declared(params, include_missing: false))
96
+ render @endpoint, serializer: Api.serializer
97
+ else
98
+ record_not_saved @endpoint
99
+ end
100
+ end
101
+ end
102
+
103
+ #
104
+ # DESTROY
105
+ #
106
+
107
+ desc Api.title(:destroy), &Api.destroy_desc
108
+ params do
109
+ use :id
110
+ end
111
+ route_setting :api_resource_options, permission: :destroy
112
+ oauth2 "delete"
113
+ route_param :id do
114
+ delete do
115
+ render @endpoint.destroy, serializer: Api.serializer
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,7 @@
1
+ class Webhooks::Outgoing::DeliveryJob < ApplicationJob
2
+ queue_as :default
3
+
4
+ def perform(delivery)
5
+ delivery.deliver
6
+ end
7
+ end
@@ -13,29 +13,21 @@ module Webhooks::Outgoing::IssuingModel
13
13
  module ClassMethods
14
14
  end
15
15
 
16
- def webhooks_team
17
- send(team_association)
18
- end
19
-
20
- def team_association
21
- Webhooks::Outgoing.team_model.underscore.to_sym
22
- end
23
-
24
16
  def generate_webhook(action)
25
17
  # we can only generate webhooks for objects that return their team.
26
- return unless respond_to? team_association
18
+ return unless respond_to? :team
27
19
 
28
20
  # Try to find an event type definition for this action.
29
21
  event_type = Webhooks::Outgoing::EventType.find_by(id: "#{self.class.name.underscore}.#{action}")
30
22
 
31
23
  # If the event type is defined as one that people can be subscribed to,
32
24
  # and this object has a team where an associated outgoing webhooks endpoint could be registered.
33
- if event_type && webhooks_team
25
+ if event_type && team
34
26
 
35
27
  # Only generate an event record if an endpoint is actually listening for this event type.
36
- if webhooks_team.webhooks_outgoing_endpoints.listening_for_event_type_id(event_type.id).any?
28
+ if team.webhooks_outgoing_endpoints.listening_for_event_type_id(event_type.id).any?
37
29
  data = "Api::V1::#{self.class.name}Serializer".constantize.new(self).serializable_hash[:data]
38
- webhook = webhooks_team.webhooks_outgoing_events.create(event_type_id: event_type.id, subject: self, data: data)
30
+ webhook = team.webhooks_outgoing_events.create(event_type_id: event_type.id, subject: self, data: data)
39
31
  webhook.deliver
40
32
  end
41
33
  end
@@ -50,8 +42,8 @@ module Webhooks::Outgoing::IssuingModel
50
42
  end
51
43
 
52
44
  def generate_deleted_webhook
53
- return false unless respond_to?(team_association)
54
- return false if webhooks_team&.being_destroyed?
45
+ return false unless respond_to?(:team)
46
+ return false if team&.being_destroyed?
55
47
  generate_webhook("deleted")
56
48
  end
57
49
  end