Skip to content

Commit 54c09bb

Browse files
feat(api): manual updates
1 parent 9b8a942 commit 54c09bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1246
-225
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 19
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/sent%2Fsent-dm-2526b6ca490323393bd93f041268aa85f1d36bed4a639ecb3e72e7cd6f51e40d.yml
33
openapi_spec_hash: 9f1e88c960a9057b40df68c059b640b8
4-
config_hash: 094d0205ec5660f35d72c520c81ae8eb
4+
config_hash: 558220e713f3aff5906078014139c92d

README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ Parameters with a default value must be set by name.
3939
use SentDm\Client;
4040

4141
$client = new Client(
42-
customerAuthScheme: getenv(
43-
'SENT_DM_CUSTOMER_AUTH_SCHEME'
44-
) ?: 'My Customer Auth Scheme',
42+
apiKey: 'My API Key',
43+
senderID: 'My Sender ID',
44+
apiKey: getenv('SENT_DM_API_KEY') ?: 'My API Key',
45+
senderID: getenv('SENT_DM_SENDER_ID') ?: 'My Sender ID',
4546
);
4647

47-
$result = $client->templates->delete('REPLACE_ME');
48+
$result = $client->messages->sendToPhone(
49+
phoneNumber: '+1234567890',
50+
templateID: '7ba7b820-9dad-11d1-80b4-00c04fd430c8',
51+
xAPIKey: '',
52+
xSenderID: '00000000-0000-0000-0000-000000000000',
53+
);
4854

4955
var_dump($result);
5056
```
@@ -68,7 +74,12 @@ use SentDm\Core\Exceptions\RateLimitException;
6874
use SentDm\Core\Exceptions\APIStatusException;
6975

7076
try {
71-
$result = $client->templates->delete('REPLACE_ME');
77+
$result = $client->messages->sendToPhone(
78+
phoneNumber: '+1234567890',
79+
templateID: '7ba7b820-9dad-11d1-80b4-00c04fd430c8',
80+
xAPIKey: '',
81+
xSenderID: '00000000-0000-0000-0000-000000000000',
82+
);
7283
} catch (APIConnectionException $e) {
7384
echo "The server could not be reached", PHP_EOL;
7485
var_dump($e->getPrevious());
@@ -110,11 +121,19 @@ You can use the `maxRetries` option to configure or disable this:
110121
use SentDm\Client;
111122

112123
// Configure the default for all requests:
113-
$client = new Client(requestOptions: ['maxRetries' => 0]);
124+
$client = new Client(
125+
apiKey: 'My API Key',
126+
senderID: 'My Sender ID',
127+
requestOptions: ['maxRetries' => 0],
128+
);
114129

115130
// Or, configure per-request:
116-
$result = $client->templates->delete(
117-
'REPLACE_ME', requestOptions: ['maxRetries' => 5]
131+
$result = $client->messages->sendToPhone(
132+
phoneNumber: '+1234567890',
133+
templateID: '7ba7b820-9dad-11d1-80b4-00c04fd430c8',
134+
xAPIKey: '',
135+
xSenderID: '00000000-0000-0000-0000-000000000000',
136+
requestOptions: ['maxRetries' => 5],
118137
);
119138
```
120139

