@@ -22,6 +22,7 @@ final class Client
22
22
private $ streamFactory ;
23
23
private $ apiKey ;
24
24
private $ rootUrl ;
25
+ private $ version ;
25
26
26
27
public function __construct (
27
28
ClientInterface $ http ,
@@ -46,6 +47,7 @@ public function __construct(
46
47
$ this ->streamFactory = $ streamFactory ;
47
48
$ this ->apiKey = $ config ["apiKey " ];
48
49
$ this ->rootUrl = $ config ["rootUrl " ] ?? "https://api.journy.io " ;
50
+ $ this ->version = \Composer \InstalledVersions::getVersion ('journy-io/sdk ' );
49
51
}
50
52
51
53
public static function withDefaults (string $ apiKey ): Client
@@ -56,6 +58,11 @@ public static function withDefaults(string $apiKey): Client
56
58
return new Client ($ http , $ factory , $ factory , ["apiKey " => $ apiKey ]);
57
59
}
58
60
61
+ private function withUserAgent (RequestInterface $ request ): RequestInterface
62
+ {
63
+ return $ request ->withAddedHeader ("user-agent " , "php-sdk/ " . $ this ->version );
64
+ }
65
+
59
66
private function withAuthentication (RequestInterface $ request ): RequestInterface
60
67
{
61
68
return $ request ->withAddedHeader ("x-api-key " , $ this ->apiKey );
@@ -125,9 +132,11 @@ public function getApiKeyDetails(): CallResult
125
132
{
126
133
$ response = $ this ->http ->sendRequest (
127
134
$ this ->withAuthentication (
128
- $ this ->requestFactory ->createRequest (
129
- "GET " ,
130
- new Uri ("{$ this ->rootUrl }/validate " )
135
+ $ this ->withUserAgent (
136
+ $ this ->requestFactory ->createRequest (
137
+ "GET " ,
138
+ new Uri ("{$ this ->rootUrl }/validate " )
139
+ )
131
140
)
132
141
)
133
142
);
@@ -171,9 +180,11 @@ public function getTrackingSnippet(string $domain): CallResult
171
180
$ encodedDomain = urlencode ($ domain );
172
181
$ response = $ this ->http ->sendRequest (
173
182
$ this ->withAuthentication (
174
- $ this ->requestFactory ->createRequest (
175
- "GET " ,
176
- new Uri ("{$ this ->rootUrl }/tracking/snippet?domain= {$ encodedDomain }" )
183
+ $ this ->withUserAgent (
184
+ $ this ->requestFactory ->createRequest (
185
+ "GET " ,
186
+ new Uri ("{$ this ->rootUrl }/tracking/snippet?domain= {$ encodedDomain }" )
187
+ )
177
188
)
178
189
)
179
190
);
@@ -287,13 +298,15 @@ public function addEvent(Event $event): CallResult
287
298
288
299
$ response = $ this ->http ->sendRequest (
289
300
$ this ->withAuthentication (
290
- $ this ->requestFactory
291
- ->createRequest (
292
- "POST " ,
293
- new Uri ("{$ this ->rootUrl }/events " )
294
- )
295
- ->withHeader ("content-type " , "application/json " )
296
- ->withBody ($ body )
301
+ $ this ->withUserAgent (
302
+ $ this ->requestFactory
303
+ ->createRequest (
304
+ "POST " ,
305
+ new Uri ("{$ this ->rootUrl }/events " )
306
+ )
307
+ ->withHeader ("content-type " , "application/json " )
308
+ ->withBody ($ body )
309
+ )
297
310
)
298
311
);
299
312
@@ -347,13 +360,15 @@ public function link(array $arguments): CallResult
347
360
348
361
$ response = $ this ->http ->sendRequest (
349
362
$ this ->withAuthentication (
350
- $ this ->requestFactory
351
- ->createRequest (
352
- "POST " ,
353
- new Uri ("{$ this ->rootUrl }/link " )
354
- )
355
- ->withHeader ("content-type " , "application/json " )
356
- ->withBody ($ body )
363
+ $ this ->withUserAgent (
364
+ $ this ->requestFactory
365
+ ->createRequest (
366
+ "POST " ,
367
+ new Uri ("{$ this ->rootUrl }/link " )
368
+ )
369
+ ->withHeader ("content-type " , "application/json " )
370
+ ->withBody ($ body )
371
+ )
357
372
)
358
373
);
359
374
@@ -455,13 +470,15 @@ public function upsertUser(array $user): CallResult
455
470
456
471
$ response = $ this ->http ->sendRequest (
457
472
$ this ->withAuthentication (
458
- $ this ->requestFactory
459
- ->createRequest (
460
- "POST " ,
461
- new Uri ("{$ this ->rootUrl }/users/upsert " )
462
- )
463
- ->withHeader ("content-type " , "application/json " )
464
- ->withBody ($ body )
473
+ $ this ->withUserAgent (
474
+ $ this ->requestFactory
475
+ ->createRequest (
476
+ "POST " ,
477
+ new Uri ("{$ this ->rootUrl }/users/upsert " )
478
+ )
479
+ ->withHeader ("content-type " , "application/json " )
480
+ ->withBody ($ body )
481
+ )
465
482
)
466
483
);
467
484
@@ -514,13 +531,15 @@ public function upsertAccount(array $account): CallResult
514
531
515
532
$ response = $ this ->http ->sendRequest (
516
533
$ this ->withAuthentication (
517
- $ this ->requestFactory
518
- ->createRequest (
519
- "POST " ,
520
- new Uri ("{$ this ->rootUrl }/accounts/upsert " )
521
- )
522
- ->withHeader ("content-type " , "application/json " )
523
- ->withBody ($ body )
534
+ $ this ->withUserAgent (
535
+ $ this ->requestFactory
536
+ ->createRequest (
537
+ "POST " ,
538
+ new Uri ("{$ this ->rootUrl }/accounts/upsert " )
539
+ )
540
+ ->withHeader ("content-type " , "application/json " )
541
+ ->withBody ($ body )
542
+ )
524
543
)
525
544
);
526
545
@@ -587,13 +606,15 @@ function (array $user) {
587
606
588
607
$ response = $ this ->http ->sendRequest (
589
608
$ this ->withAuthentication (
590
- $ this ->requestFactory
591
- ->createRequest (
592
- "POST " ,
593
- new Uri ("{$ this ->rootUrl }/accounts/users/add " )
594
- )
595
- ->withHeader ("content-type " , "application/json " )
596
- ->withBody ($ body )
609
+ $ this ->withUserAgent (
610
+ $ this ->requestFactory
611
+ ->createRequest (
612
+ "POST " ,
613
+ new Uri ("{$ this ->rootUrl }/accounts/users/add " )
614
+ )
615
+ ->withHeader ("content-type " , "application/json " )
616
+ ->withBody ($ body )
617
+ )
597
618
)
598
619
);
599
620
@@ -660,13 +681,15 @@ function (array $user) {
660
681
661
682
$ response = $ this ->http ->sendRequest (
662
683
$ this ->withAuthentication (
663
- $ this ->requestFactory
664
- ->createRequest (
665
- "POST " ,
666
- new Uri ("{$ this ->rootUrl }/accounts/users/remove " )
667
- )
668
- ->withHeader ("content-type " , "application/json " )
669
- ->withBody ($ body )
684
+ $ this ->withUserAgent (
685
+ $ this ->requestFactory
686
+ ->createRequest (
687
+ "POST " ,
688
+ new Uri ("{$ this ->rootUrl }/accounts/users/remove " )
689
+ )
690
+ ->withHeader ("content-type " , "application/json " )
691
+ ->withBody ($ body )
692
+ )
670
693
)
671
694
);
672
695
0 commit comments