bullet_train-incoming_webhooks 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 57c272275c23c8cdf38dd1ad65deff709a804c40a4d778873baab4a577f20e0a
4
+ data.tar.gz: 1f6c895cc943637d94058adb4d310ff993f10fd21e507ba23c6e492c10d50580
5
+ SHA512:
6
+ metadata.gz: b2f3246b99cb476a30bd3d93d7220235dad2d4739a66180b7839a2172868d2943f70c14c8665fec37659f9fc8f288abfce3be6247d7ae7c3d54481cba693dd22
7
+ data.tar.gz: db23de4338e3707de7b95969da8762eec5f97e7c1d6cde1d9c48079a2ac25717ce9f76e5a5e1c670fd664795481e4ebb862a526b913a5f5028c6be119351d7af
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Bullet Train, Inc.
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 ADDED
@@ -0,0 +1,28 @@
1
+ # BulletTrain::IncomingWebhooks
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "bullet_train-incoming_webhooks"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install bullet_train-incoming_webhooks
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ class Webhooks::Incoming::BulletTrainWebhooksController < Webhooks::Incoming::WebhooksController
2
+ def create
3
+ Webhooks::Incoming::BulletTrainWebhook.create(data: JSON.parse(request.body.read)).process_async
4
+ render json: {status: "OK"}, status: :created
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ class Webhooks::Incoming::WebhooksController < ApplicationController
2
+ skip_before_action :verify_authenticity_token
3
+ layout false
4
+ end
@@ -0,0 +1,7 @@
1
+ class Webhooks::Incoming::WebhookProcessingJob < ApplicationJob
2
+ queue_as :default
3
+
4
+ def perform(webhook)
5
+ webhook.verify_and_process
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ class Webhooks::Incoming::BulletTrainWebhook < ApplicationRecord
2
+ include Webhooks::Incoming::Webhook
3
+ include Rails.application.routes.url_helpers
4
+
5
+ # there are many ways a service might ask you to verify the validity of a webhook.
6
+ # whatever that method is, you would implement it here.
7
+ def verify_authenticity
8
+ # trying to fix integration tests. if this fixes it, i don't know why puma won't accept another connection here.
9
+ return true if Rails.env.test?
10
+
11
+ uri = URI.parse(api_v1_webhooks_outgoing_event_url(data["event_id"]))
12
+ http = Net::HTTP.new(uri.host, uri.port)
13
+ http.use_ssl = true if uri.scheme == "https"
14
+ request = Net::HTTP::Get.new(uri.path)
15
+ request.add_field("Content-Type", "application/json")
16
+ # TODO We need to adjust the way we set up authentication here.
17
+ # request.basic_auth ENV["BULLET_TRAIN_API_KEY"], ENV["BULLET_TRAIN_API_SECRET"]
18
+ response = http.request(request)
19
+
20
+ # ensure that the payload on the server is the same as the payload we received.
21
+ JSON.parse(response.body) == data
22
+ end
23
+
24
+ def process
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ module Webhooks::Incoming::Webhook
2
+ def verify_authenticity
3
+ raise "you must either implement `verify_authenticity` in #{self.class.name} or perform verification and set `verified_at` in #{self.class.name}sController."
4
+ end
5
+
6
+ def verified?
7
+ unless verified_at
8
+ touch(:verified_at) if verify_authenticity
9
+ end
10
+ verified_at.present?
11
+ end
12
+
13
+ def process_async
14
+ Webhooks::Incoming::WebhookProcessingJob.perform_later(self)
15
+ end
16
+
17
+ def processed?
18
+ processed_at.present?
19
+ end
20
+
21
+ def mark_processed
22
+ touch(:processed_at)
23
+ end
24
+
25
+ def verify_and_process
26
+ return if processed?
27
+ if verified?
28
+ process
29
+ mark_processed
30
+ end
31
+ end
32
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,6 @@
1
+ module BulletTrain
2
+ module IncomingWebhooks
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module BulletTrain
2
+ module IncomingWebhooks
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "bullet_train/incoming_webhooks/version"
2
+ require "bullet_train/incoming_webhooks/engine"
3
+
4
+ module BulletTrain
5
+ module IncomingWebhooks
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bullet_train_incoming_webhooks do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bullet_train-incoming_webhooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Culver
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 6.0.0
27
+ description: Bullet Train Incoming Webhooks
28
+ email:
29
+ - andrew.culver@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/config/bullet_train_incoming_webhooks_manifest.js
38
+ - app/controllers/webhooks/incoming/bullet_train_webhooks_controller.rb
39
+ - app/controllers/webhooks/incoming/webhooks_controller.rb
40
+ - app/jobs/webhooks/incoming/webhook_processing_job.rb
41
+ - app/models/webhooks/incoming/bullet_train_webhook.rb
42
+ - app/models/webhooks/incoming/webhook.rb
43
+ - config/routes.rb
44
+ - lib/bullet_train/incoming_webhooks.rb
45
+ - lib/bullet_train/incoming_webhooks/engine.rb
46
+ - lib/bullet_train/incoming_webhooks/version.rb
47
+ - lib/tasks/bullet_train/incoming_webhooks_tasks.rake
48
+ homepage: https://github.com/bullet-train-co/bullet_train-incoming_webhooks
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/bullet-train-co/bullet_train-incoming_webhooks
53
+ source_code_uri: https://github.com/bullet-train-co/bullet_train-incoming_webhooks
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.2.22
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Bullet Train Incoming Webhooks
73
+ test_files: []