@@ -131,8 +150,11 @@ Note: the `extra*` parameters of the same name overrides the documented paramete
131150
```php
132151
<?php
133152

134-
$result = $client->templates->delete(
135-
'REPLACE_ME',
153+
$result = $client->messages->sendToPhone(
154+
phoneNumber: '+1234567890',
155+
templateID: '7ba7b820-9dad-11d1-80b4-00c04fd430c8',
156+
xAPIKey: '',
157+
xSenderID: '00000000-0000-0000-0000-000000000000',
136158
requestOptions: [
137159
'extraQueryParams' => ['my_query_parameter' => 'value'],
138160
'extraBodyParams' => ['my_body_parameter' => 'value'],

src/Client.php

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
use SentDm\Services\TemplatesService;
1616

1717
/**
18-
* @phpstan-import-type NormalizedRequest from \SentDm\Core\BaseClient
1918
* @phpstan-import-type RequestOpts from \SentDm\RequestOptions
2019
*/
2120
class Client extends BaseClient
2221
{
23-
public string $adminAuthScheme;
22+
public string $apiKey;
2423

25-
public string $customerAuthScheme;
24+
public string $senderID;
2625

2726
/**
2827
* @api
@@ -53,13 +52,13 @@ class Client extends BaseClient
5352
* @param RequestOpts|null $requestOptions
5453
*/
5554
public function __construct(
56-
?string $adminAuthScheme = null,
57-
?string $customerAuthScheme = null,
55+
?string $apiKey = null,
56+
?string $senderID = null,
5857
?string $baseUrl = null,
5958
RequestOptions|array|null $requestOptions = null,
6059
) {
61-
$this->adminAuthScheme = (string) ($adminAuthScheme ?? getenv('SENT_DM_ADMIN_AUTH_SCHEME'));
62-
$this->customerAuthScheme = (string) ($customerAuthScheme ?? getenv('SENT_DM_CUSTOMER_AUTH_SCHEME'));
60+
$this->apiKey = (string) ($apiKey ?? getenv('SENT_DM_API_KEY'));
61+
$this->senderID = (string) ($senderID ?? getenv('SENT_DM_SENDER_ID'));
6362

6463
$baseUrl ??= getenv('SENT_DM_BASE_URL') ?: 'https://api.sent.dm';
6564

@@ -95,56 +94,4 @@ public function __construct(
9594
$this->numberLookup = new NumberLookupService($this);
9695
$this->organizations = new OrganizationsService($this);
9796
}
98-
99-
/** @return array<string,string> */
100-
protected function authHeaders(): array
101-
{
102-
return [
103-
...$this->adminAuthenticationScheme(),
104-
...$this->customerAuthenticationScheme(),
105-
];
106-
}
107-
108-
/** @return array<string,string> */
109-
protected function adminAuthenticationScheme(): array
110-
{
111-
return $this->adminAuthScheme ? ['x-api-key' => $this->adminAuthScheme] : [
112-
];
113-
}
114-
115-
/** @return array<string,string> */
116-
protected function customerAuthenticationScheme(): array
117-
{
118-
return $this->customerAuthScheme ? [
119-
'x-sender-id' => $this->customerAuthScheme,
120-
] : [];
121-
}
122-
123-
/**
124-
* @internal
125-
*
126-
* @param string|list<string> $path
127-
* @param array<string,mixed> $query
128-
* @param array<string,string|int|list<string|int>|null> $headers
129-
* @param RequestOpts|null $opts
130-
*
131-
* @return array{NormalizedRequest, RequestOptions}
132-
*/
133-
protected function buildRequest(
134-
string $method,
135-
string|array $path,
136-
array $query,
137-
array $headers,
138-
mixed $body,
139-
RequestOptions|array|null $opts,
140-
): array {
141-
return parent::buildRequest(
142-
method: $method,
143-
path: $path,
144-
query: $query,
145-
headers: [...$this->authHeaders(), ...$headers],
146-
body: $body,
147-
opts: $opts,
148-
);
149-
}
15097
}

src/Contacts/ContactListParams.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
*
1515
* @see SentDm\Services\ContactsService::list()
1616
*
17-
* @phpstan-type ContactListParamsShape = array{page: int, pageSize: int}
17+
* @phpstan-type ContactListParamsShape = array{
18+
* page: int, pageSize: int, xAPIKey: string, xSenderID: string
19+
* }
1820
*/
1921
final class ContactListParams implements BaseModel
2022
{
@@ -34,18 +36,28 @@ final class ContactListParams implements BaseModel
3436
#[Required]
3537
public int $pageSize;
3638

39+
#[Required]
40+
public string $xAPIKey;
41+
42+
#[Required]
43+
public string $xSenderID;
44+
3745
/**
3846
* `new ContactListParams()` is missing required properties by the API.
3947
*
4048
* To enforce required parameters use
4149
* ```
42-
* ContactListParams::with(page: ..., pageSize: ...)
50+
* ContactListParams::with(page: ..., pageSize: ..., xAPIKey: ..., xSenderID: ...)
4351
* ```
4452
*
4553
* Otherwise ensure the following setters are called
4654
*
4755
* ```
48-
* (new ContactListParams)->withPage(...)->withPageSize(...)
56+
* (new ContactListParams)
57+
* ->withPage(...)
58+
* ->withPageSize(...)
59+
* ->withXAPIKey(...)
60+
* ->withXSenderID(...)
4961
* ```
5062
*/
5163
public function __construct()
@@ -58,12 +70,18 @@ public function __construct()
5870
*
5971
* You must use named parameters to construct any parameters with a default value.
6072
*/
61-
public static function with(int $page, int $pageSize): self
62-
{
73+
public static function with(
74+
int $page,
75+
int $pageSize,
76+
string $xAPIKey,
77+
string $xSenderID
78+
): self {
6379
$self = new self;
6480

6581
$self['page'] = $page;
6682
$self['pageSize'] = $pageSize;
83+
$self['xAPIKey'] = $xAPIKey;
84+
$self['xSenderID'] = $xSenderID;
6785

6886
return $self;
6987
}
@@ -89,4 +107,20 @@ public function withPageSize(int $pageSize): self
89107

90108
return $self;
91109
}
110+
111+
public function withXAPIKey(string $xAPIKey): self
112+
{
113+
$self = clone $this;
114+
$self['xAPIKey'] = $xAPIKey;
115+
116+
return $self;
117+
}
118+
119+
public function withXSenderID(string $xSenderID): self
120+
{
121+
$self = clone $this;
122+
$self['xSenderID'] = $xSenderID;
123+
124+
return $self;
125+
}
92126
}

src/Contacts/ContactRetrieveByPhoneParams.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
*
1515
* @see SentDm\Services\ContactsService::retrieveByPhone()
1616
*
17-
* @phpstan-type ContactRetrieveByPhoneParamsShape = array{phoneNumber: string}
17+
* @phpstan-type ContactRetrieveByPhoneParamsShape = array{
18+
* phoneNumber: string, xAPIKey: string, xSenderID: string
19+
* }
1820
*/
1921
final class ContactRetrieveByPhoneParams implements BaseModel
2022
{
@@ -28,18 +30,29 @@ final class ContactRetrieveByPhoneParams implements BaseModel
2830
#[Required]
2931
public string $phoneNumber;
3032

33+
#[Required]
34+
public string $xAPIKey;
35+
36+
#[Required]
37+
public string $xSenderID;
38+
3139
/**
3240
* `new ContactRetrieveByPhoneParams()` is missing required properties by the API.
3341
*
3442
* To enforce required parameters use
3543
* ```
36-
* ContactRetrieveByPhoneParams::with(phoneNumber: ...)
44+
* ContactRetrieveByPhoneParams::with(
45+
* phoneNumber: ..., xAPIKey: ..., xSenderID: ...
46+
* )
3747
* ```
3848
*
3949
* Otherwise ensure the following setters are called
4050
*
4151
* ```
42-
* (new ContactRetrieveByPhoneParams)->withPhoneNumber(...)
52+
* (new ContactRetrieveByPhoneParams)
53+
* ->withPhoneNumber(...)
54+
* ->withXAPIKey(...)
55+
* ->withXSenderID(...)
4356
* ```
4457
*/
4558
public function __construct()
@@ -52,11 +65,16 @@ public function __construct()
5265
*
5366
* You must use named parameters to construct any parameters with a default value.
5467
*/
55-
public static function with(string $phoneNumber): self
56-
{
68+
public static function with(
69+
string $phoneNumber,
70+
string $xAPIKey,
71+
string $xSenderID
72+
): self {
5773
$self = new self;
5874

5975
$self['phoneNumber'] = $phoneNumber;
76+
$self['xAPIKey'] = $xAPIKey;
77+
$self['xSenderID'] = $xSenderID;
6078

6179
return $self;
6280
}
@@ -71,4 +89,20 @@ public function withPhoneNumber(string $phoneNumber): self
7189

7290
return $self;
7391
}
92+
93+
public function withXAPIKey(string $xAPIKey): self
94+
{
95+
$self = clone $this;
96+
$self['xAPIKey'] = $xAPIKey;
97+
98+
return $self;
99+
}
100+
101+
public function withXSenderID(string $xSenderID): self
102+
{
103+
$self = clone $this;
104+
$self['xSenderID'] = $xSenderID;
105+
106+
return $self;
107+
}
74108
}

0 commit comments

Comments
 (0)