4
4
* An unofficial PHP client library for accessing the official Todoist REST API.
5
5
*
6
6
* @author Fabian Beiner <fb@fabianbeiner.de>
7
- * @license MIT
7
+ * @license https://opensource.org/licenses/MIT MIT
8
+ * @version 0.6.0 <2018-03-06>
8
9
* @link https://github.com/FabianBeiner/Todoist-PHP-API-Library
9
- * @version 0.5.0 <2018-03-02>
10
10
*/
11
11
12
12
namespace FabianBeiner \Todoist ;
@@ -40,11 +40,6 @@ class Todoist
40
40
*/
41
41
private $ client ;
42
42
43
- /**
44
- * @var string Default URL query.
45
- */
46
- private $ tokenQuery ;
47
-
48
43
/**
49
44
* Todoist constructor.
50
45
*
@@ -60,23 +55,30 @@ public function __construct($apiToken)
60
55
}
61
56
$ this ->apiToken = trim ($ apiToken );
62
57
63
- // Create a default query for the token.
64
- $ this ->tokenQuery = http_build_query ([
65
- 'token ' => $ this ->apiToken
66
- ],
67
- null ,
68
- '& ' ,
69
- PHP_QUERY_RFC3986 );
70
-
71
58
// Create a Guzzle client.
72
59
$ this ->client = new Client ([
73
60
'base_uri ' => $ this ->restApiUrl ,
74
- 'headers ' => [ ' X-Request-Id ' => $ this ->generateV4GUID ()] ,
61
+ 'headers ' => $ this ->createHeaders () ,
75
62
'http_errors ' => false ,
76
63
'timeout ' => 5
77
64
]);
78
65
}
79
66
67
+ /**
68
+ * Helper function (introduced by @balazscsaba2006), to easily define
69
+ * Guzzle (cURL) headers.
70
+ *
71
+ * @return array Guzzle headers.
72
+ */
73
+ protected function createHeaders (): array
74
+ {
75
+ return [
76
+ 'Authorization ' => sprintf ('Bearer %s ' , $ this ->apiToken ),
77
+ 'X-Request-Id ' => $ this ->generateV4GUID (),
78
+ 'Accept-Encoding ' => 'gzip '
79
+ ];
80
+ }
81
+
80
82
/**
81
83
* Generate a v4 GUID string.
82
84
*
@@ -85,7 +87,7 @@ public function __construct($apiToken)
85
87
*
86
88
* @return string A v4 GUID.
87
89
*/
88
- private function generateV4GUID ()
90
+ private function generateV4GUID (): string
89
91
{
90
92
if (function_exists ('com_create_guid ' ) === true ) {
91
93
return trim (com_create_guid (), '{} ' );
0 commit comments