|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace LaravelSixConnex; |
|
5
|
|
|
|
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
|
|
8
|
|
|
class SixConnexApi |
|
9
|
|
|
{ |
|
10
|
|
|
protected string $clientDomain; |
|
11
|
|
|
|
|
12
|
|
|
protected string $username; |
|
13
|
|
|
|
|
14
|
|
|
protected string $password; |
|
15
|
|
|
|
|
16
|
|
|
protected string $topLevelDomain; |
|
17
|
|
|
|
|
18
|
|
|
protected bool $ssl; |
|
19
|
|
|
|
|
20
|
|
|
protected bool $production; |
|
21
|
|
|
|
|
22
|
|
|
protected array $guzzle; |
|
23
|
|
|
|
|
24
|
10 |
|
public function __construct(string $clientDomain, string $username, string $password, array $options = []) |
|
25
|
|
|
{ |
|
26
|
10 |
|
$this->clientDomain = $clientDomain; |
|
27
|
10 |
|
$this->username = $username; |
|
28
|
10 |
|
$this->password = $password; |
|
29
|
|
|
|
|
30
|
10 |
|
$this->topLevelDomain = (string) ($options['top_level_domain'] ?? 'com'); |
|
31
|
10 |
|
$this->ssl = (bool) ($options['ssl'] ?? true); |
|
32
|
10 |
|
$this->production = (bool) ($options['production'] ?? true); |
|
33
|
10 |
|
$this->guzzle = $options['guzzle'] ?? []; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
3 |
|
public function isProduction(): bool |
|
37
|
|
|
{ |
|
38
|
3 |
|
return $this->production; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param bool $production |
|
43
|
|
|
* |
|
44
|
|
|
* @return $this |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function env(bool $production = true): self |
|
47
|
|
|
{ |
|
48
|
1 |
|
$this->production = $production; |
|
49
|
|
|
|
|
50
|
1 |
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Base url |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $path |
|
57
|
|
|
* |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
10 |
|
public function url(string $path = ''): string |
|
61
|
|
|
{ |
|
62
|
10 |
|
$middle = $this->production ? '6connex' : '6connexstage'; |
|
63
|
10 |
|
$protocol = $this->ssl ? 'https' : 'http'; |
|
64
|
|
|
|
|
65
|
10 |
|
$base = "{$protocol}://{$this->clientDomain}.{$middle}.{$this->topLevelDomain}"; |
|
66
|
10 |
|
if ($path && !Str::startsWith($path, '/')) { |
|
67
|
1 |
|
$path = "/$path"; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
10 |
|
return "{$base}{$path}"; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Link to testing page |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function testApiUrl(): string |
|
78
|
|
|
{ |
|
79
|
1 |
|
return $this->url('publicapi/test-apis'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
6 |
|
public function usersRequest(?string $apiCall = null, ?array $options = null): ApiRequest |
|
83
|
|
|
{ |
|
84
|
6 |
|
$request = new ApiRequest( |
|
85
|
6 |
|
$this->username, |
|
86
|
6 |
|
$this->password, |
|
87
|
6 |
|
$this->url('/publicapi/users/executeAPIcall'), |
|
88
|
6 |
|
[ 'guzzle' => $this->guzzle, ] |
|
89
|
6 |
|
); |
|
90
|
6 |
|
if ($apiCall) { |
|
91
|
1 |
|
$request->setApiCall($apiCall); |
|
92
|
|
|
} |
|
93
|
6 |
|
if ($options) { |
|
94
|
1 |
|
$request->addOption($options); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
6 |
|
return $request; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|