Skip to content

Commit c19246f

Browse files
committed
Methods return null on error
1 parent ba449f8 commit c19246f

File tree

86 files changed

+652
-487
lines changed

Some content is hidden

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

86 files changed

+652
-487
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This library normalizes the [Constant Contact API](https://v3.developer.constant
2525
Due to a mistake in naming conventions by Constant Contact API designers, several end points are duplicated between the end point that returns all objects, and the end point that just works with one object. Normally this is dealt with by using the singular form of the noun for CRUD type operations on a single object, and the plural noun form returns a list of objects. This library follows the correct naming convention (single nouns for CRUD and plural nouns for collections) and not the Constant Contact naming convention.
2626

2727
## Definitions
28-
This Constant Contact API defines all types of objects to interact with the API. They are defined in the **PHPFUI\ConstantContact\Definition** namespace. Only valid fields are allowed to be accessed. Types are fully validated as to the best ability of PHP. Min and max lengths are enforced for strings.
28+
This Constant Contact API defines all types of objects to interact with the API. They are defined in the **PHPFUI\ConstantContact\Definition** namespace. Only valid fields are allowed to be accessed. Types are fully validated as to the best ability of PHP. Min and max lengths are enforced for strings. Invalid values will throw exceptions for type safety.
2929

3030
## Usage Once Authorized (see below)
3131
```php
@@ -95,6 +95,11 @@ $client->refreshToken();
9595
```
9696
The token will expire requiring your user to reauthorize your app unless you refresh the token. You should refresh the token on a regular basis to avoid reauthorization.
9797

98+
## Method Return Values
99+
The library methods will return either raw PHP arrays, objects in the **\ConstantContact\Definition** namespace, or a null value. The plain end points like get(), post(), update(), etc. return plain PHP arrays. The end points suffixed with Typed will return a fully formed object in the **\ConstantContact\Definition** namespace. Some Typed() methods will return an array of typed **\ConstantContact\Definition** objects.
100+
101+
If a raw or typed method returns null, then an error occured and you should check $client->getStatusCode() or $client->getLastError() for more information.
102+
98103
## Versioning
99104
Since the [Constant Contact API](https://v3.developer.constantcontact.com/api_guide/index.html) is constantly being updated, this library will track all updates on a calendar based versioning schema. The major version will be the last two digits of the year the update was released. The minor version will be the month it was released. Any bug fixes will be a patch version. So V21.8.0 would be the first August 2021 version, and V21.8.1 would be a bug fix to V21.8. All bug fixes will be included in subsequent versions, so V21.9.0 would include all fixes from the V21.8 version. YAML changes are tracked nightly and a new version will be generated automatically. Multiple YAML changes in a month will be tracked as patch versions.
100105

Tool/Generator.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ private function writeClass(string $namespacedClass, string $apiPath, array $pro
540540
~description~
541541
*~docblock~
542542
*/
543-
public function ~method~(~parameters~) : array
543+
public function ~method~(~parameters~) : ?array
544544
{
545545
~code~
546546
METHOD;
@@ -607,7 +607,7 @@ public function ~method~(~parameters~) : array
607607
$summary = $this->formatDescription($specs['summary']);
608608
$description = $this->formatDescription($specs['description']);
609609

610-
// add in ReturnSchema methods
610+
// add in Typed return methods
611611
foreach ($specs['responses'] ?? [] as $returnCode => $parameter)
612612
{
613613
$returnCode = (int)$returnCode;
@@ -623,12 +623,18 @@ public function ~method~(~parameters~) : array
623623
$returnSchema = <<<SCHEMA
624624
625625
/**
626-
* @return array<{$schema}>
626+
* @return ?array<{$schema}>
627627
*/
628-
public function ~method~ReturnSchema(~parameters~) : array
628+
public function ~method~Typed(~parameters~) : ?array
629629
{
630+
{$dollar}data = {$dollar}this->~method~(~passedParameters~);
631+
if (is_null({$dollar}data))
632+
{
633+
return null;
634+
}
635+
630636
{$dollar}array = [];
631-
foreach ({$dollar}this->~method~(~passedParameters~) as {$dollar}object)
637+
foreach ({$dollar}data as {$dollar}object)
632638
{
633639
{$dollar}array[] = new {$schema}({$dollar}object);
634640
}
@@ -638,26 +644,16 @@ public function ~method~ReturnSchema(~parameters~) : array
638644
639645
SCHEMA;
640646
}
641-
// else if ('string' === $returnType)
642-
// {
643-
// $returnSchema = <<<SCHEMA
644-
//
645-
//
646-
// public function ~method~ReturnSchema(~parameters~) : string
647-
// {
648-
// return {$dollar}this->~method~(~passedParameters~);
649-
// }
650-
//
651-
//SCHEMA;
652-
// }
653647
else
654648
{
655649
$returnSchema = <<<SCHEMA
656650
657651
658-
public function ~method~ReturnSchema(~parameters~) : {$schema}
652+
public function ~method~Typed(~parameters~) : ?{$schema}
659653
{
660-
return new {$schema}({$dollar}this->~method~(~passedParameters~));
654+
{$dollar}data = {$dollar}this->~method~(~passedParameters~);
655+
656+
return {$dollar}data ? new {$schema}({$dollar}data) : null;
661657
}
662658
663659
SCHEMA;

src/ConstantContact/Client.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function addScope(string $scope) : self
120120
/**
121121
* Issue a delete request. This is not normally called directly, but by the V3 namespace classes.
122122
*/
123-
public function delete(string $url) : array
123+
public function delete(string $url) : ?array
124124
{
125125
try
126126
{
@@ -135,13 +135,13 @@ public function delete(string $url) : array
135135
$this->statusCode = $e->getResponse()->getStatusCode();
136136
}
137137

138-
return [];
138+
return null;
139139
}
140140

141141
/**
142142
* Issue a get request. This is not normally called directly, but by the V3 namespace classes.
143143
*/
144-
public function get(string $url, array $parameters) : array
144+
public function get(string $url, array $parameters) : ?array
145145
{
146146
try
147147
{
@@ -167,7 +167,7 @@ public function get(string $url, array $parameters) : array
167167
$this->statusCode = $e->getResponse()->getStatusCode();
168168
}
169169

170-
return [];
170+
return null;
171171
}
172172

173173
/**
@@ -244,15 +244,15 @@ public function next() : array
244244
/**
245245
* Issue a patch request. This is not normally called directly, but by the V3 namespace classes.
246246
*/
247-
public function patch(string $url, array $parameters) : array
247+
public function patch(string $url, array $parameters) : ?array
248248
{
249249
return $this->put($url, $parameters, 'PATCH');
250250
}
251251

252252
/**
253253
* Issue a post request. This is not normally called directly, but by the V3 namespace classes.
254254
*/
255-
public function post(string $url, array $parameters) : array
255+
public function post(string $url, array $parameters) : ?array
256256
{
257257
try
258258
{
@@ -270,13 +270,13 @@ public function post(string $url, array $parameters) : array
270270
$this->statusCode = $e->getResponse()->getStatusCode();
271271
}
272272

273-
return [];
273+
return null;
274274
}
275275

276276
/**
277277
* Issue a put request. This is not normally called directly, but by the V3 namespace classes.
278278
*/
279-
public function put(string $url, array $parameters, string $method = 'PUT') : array
279+
public function put(string $url, array $parameters, string $method = 'PUT') : ?array
280280
{
281281
try
282282
{
@@ -303,7 +303,7 @@ public function put(string $url, array $parameters, string $method = 'PUT') : ar
303303
$this->statusCode = $e->getResponse()->getStatusCode();
304304
}
305305

306-
return [];
306+
return null;
307307
}
308308

309309
/**
@@ -450,7 +450,7 @@ private function getHeaders(array $additional = []) : array
450450
], $additional);
451451
}
452452

453-
private function process(\Psr\Http\Message\ResponseInterface $response) : array
453+
private function process(\Psr\Http\Message\ResponseInterface $response) : ?array
454454
{
455455
$this->next = '';
456456
$this->lastError = $response->getReasonPhrase();
@@ -470,7 +470,7 @@ private function process(\Psr\Http\Message\ResponseInterface $response) : array
470470
$this->lastError = \json_last_error_msg();
471471
$this->statusCode = \json_last_error();
472472

473-
return [];
473+
return null;
474474
}
475475

476476
private function session(string $key, ?string $value) : string

src/ConstantContact/Definition/ActivityDeleteListResponse.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
/**
88
* @property \PHPFUI\ConstantContact\UUID $activity_id Unique ID for the delete list batch job.
99
* @property string $state The state of the request:
10-
<p><ul>
11-
<li>initialized - request has been received</li>
12-
<li>processing - request is being processed</li>
13-
<li>completed - job completed</li>
14-
<li>cancelled - request was cancelled</li>
15-
<li>failed - job failed to complete</li>
16-
<li>timed_out - the request timed out before completing"</li>
10+
* <p><ul>
11+
* <li>initialized - request has been received</li>
12+
* <li>processing - request is being processed</li>
13+
* <li>completed - job completed</li>
14+
* <li>cancelled - request was cancelled</li>
15+
* <li>failed - job failed to complete</li>
16+
* <li>timed_out - the request timed out before completing"</li>
1717
* </ul> </p>
1818
* @property \PHPFUI\ConstantContact\DateTime $created_at Date and time that the request was received, in ISO-8601 formmat.
1919
* @property \PHPFUI\ConstantContact\DateTime $updated_at Date and time that the request status was updated, in ISO-8601 format.

src/ConstantContact/Definition/ActivityExportStatus.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
/**
88
* @property \PHPFUI\ConstantContact\UUID $activity_id Unique ID for the activity.
99
* @property string $state <p> The state of the request: <ul>
10-
<li>initialized - request has been received</li>
11-
<li>processing - request is being processed</li>
12-
<li>completed - job completed</li>
13-
<li>cancelled - request was cancelled</li>
14-
<li>failed - job failed to complete</li>
15-
<li>timed_out - the request timed out before completing"</li>
16-
</ul> </p>
10+
* <li>initialized - request has been received</li>
11+
* <li>processing - request is being processed</li>
12+
* <li>completed - job completed</li>
13+
* <li>cancelled - request was cancelled</li>
14+
* <li>failed - job failed to complete</li>
15+
* <li>timed_out - the request timed out before completing"</li>
16+
* </ul> </p>
1717
* @property \PHPFUI\ConstantContact\DateTime $started_at Timestamp showing when we began processing the activity request, in ISO-8601 format.
1818
* @property \PHPFUI\ConstantContact\DateTime $completed_at Timestamp showing when we completed processing the activity, in ISO-8601 format.
1919
* @property \PHPFUI\ConstantContact\DateTime $created_at Timestamp showing when we created the activity, in ISO-8601 format.

src/ConstantContact/Definition/ActivityImport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
/**
88
* @property \PHPFUI\ConstantContact\UUID $activity_id Unique ID for the activity.
99
* @property string $state The state of the request:
10-
<p><ul>
11-
* <li>initialized - request has been received</li>
10+
* <p><ul>
11+
* <li>initialized - request has been received</li>
1212
* <li>processing - request is being processed</li>
1313
* <li>completed - job completed</li>
1414
* <li>cancelled - request was cancelled</li>

src/ConstantContact/Definition/Base.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,14 @@ public function getJSON() : string
310310
{
311311
return \json_encode($this->getData(), JSON_PRETTY_PRINT);
312312
}
313+
314+
/**
315+
* More descriptive alternative to getData()
316+
*
317+
* @return array representation of data
318+
*/
319+
public function toArray() : array
320+
{
321+
return $this->getData();
322+
}
313323
}

src/ConstantContact/Definition/EmailSendHistory.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
* @property array $segment_ids The contact segments that Constant Contact sent the email campaign activity to as an array of <code>segment_id</code> integers.
1111
* @property int $count The number of contacts that Constant Contact sent this email campaign activity to. This property is specific to each send history object. When you resend an email campaign activity, Constant Contact only sends it to new contacts in the contact lists or segments you are using.
1212
* @property \PHPFUI\ConstantContact\DateTime $run_date The system generated date and time that Constant Contact sent the email campaign activity to contacts in ISO-8601 format.
13-
* @property string $send_status The send status for the email campaign activity. Valid values are: <ul>
13+
* @property string $send_status The send status for the email campaign activity. Valid values are: <ul>
1414
* <li><code>COMPLETED</code>: Constant Contact successfully sent the email campaign activity.</li>
1515
* <li><code>ERRORED</code>: Constant Contact encountered an error when sending the email campaign activity.<li> * </ul>
1616
* @property int $reason_code The reason why the send attempt completed or encountered an error. This method returns <code>0</code> if Constant Contact successfully sent the email campaign activity to contacts. Possible <code>reason_code</code> values are: <ul>
17-
* <li>0 — Constant Contact successfully sent the email to contacts.</li>
18-
* <li>1 — An error occurred when sending this email. Try scheduling it again, or contact <a href='http://support.constantcontact.com' target='_blank'>Customer Support</a>.</li>
19-
* <li>2 — We were unable to send the email. Please contact our <a href='http://knowledgebase.constantcontact.com/articles/KnowledgeBase/5782-contact-an-account-review-and-deliverability-specialist' target='_blank'>Account Review Team</a> for more information.</li>
20-
* <li>3 — This Constant Contact account cannot currently send emails. This can be due to billing or product expiration.</li>
21-
* <li>4 — You're not able to send the email to that many contacts. Remove contacts from the contact lists you are using or select a list with fewer contacts.</li>
22-
* <li>5 — The email is currently in staging. For more information, see the <a href='http://knowledgebase.constantcontact.com/articles/KnowledgeBase/7402-email-staging' target='_blank>Email Staging Knowledge Base article</a>.</li>
23-
* <li>6 — Constant Contact was unable to finish sending this email to all of the contacts on your list. Please contact <a href='http://support.constantcontact.com' target='_blank'>Customer Support</a> for more information.</li>
24-
* <li>7 — The email contains invalid images. This can be caused when one or more images in the email are longer available in your image library.</li>
25-
* <li>8 — The email contains a link URL that exceeds 1005 characters.</li>
26-
* <li>9 — Constant Contact was unable to verify your authenticated Sender address. Please contact <a href='http://support.constantcontact.com' target='_blank'>Customer Support</a> for more information.</li>
27-
* <li>10 — Constant Contact was unable to verify your authenticated Sender address. Please contact <a href='http://support.constantcontact.com' target='_blank'>Customer Support</a> for more information.</li>
28-
* <li>11 — This Constant Contact account cannot send survey invitations.</li>
29-
* <li>12 — Constant Contact attempted to send the email, but there were no eligible contacts to send it to. This can be caused by an invalid contact list, a contact list with no contacts, or a contact list with no new contacts during a resend. This method displays <code>reason_code</code> 12 as a send attempt with a <code>send_status</code> of COMPLETED and a <code>count</code> of 0.</li> * </ul>
17+
* <li>0 — Constant Contact successfully sent the email to contacts.</li>
18+
* <li>1 — An error occurred when sending this email. Try scheduling it again, or contact <a href='http://support.constantcontact.com' target='_blank'>Customer Support</a>.</li>
19+
* <li>2 — We were unable to send the email. Please contact our <a href='http://knowledgebase.constantcontact.com/articles/KnowledgeBase/5782-contact-an-account-review-and-deliverability-specialist' target='_blank'>Account Review Team</a> for more information.</li>
20+
* <li>3 — This Constant Contact account cannot currently send emails. This can be due to billing or product expiration.</li>
21+
* <li>4 — You're not able to send the email to that many contacts. Remove contacts from the contact lists you are using or select a list with fewer contacts.</li>
22+
* <li>5 — The email is currently in staging. For more information, see the <a href='http://knowledgebase.constantcontact.com/articles/KnowledgeBase/7402-email-staging' target='_blank>Email Staging Knowledge Base article</a>.</li>
23+
* <li>6 — Constant Contact was unable to finish sending this email to all of the contacts on your list. Please contact <a href='http://support.constantcontact.com' target='_blank'>Customer Support</a> for more information.</li>
24+
* <li>7 — The email contains invalid images. This can be caused when one or more images in the email are longer available in your image library.</li>
25+
* <li>8 — The email contains a link URL that exceeds 1005 characters.</li>
26+
* <li>9 — Constant Contact was unable to verify your authenticated Sender address. Please contact <a href='http://support.constantcontact.com' target='_blank'>Customer Support</a> for more information.</li>
27+
* <li>10 — Constant Contact was unable to verify your authenticated Sender address. Please contact <a href='http://support.constantcontact.com' target='_blank'>Customer Support</a> for more information.</li>
28+
* <li>11 — This Constant Contact account cannot send survey invitations.</li>
29+
* <li>12 — Constant Contact attempted to send the email, but there were no eligible contacts to send it to. This can be caused by an invalid contact list, a contact list with no contacts, or a contact list with no new contacts during a resend. This method displays <code>reason_code</code> 12 as a send attempt with a <code>send_status</code> of COMPLETED and a <code>count</code> of 0.</li> * </ul>
3030
*/
3131
class EmailSendHistory extends \PHPFUI\ConstantContact\Definition\Base
3232
{

src/ConstantContact/Definition/PlanInfo.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* @property string $plan_type Use this property to update the client account billing plan to a different billing plan. After changing the <code>plan_type</code> from <code>TRIAL</code> to any other billing plan type, you cannot change it back to <code>TRIAL</code>.
99
* <ul>
1010
* <li><code>TRIAL</code>: A non-billable account with an expiration date that allows clients to try Constant Contact product features.</li>
11-
* <li><code>GOLD</code>: A billable client account plan.</li>
12-
* <li><code>SILVER</code>: A billable client account plan.</li>
13-
* <li><code>BRONZE</code>: A billable client account plan.</li>
11+
* <li><code>GOLD</code>: A billable client account plan.</li>
12+
* <li><code>SILVER</code>: A billable client account plan.</li>
13+
* <li><code>BRONZE</code>: A billable client account plan.</li>
1414
* </ul>
1515
* @property int $plan_group_id Updates an existing client account billing plan group to a new billing plan group. If you don't know the `plan_group_id` to use, contact our API support team.
1616
* @property int $billing_day_of_month This property is required if a client account is not set up to use single billing. You can choose to enter a specific day of the month or accept the default value, which is the day on which the <code>plan_type</code> value changes from a <code>TRIAL</code> plan to a different <code>plan_type</code>. For trial accounts, the value defaults to null. You can only change the <code>billing_day_of_month</code> when changing the <code>plan_type</code> value from <code>TRIAL</code> to a different <code>plan_type</code>, otherwise the value you enter is ignored.

src/ConstantContact/Definition/PlanTiersObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* @property string $plan_type The billing plan that is associated with a client's Constant Contact account. The billing plan determines which Constant Contact product features that the client account can access. If you are not on the latest billing plan, contact the Constant Contact Partner Team. However, older billing plans and <code>plan_type</code> enum values will continue to be supported. <ul>
99
* <li><code>TRIAL</code>: Provides limited product features for a non-billed account and the account has an expiration date.</li>
10-
* <li><code>BRONZE</code>: Billable plan that provides basic email and marketing tools.</li>
10+
* <li><code>BRONZE</code>: Billable plan that provides basic email and marketing tools.</li>
1111
* <li><code>SILVER</code>: Billable plan that provides all features available in the <code>BRONZE</code> plan, and adds some additional email campaign to features, such as contact segmentation and social media ads integration.</li>
1212
* <li><code>GOLD</code>: Billable plan that provides all available product features.</li> * </ul>
1313
* @property array<\PHPFUI\ConstantContact\Definition\TierObject> $current_tiers Lists the billing plan tiers that are currently associated with a client account.

0 commit comments

Comments
 (0)