bullet_train-incoming_webhooks 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/app/models/webhooks/incoming/bullet_train_webhook.rb +2 -0
- data/lib/bullet_train/incoming_webhooks/engine.rb +9 -0
- data/lib/bullet_train/incoming_webhooks/scaffolders/incoming_webhooks_scaffolder.rb +40 -0
- data/lib/bullet_train/incoming_webhooks/version.rb +1 -1
- data/lib/scaffolding/incoming_webhooks_transformer.rb +98 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 841631804b153e610af2c14dcf42bb8d1eeab70553fb2bffbbb53ada8e220036
|
4
|
+
data.tar.gz: 2c4359e0e6a1b9b63d20a93e5861cf8b79089a04210fb1660890da8d758365b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8a194b7c27b8dbfe972143863fddb83c8be7bf5a1dd1fec25a49f5275e89ddc0918582d193cc237346abbf062c0fbdf34658837a4d789e96b8f5179a38d67c8
|
7
|
+
data.tar.gz: ae8331ebaf6460a674a06c03f0fc3c9c0f14e65219a351037ae48ea8c44b5f20cc966bceb0f400889b31c753e55775708424dc057ada9be3c9a5277c8fa041af
|
data/MIT-LICENSE
CHANGED
@@ -5,6 +5,7 @@ class Webhooks::Incoming::BulletTrainWebhook < ApplicationRecord
|
|
5
5
|
# there are many ways a service might ask you to verify the validity of a webhook.
|
6
6
|
# whatever that method is, you would implement it here.
|
7
7
|
def verify_authenticity
|
8
|
+
# 🚅 skip this section when scaffolding.
|
8
9
|
# trying to fix integration tests. if this fixes it, i don't know why puma won't accept another connection here.
|
9
10
|
return true if Rails.env.test?
|
10
11
|
|
@@ -19,6 +20,7 @@ class Webhooks::Incoming::BulletTrainWebhook < ApplicationRecord
|
|
19
20
|
|
20
21
|
# ensure that the payload on the server is the same as the payload we received.
|
21
22
|
JSON.parse(response.body) == data
|
23
|
+
# 🚅 stop any skipping we're doing now.
|
22
24
|
end
|
23
25
|
|
24
26
|
def process
|
@@ -1,6 +1,15 @@
|
|
1
|
+
require "bullet_train/incoming_webhooks/scaffolders/incoming_webhooks_scaffolder"
|
2
|
+
|
1
3
|
module BulletTrain
|
2
4
|
module IncomingWebhooks
|
3
5
|
class Engine < ::Rails::Engine
|
6
|
+
initializer "bullet_train.super_scaffolding.incoming_webhooks.templates.register_template_path" do |app|
|
7
|
+
# Register the base of this package with the Super Scaffolding engine.
|
8
|
+
BulletTrain::SuperScaffolding.template_paths << File.expand_path("../../../..", __FILE__)
|
9
|
+
BulletTrain::SuperScaffolding.scaffolders.merge!({
|
10
|
+
"incoming-webhooks" => "BulletTrain::IncomingWebhooks::Scaffolders::IncomingWebhooksScaffolder"
|
11
|
+
})
|
12
|
+
end
|
4
13
|
end
|
5
14
|
end
|
6
15
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "scaffolding/incoming_webhooks_transformer"
|
2
|
+
|
3
|
+
module BulletTrain
|
4
|
+
module IncomingWebhooks
|
5
|
+
module Scaffolders
|
6
|
+
class IncomingWebhooksScaffolder < SuperScaffolding::Scaffolder
|
7
|
+
def run
|
8
|
+
unless argv.count >= 1
|
9
|
+
puts ""
|
10
|
+
puts "🚅 usage: bin/super-scaffold incoming-webhooks SomeProvider"
|
11
|
+
puts ""
|
12
|
+
puts "E.g. prepare to receive system-level webhooks from ClickFunnels"
|
13
|
+
puts " bin/super-scaffold incoming-webhooks ClickFunnels"
|
14
|
+
puts ""
|
15
|
+
standard_protip
|
16
|
+
puts ""
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
provider_name = argv.shift
|
21
|
+
transformer = Scaffolding::IncomingWebhooksTransformer.new(provider_name)
|
22
|
+
|
23
|
+
`yes n | bin/rails g model webhooks_incoming_#{provider_name.tableize.singularize}_webhook data:jsonb processed_at:datetime verified_at:datetime`
|
24
|
+
|
25
|
+
transformer.scaffold_incoming_webhook
|
26
|
+
|
27
|
+
puts ""
|
28
|
+
puts "1. To receive webhooks in your development environment, you'll need to configure a tunnel.".yellow
|
29
|
+
puts " See http://bullettrain.co/docs/tunneling for more information.".yellow
|
30
|
+
puts ""
|
31
|
+
puts "2. Once you have a tunnel running, you can configure the provider to deliver webhooks to:".yellow
|
32
|
+
puts " https://your-tunnel.ngrok.io/webhooks/incoming/#{provider_name.tableize}_webhooks".yellow
|
33
|
+
puts ""
|
34
|
+
|
35
|
+
transformer.restart_server
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class Scaffolding::IncomingWebhooksTransformer < Scaffolding::Transformer
|
2
|
+
attr_accessor :provider_name
|
3
|
+
|
4
|
+
def initialize(provider_name, cli_options = {})
|
5
|
+
super("", "", cli_options)
|
6
|
+
self.provider_name = provider_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def scaffold_incoming_webhook
|
10
|
+
files = [
|
11
|
+
"./app/models/webhooks/incoming/bullet_train_webhook.rb",
|
12
|
+
"./app/controllers/webhooks/incoming/bullet_train_webhooks_controller.rb"
|
13
|
+
]
|
14
|
+
|
15
|
+
files.each do |name|
|
16
|
+
if File.directory?(resolve_template_path(name))
|
17
|
+
scaffold_directory(name)
|
18
|
+
else
|
19
|
+
scaffold_file(name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Rename files according to their provider name.
|
24
|
+
file_name_hook = "bullet_train_webhook"
|
25
|
+
new_model_file_name, new_controller_file_name = files.map { |file| file.gsub(file_name_hook, replacement_for(file_name_hook)) }
|
26
|
+
File.rename("./app/models/webhooks/incoming/bullet_train_webhook.rb", new_model_file_name)
|
27
|
+
File.rename("./app/controllers/webhooks/incoming/bullet_train_webhooks_controller.rb", new_controller_file_name)
|
28
|
+
|
29
|
+
# Since we eject the model from this repository, we don't need the
|
30
|
+
# extra model generated by `rails g model` (just the migration).
|
31
|
+
File.delete("./app/models/webhooks_incoming_#{replacement_for(file_name_hook)}.rb")
|
32
|
+
|
33
|
+
# Set up the model's `verify_authenticity` method to return `true`.
|
34
|
+
model_file_lines = File.readlines(new_model_file_name)
|
35
|
+
comment_lines = [
|
36
|
+
"# You can implement your authenticity verification logic in either\n",
|
37
|
+
"# the newly scaffolded model or controller for your incoming webhooks.\n"
|
38
|
+
]
|
39
|
+
lines_to_ignore = [
|
40
|
+
" # there are many ways a service might ask you to verify the validity of a webhook.\n",
|
41
|
+
" # whatever that method is, you would implement it here.\n"
|
42
|
+
]
|
43
|
+
|
44
|
+
model_file_lines = File.readlines(new_model_file_name)
|
45
|
+
new_model_file_lines = File.open(new_model_file_name).map.with_index do |line, idx|
|
46
|
+
if line.match?("def verify_authenticity")
|
47
|
+
indentation = Scaffolding::BlockManipulator.indentation_of(idx, model_file_lines)
|
48
|
+
new_comment_lines = comment_lines.map { |comment_line| "#{indentation}#{comment_line}" }.join
|
49
|
+
|
50
|
+
new_comment_lines +
|
51
|
+
"#{line}" \
|
52
|
+
"#{indentation} true\n"
|
53
|
+
elsif lines_to_ignore.include?(line)
|
54
|
+
next
|
55
|
+
else
|
56
|
+
line
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
Scaffolding::FileManipulator.write(new_model_file_name, new_model_file_lines)
|
61
|
+
|
62
|
+
# Apply new routes
|
63
|
+
begin
|
64
|
+
[
|
65
|
+
"config/routes.rb",
|
66
|
+
# "config/routes/api/v1.rb"
|
67
|
+
].each do |routes_file|
|
68
|
+
# Since the webhooks routes don't live under a parent resource, we can't use the `apply` method to apply routes.
|
69
|
+
routes_manipulator = Scaffolding::RoutesFileManipulator.new(routes_file, "", "")
|
70
|
+
resources_line = " resources :#{replacement_for("bullet_train_webhooks")}"
|
71
|
+
new_routes_lines = Scaffolding::BlockManipulator.insert(resources_line, lines: routes_manipulator.lines, after: "namespace :incoming")
|
72
|
+
Scaffolding::FileManipulator.write(routes_file, new_routes_lines)
|
73
|
+
end
|
74
|
+
rescue BulletTrain::SuperScaffolding::CannotFindParentResourceException => exception
|
75
|
+
add_additional_step :red, "We were not able to generate the routes for your Incoming Webhook automatically because: \"#{exception.message}\" You'll need to add them manually, which admittedly can be complicated. See https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/ for guidance. 🙇🏻♂️"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def transform_string(string)
|
80
|
+
[
|
81
|
+
"Webhooks::Incoming::BulletTrainWebhook"
|
82
|
+
].each do |needle|
|
83
|
+
string = string.gsub(needle, replacement_for(needle))
|
84
|
+
end
|
85
|
+
string
|
86
|
+
end
|
87
|
+
|
88
|
+
def replacement_for(string)
|
89
|
+
case string
|
90
|
+
when "bullet_train_webhook"
|
91
|
+
"#{provider_name.tableize.singularize}_webhook"
|
92
|
+
when "bullet_train_webhooks"
|
93
|
+
"#{provider_name.tableize.singularize}_webhooks"
|
94
|
+
when "Webhooks::Incoming::BulletTrainWebhook"
|
95
|
+
"Webhooks::Incoming::#{provider_name}Webhook"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-incoming_webhooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0
|
27
27
|
description: Bullet Train Incoming Webhooks
|
28
28
|
email:
|
29
29
|
- andrew.culver@gmail.com
|
@@ -43,7 +43,9 @@ files:
|
|
43
43
|
- config/routes.rb
|
44
44
|
- lib/bullet_train/incoming_webhooks.rb
|
45
45
|
- lib/bullet_train/incoming_webhooks/engine.rb
|
46
|
+
- lib/bullet_train/incoming_webhooks/scaffolders/incoming_webhooks_scaffolder.rb
|
46
47
|
- lib/bullet_train/incoming_webhooks/version.rb
|
48
|
+
- lib/scaffolding/incoming_webhooks_transformer.rb
|
47
49
|
- lib/tasks/bullet_train/incoming_webhooks_tasks.rake
|
48
50
|
homepage: https://github.com/bullet-train-co/bullet_train-incoming_webhooks
|
49
51
|
licenses:
|
@@ -66,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
68
|
- !ruby/object:Gem::Version
|
67
69
|
version: '0'
|
68
70
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
71
|
+
rubygems_version: 3.3.7
|
70
72
|
signing_key:
|
71
73
|
specification_version: 4
|
72
74
|
summary: Bullet Train Incoming Webhooks
|