-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhookreceiver.php
44 lines (32 loc) · 1.38 KB
/
webhookreceiver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
throw new Exception('This must be accessed via POST');
}
$apiKey = ''; // your BreweryDB API key
// checks to make sure that the request was actually sent from the BreweryDB API
$isValidRequest = sha1($apiKey . $_GET['nonce']) == $_GET['key'];
if ($isValidRequest) {
// this will be one of beer, brewery, location, guild, or event
$attribute = $_POST['attribute'];
// The corresponding beerId, breweryId, locationId,
// guildId, or eventId
// depending upon what the value of $attribute is
$attributeId = $_POST['attributeId'];
// The action that was taken on the attribute.
// Either insert, delete, or edit
$action = $_POST['action'];
// The subaction that was taken on the attribute.
// Either 'none' or various other options like
// 'socialaccount-update' or 'beer-add'
$subAction = $_POST['subAction'];
// Timestamp that the change was integrated
$timestamp = $_POST['timestamp'];
// Now you can take whatever action you need based
// on the information you received
// The best practice is to put this data in a queue
// somewhere locally for you to process it in an
// asynchronous manner so you don't get your webhoook
// disabled because it takes too long to respond.
} else {
throw new Exception('Key was not valid');
}