-
Notifications
You must be signed in to change notification settings - Fork 4
/
check.php
40 lines (32 loc) · 1.03 KB
/
check.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
<?php
require 'vendor/autoload.php';
require_once 'keys.php';
use GuzzleHttp\Client;
use Wunderlist\WunderlistClient as Wunderlist;
$guzzle = new Client(
[
'base_uri' => 'https://a.wunderlist.com/api/v1/',
'headers' => [
'Content-Type' => 'application/json',
'X-Client-ID' => $client_id,
'X-Access-Token' => $access_token,
]
]
);
$wunderlist = new Wunderlist($guzzle);
echo deliver($wunderlist);
function deliver($wunderlist) {
if (!isset($_POST['task_id']) || !isset($_POST['revision'])) {
return json_encode(['error' => 'Bad request']);
}
try {
$response = $wunderlist->completeTask($_POST['task_id'], $_POST['revision']);
if ($response->revision === (int) $_POST['revision'] + 1 && $response->completed === true) {
return json_encode(['completed' => true]);
}
return json_encode(['error' => 'Unknown error']);
}
catch (\Exception $e) {
return json_encode(['error' => $e->getMessage()]);
}
}