Skip to content

Commit 43ce27f

Browse files
Merge pull request #454 from HubSpot/feature/codegenComPreferences
Codegen: Communications Preferences
2 parents 727c483 + bfeeeac commit 43ce27f

14 files changed

Lines changed: 210 additions & 128 deletions

codegen/CommunicationPreferences/Api/DefinitionApi.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
*/
1111

1212
/**
13-
* Communication Preferences Subscriptions
13+
* Subscriptions
1414
*
1515
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
1616
*
1717
* The version of the OpenAPI document: v3
1818
* Generated by: https://openapi-generator.tech
19-
* OpenAPI Generator version: 7.3.0
19+
* Generator version: 7.12.0
2020
*/
2121

2222
/**
@@ -83,13 +83,13 @@ class DefinitionApi
8383
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
8484
*/
8585
public function __construct(
86-
ClientInterface $client = null,
87-
Configuration $config = null,
88-
HeaderSelector $selector = null,
89-
$hostIndex = 0
86+
?ClientInterface $client = null,
87+
?Configuration $config = null,
88+
?HeaderSelector $selector = null,
89+
int $hostIndex = 0
9090
) {
9191
$this->client = $client ?: new Client();
92-
$this->config = $config ?: new Configuration();
92+
$this->config = $config ?: Configuration::getDefaultConfiguration();
9393
$this->headerSelector = $selector ?: new HeaderSelector();
9494
$this->hostIndex = $hostIndex;
9595
}
@@ -176,18 +176,6 @@ public function getPageWithHttpInfo(string $contentType = self::contentTypes['ge
176176

177177
$statusCode = $response->getStatusCode();
178178

179-
if ($statusCode < 200 || $statusCode > 299) {
180-
throw new ApiException(
181-
sprintf(
182-
'[%d] Error connecting to the API (%s)',
183-
$statusCode,
184-
(string) $request->getUri()
185-
),
186-
$statusCode,
187-
$response->getHeaders(),
188-
(string) $response->getBody()
189-
);
190-
}
191179

192180
switch($statusCode) {
193181
case 200:
@@ -246,6 +234,19 @@ public function getPageWithHttpInfo(string $contentType = self::contentTypes['ge
246234
];
247235
}
248236

237+
if ($statusCode < 200 || $statusCode > 299) {
238+
throw new ApiException(
239+
sprintf(
240+
'[%d] Error connecting to the API (%s)',
241+
$statusCode,
242+
(string) $request->getUri()
243+
),
244+
$statusCode,
245+
$response->getHeaders(),
246+
(string) $response->getBody()
247+
);
248+
}
249+
249250
$returnType = '\HubSpot\Client\CommunicationPreferences\Model\SubscriptionDefinitionsResponse';
250251
if ($returnType === '\SplFileObject') {
251252
$content = $response->getBody(); //stream goes to serializer

codegen/CommunicationPreferences/Api/StatusApi.php

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
*/
1111

1212
/**
13-
* Communication Preferences Subscriptions
13+
* Subscriptions
1414
*
1515
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
1616
*
1717
* The version of the OpenAPI document: v3
1818
* Generated by: https://openapi-generator.tech
19-
* OpenAPI Generator version: 7.3.0
19+
* Generator version: 7.12.0
2020
*/
2121

2222
/**
@@ -89,13 +89,13 @@ class StatusApi
8989
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
9090
*/
9191
public function __construct(
92-
ClientInterface $client = null,
93-
Configuration $config = null,
94-
HeaderSelector $selector = null,
95-
$hostIndex = 0
92+
?ClientInterface $client = null,
93+
?Configuration $config = null,
94+
?HeaderSelector $selector = null,
95+
int $hostIndex = 0
9696
) {
9797
$this->client = $client ?: new Client();
98-
$this->config = $config ?: new Configuration();
98+
$this->config = $config ?: Configuration::getDefaultConfiguration();
9999
$this->headerSelector = $selector ?: new HeaderSelector();
100100
$this->hostIndex = $hostIndex;
101101
}
@@ -184,18 +184,6 @@ public function getEmailStatusWithHttpInfo($email_address, string $contentType =
184184

185185
$statusCode = $response->getStatusCode();
186186

187-
if ($statusCode < 200 || $statusCode > 299) {
188-
throw new ApiException(
189-
sprintf(
190-
'[%d] Error connecting to the API (%s)',
191-
$statusCode,
192-
(string) $request->getUri()
193-
),
194-
$statusCode,
195-
$response->getHeaders(),
196-
(string) $response->getBody()
197-
);
198-
}
199187

200188
switch($statusCode) {
201189
case 200:
@@ -254,6 +242,19 @@ public function getEmailStatusWithHttpInfo($email_address, string $contentType =
254242
];
255243
}
256244

245+
if ($statusCode < 200 || $statusCode > 299) {
246+
throw new ApiException(
247+
sprintf(
248+
'[%d] Error connecting to the API (%s)',
249+
$statusCode,
250+
(string) $request->getUri()
251+
),
252+
$statusCode,
253+
$response->getHeaders(),
254+
(string) $response->getBody()
255+
);
256+
}
257+
257258
$returnType = '\HubSpot\Client\CommunicationPreferences\Model\PublicSubscriptionStatusesResponse';
258259
if ($returnType === '\SplFileObject') {
259260
$content = $response->getBody(); //stream goes to serializer
@@ -530,18 +531,6 @@ public function subscribeWithHttpInfo($public_update_subscription_status_request
530531

531532
$statusCode = $response->getStatusCode();
532533

533-
if ($statusCode < 200 || $statusCode > 299) {
534-
throw new ApiException(
535-
sprintf(
536-
'[%d] Error connecting to the API (%s)',
537-
$statusCode,
538-
(string) $request->getUri()
539-
),
540-
$statusCode,
541-
$response->getHeaders(),
542-
(string) $response->getBody()
543-
);
544-
}
545534

546535
switch($statusCode) {
547536
case 200:
@@ -600,6 +589,19 @@ public function subscribeWithHttpInfo($public_update_subscription_status_request
600589
];
601590
}
602591

592+
if ($statusCode < 200 || $statusCode > 299) {
593+
throw new ApiException(
594+
sprintf(
595+
'[%d] Error connecting to the API (%s)',
596+
$statusCode,
597+
(string) $request->getUri()
598+
),
599+
$statusCode,
600+
$response->getHeaders(),
601+
(string) $response->getBody()
602+
);
603+
}
604+
603605
$returnType = '\HubSpot\Client\CommunicationPreferences\Model\PublicSubscriptionStatus';
604606
if ($returnType === '\SplFileObject') {
605607
$content = $response->getBody(); //stream goes to serializer
@@ -875,18 +877,6 @@ public function unsubscribeWithHttpInfo($public_update_subscription_status_reque
875877

876878
$statusCode = $response->getStatusCode();
877879

878-
if ($statusCode < 200 || $statusCode > 299) {
879-
throw new ApiException(
880-
sprintf(
881-
'[%d] Error connecting to the API (%s)',
882-
$statusCode,
883-
(string) $request->getUri()
884-
),
885-
$statusCode,
886-
$response->getHeaders(),
887-
(string) $response->getBody()
888-
);
889-
}
890880

891881
switch($statusCode) {
892882
case 200:
@@ -945,6 +935,19 @@ public function unsubscribeWithHttpInfo($public_update_subscription_status_reque
945935
];
946936
}
947937

938+
if ($statusCode < 200 || $statusCode > 299) {
939+
throw new ApiException(
940+
sprintf(
941+
'[%d] Error connecting to the API (%s)',
942+
$statusCode,
943+
(string) $request->getUri()
944+
),
945+
$statusCode,
946+
$response->getHeaders(),
947+
(string) $response->getBody()
948+
);
949+
}
950+
948951
$returnType = '\HubSpot\Client\CommunicationPreferences\Model\PublicSubscriptionStatus';
949952
if ($returnType === '\SplFileObject') {
950953
$content = $response->getBody(); //stream goes to serializer

codegen/CommunicationPreferences/ApiException.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
*/
1111

1212
/**
13-
* Communication Preferences Subscriptions
13+
* Subscriptions
1414
*
1515
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
1616
*
1717
* The version of the OpenAPI document: v3
1818
* Generated by: https://openapi-generator.tech
19-
* OpenAPI Generator version: 7.3.0
19+
* Generator version: 7.12.0
2020
*/
2121

2222
/**
@@ -49,7 +49,7 @@ class ApiException extends Exception
4949
/**
5050
* The HTTP header of the server response.
5151
*
52-
* @var string[]|null
52+
* @var string[][]|null
5353
*/
5454
protected $responseHeaders;
5555

@@ -65,7 +65,7 @@ class ApiException extends Exception
6565
*
6666
* @param string $message Error message
6767
* @param int $code HTTP status code
68-
* @param string[]|null $responseHeaders HTTP response header
68+
* @param string[][]|null $responseHeaders HTTP response header
6969
* @param \stdClass|string|null $responseBody HTTP decoded body of the server response either as \stdClass or string
7070
*/
7171
public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null)
@@ -78,7 +78,7 @@ public function __construct($message = "", $code = 0, $responseHeaders = [], $re
7878
/**
7979
* Gets the HTTP response header
8080
*
81-
* @return string[]|null HTTP response header
81+
* @return string[][]|null HTTP response header
8282
*/
8383
public function getResponseHeaders()
8484
{

codegen/CommunicationPreferences/Configuration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
*/
1111

1212
/**
13-
* Communication Preferences Subscriptions
13+
* Subscriptions
1414
*
1515
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
1616
*
1717
* The version of the OpenAPI document: v3
1818
* Generated by: https://openapi-generator.tech
19-
* OpenAPI Generator version: 7.3.0
19+
* Generator version: 7.12.0
2020
*/
2121

2222
/**
@@ -486,7 +486,7 @@ public function getHostSettings()
486486
* @param array|null $variables hash of variable and the corresponding value (optional)
487487
* @return string URL based on host settings
488488
*/
489-
public static function getHostString(array $hostSettings, $hostIndex, array $variables = null)
489+
public static function getHostString(array $hostSettings, $hostIndex, ?array $variables = null)
490490
{
491491
if (null === $variables) {
492492
$variables = [];

codegen/CommunicationPreferences/HeaderSelector.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
*/
1111

1212
/**
13-
* Communication Preferences Subscriptions
13+
* Subscriptions
1414
*
1515
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
1616
*
1717
* The version of the OpenAPI document: v3
1818
* Generated by: https://openapi-generator.tech
19-
* OpenAPI Generator version: 7.3.0
19+
* Generator version: 7.12.0
2020
*/
2121

2222
/**
@@ -85,7 +85,7 @@ private function selectAcceptHeader(array $accept): ?string
8585
}
8686

8787
# If none of the available Accept headers is of type "json", then just use all them
88-
$headersWithJson = preg_grep('~(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$~', $accept);
88+
$headersWithJson = $this->selectJsonMimeList($accept);
8989
if (count($headersWithJson) === 0) {
9090
return implode(',', $accept);
9191
}
@@ -95,6 +95,34 @@ private function selectAcceptHeader(array $accept): ?string
9595
return $this->getAcceptHeaderWithAdjustedWeight($accept, $headersWithJson);
9696
}
9797

98+
/**
99+
* Detects whether a string contains a valid JSON mime type
100+
*
101+
* @param string $searchString
102+
* @return bool
103+
*/
104+
public function isJsonMime(string $searchString): bool
105+
{
106+
return preg_match('~^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)~', $searchString) === 1;
107+
}
108+
109+
/**
110+
* Select all items from a list containing a JSON mime type
111+
*
112+
* @param array $mimeList
113+
* @return array
114+
*/
115+
private function selectJsonMimeList(array $mimeList): array {
116+
$jsonMimeList = [];
117+
foreach ($mimeList as $mime) {
118+
if($this->isJsonMime($mime)) {
119+
$jsonMimeList[] = $mime;
120+
}
121+
}
122+
return $jsonMimeList;
123+
}
124+
125+
98126
/**
99127
* Create an Accept header string from the given "Accept" headers array, recalculating all weights
100128
*

codegen/CommunicationPreferences/Model/Error.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
*/
1212

1313
/**
14-
* Communication Preferences Subscriptions
14+
* Subscriptions
1515
*
1616
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
1717
*
1818
* The version of the OpenAPI document: v3
1919
* Generated by: https://openapi-generator.tech
20-
* OpenAPI Generator version: 7.3.0
20+
* Generator version: 7.12.0
2121
*/
2222

2323
/**
@@ -275,10 +275,10 @@ public function getModelName()
275275
/**
276276
* Constructor
277277
*
278-
* @param mixed[] $data Associated array of property values
278+
* @param mixed[]|null $data Associated array of property values
279279
* initializing the model
280280
*/
281-
public function __construct(array $data = null)
281+
public function __construct(?array $data = null)
282282
{
283283
$this->setIfExists('sub_category', $data ?? [], null);
284284
$this->setIfExists('context', $data ?? [], null);

0 commit comments

Comments
 (0)