Class: Webhooks::Incoming::BulletTrainWebhook
- Inherits:
-
Object
- Object
- Webhooks::Incoming::BulletTrainWebhook
- Includes:
- Webhook
- Defined in:
- app/models/webhooks/incoming/bullet_train_webhook.rb
Instance Method Summary collapse
- #process ⇒ Object
-
#verify_authenticity ⇒ Object
there are many ways a service might ask you to verify the validity of a webhook.
Instance Method Details
#process ⇒ Object
26 27 |
# File 'app/models/webhooks/incoming/bullet_train_webhook.rb', line 26 def process end |
#verify_authenticity ⇒ Object
there are many ways a service might ask you to verify the validity of a webhook. whatever that method is, you would implement it here.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/webhooks/incoming/bullet_train_webhook.rb', line 7 def verify_authenticity # 🚅 skip this section when scaffolding. # trying to fix integration tests. if this fixes it, i don't know why puma won't accept another connection here. return true if Rails.env.test? uri = URI.parse(api_v1_webhooks_outgoing_event_url(data["event_id"])) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == "https" request = Net::HTTP::Get.new(uri.path) request.add_field("Content-Type", "application/json") # TODO We need to adjust the way we set up authentication here. # request.basic_auth ENV["BULLET_TRAIN_API_KEY"], ENV["BULLET_TRAIN_API_SECRET"] response = http.request(request) # ensure that the payload on the server is the same as the payload we received. JSON.parse(response.body) == data # 🚅 stop any skipping we're doing now. end |