2
2
3
3
/*
4
4
* Encore Digital Group - Planning Center PHP SDK
5
- * Copyright (c) 2023-2024 . Encore Digital Group
5
+ * Copyright (c) 2023-2025 . Encore Digital Group
6
6
*/
7
7
8
8
namespace EncoreDigitalGroup \PlanningCenter \Traits ;
9
9
10
10
use EncoreDigitalGroup \PlanningCenter \Objects \SdkObjects \ClientResponse ;
11
+ use EncoreDigitalGroup \PlanningCenter \Support \AuthType ;
11
12
use EncoreDigitalGroup \PlanningCenter \Support \PlanningCenterApiVersion ;
13
+ use EncoreDigitalGroup \StdLib \Objects \Support \Types \Str ;
12
14
use Illuminate \Http \Client \PendingRequest ;
13
15
use Illuminate \Http \Client \Response ;
14
16
use PHPGenesis \Http \HttpClient ;
@@ -18,22 +20,33 @@ trait HasPlanningCenterClient
18
20
{
19
21
protected const string HOSTNAME = "https://api.planningcenteronline.com " ;
20
22
23
+ /** @experimental This could change. Use with caution. */
24
+ protected const string X_PCO_API_VERSION_HEADER = "X-PCO-API-Version " ;
25
+
21
26
protected string $ clientId ;
22
27
protected string $ clientSecret ;
23
28
protected string $ apiVersion = "" ;
24
29
30
+ /** @experimental This could change. Use with caution. */
31
+ protected AuthType $ authType = AuthType::Basic;
32
+
25
33
public function __construct (?string $ clientId = null , ?string $ clientSecret = null )
26
34
{
27
- $ this ->clientId = $ clientId ?? "" ;
28
- $ this ->clientSecret = $ clientSecret ?? "" ;
35
+ $ this ->clientId = $ clientId ?? Str:: empty () ;
36
+ $ this ->clientSecret = $ clientSecret ?? Str:: empty () ;
29
37
30
38
new HttpClientBuilder ;
31
39
}
32
40
33
41
public function client (): PendingRequest
34
42
{
43
+ if ($ this ->authType == AuthType::Token) {
44
+ return HttpClient::withToken ($ this ->clientId )
45
+ ->withHeader (self ::X_PCO_API_VERSION_HEADER , $ this ->apiVersion );
46
+ }
47
+
35
48
return HttpClient::withBasicAuth ($ this ->clientId , $ this ->clientSecret )
36
- ->withHeader (" X-PCO-API-Version " , $ this ->apiVersion );
49
+ ->withHeader (self :: X_PCO_API_VERSION_HEADER , $ this ->apiVersion );
37
50
}
38
51
39
52
public function hostname (): string
@@ -48,6 +61,32 @@ public function setApiVersion(string $apiVersion): static
48
61
return $ this ;
49
62
}
50
63
64
+ /** @experimental This could change. Use with caution. */
65
+ public function setAuthType (AuthType $ authType ): static
66
+ {
67
+ $ this ->authType = $ authType ;
68
+
69
+ return $ this ;
70
+ }
71
+
72
+ /** @experimental This could change. Use with caution. */
73
+ public function withBasicAuth (string $ clientId = "" , string $ clientSecret = "" ): static
74
+ {
75
+ $ this ->clientId = $ clientId ;
76
+ $ this ->clientSecret = $ clientSecret ;
77
+
78
+ return $ this ->setAuthType (AuthType::Basic);
79
+ }
80
+
81
+ /** @experimental This could change. Use with caution. */
82
+ public function withToken (string $ token = "" ): static
83
+ {
84
+ $ this ->clientId = $ token ;
85
+ $ this ->clientSecret = Str::empty ();
86
+
87
+ return $ this ->setAuthType (AuthType::Token);
88
+ }
89
+
51
90
protected function processResponse (Response $ http ): ClientResponse
52
91
{
53
92
$ clientResponse = new ClientResponse ($ http );
0 commit comments