Skip to content

Commit 8d57692

Browse files
committed
Merge remote-tracking branch 'origin/v4-api-oauth' into v4-api-webhooks
# Conflicts: # tests/ConvertKitAPITest.php
2 parents bf449bf + f7fe5e1 commit 8d57692

File tree

2 files changed

+202
-110
lines changed

2 files changed

+202
-110
lines changed

Diff for: src/ConvertKit_API.php

+111-74
Original file line numberDiff line numberDiff line change
@@ -1292,39 +1292,59 @@ public function get_subscriber_tags(
12921292
}
12931293

12941294
/**
1295-
* Gets a list of broadcasts.
1295+
* List broadcasts.
12961296
*
1297-
* @see https://developers.convertkit.com/#list-broadcasts
1297+
* @param boolean $include_total_count To include the total count of records in the response, use true.
1298+
* @param string $after_cursor Return results after the given pagination cursor.
1299+
* @param string $before_cursor Return results before the given pagination cursor.
1300+
* @param integer $per_page Number of results to return.
12981301
*
1299-
* @return false|array<int,\stdClass>
1302+
* @see https://developers.convertkit.com/v4.html#list-broadcasts
1303+
*
1304+
* @return false|mixed
13001305
*/
1301-
public function get_broadcasts()
1302-
{
1303-
return $this->get('broadcasts');
1306+
public function get_broadcasts(
1307+
bool $include_total_count = false,
1308+
string $after_cursor = '',
1309+
string $before_cursor = '',
1310+
int $per_page = 100
1311+
) {
1312+
// Send request.
1313+
return $this->get(
1314+
endpoint: 'broadcasts',
1315+
args: $this->build_total_count_and_pagination_params(
1316+
include_total_count: $include_total_count,
1317+
after_cursor: $after_cursor,
1318+
before_cursor: $before_cursor,
1319+
per_page: $per_page
1320+
)
1321+
);
13041322
}
13051323

13061324
/**
13071325
* Creates a broadcast.
13081326
*
1309-
* @param string $subject The broadcast email's subject.
1310-
* @param string $content The broadcast's email HTML content.
1311-
* @param string $description An internal description of this broadcast.
1312-
* @param boolean $public Specifies whether or not this is a public post.
1313-
* @param \DateTime $published_at Specifies the time that this post was published (applicable
1314-
* only to public posts).
1315-
* @param \DateTime $send_at Time that this broadcast should be sent; leave blank to create
1316-
* a draft broadcast. If set to a future time, this is the time that
1317-
* the broadcast will be scheduled to send.
1318-
* @param string $email_address Sending email address; leave blank to use your account's
1319-
* default sending email address.
1320-
* @param string $email_layout_template Name of the email template to use; leave blank to use your
1321-
* account's default email template.
1322-
* @param string $thumbnail_alt Specify the ALT attribute of the public thumbnail image
1323-
* (applicable only to public posts).
1324-
* @param string $thumbnail_url Specify the URL of the thumbnail image to accompany the broadcast
1325-
* post (applicable only to public posts).
1326-
*
1327-
* @see https://developers.convertkit.com/#create-a-broadcast
1327+
* @param string $subject The broadcast email's subject.
1328+
* @param string $content The broadcast's email HTML content.
1329+
* @param string $description An internal description of this broadcast.
1330+
* @param boolean $public Specifies whether or not this is a public post.
1331+
* @param \DateTime $published_at Specifies the time that this post was published (applicable
1332+
* only to public posts).
1333+
* @param \DateTime $send_at Time that this broadcast should be sent; leave blank to create
1334+
* a draft broadcast. If set to a future time, this is the time that
1335+
* the broadcast will be scheduled to send.
1336+
* @param string $email_address Sending email address; leave blank to use your account's
1337+
* default sending email address.
1338+
* @param string $email_template_id ID of the email template to use; leave blank to use your
1339+
* account's default email template.
1340+
* @param string $thumbnail_alt Specify the ALT attribute of the public thumbnail image
1341+
* (applicable only to public posts).
1342+
* @param string $thumbnail_url Specify the URL of the thumbnail image to accompany the broadcast
1343+
* post (applicable only to public posts).
1344+
* @param string $preview_text Specify the preview text of the email.
1345+
* @param array<string,string> $subscriber_filter Filter subscriber(s) to send the email to.
1346+
*
1347+
* @see https://developers.convertkit.com/v4.html#create-a-broadcast
13281348
*
13291349
* @return false|object
13301350
*/
@@ -1336,22 +1356,28 @@ public function create_broadcast(
13361356
\DateTime $published_at = null,
13371357
\DateTime $send_at = null,
13381358
string $email_address = '',
1339-
string $email_layout_template = '',
1359+
string $email_template_id = '',
13401360
string $thumbnail_alt = '',
1341-
string $thumbnail_url = ''
1361+
string $thumbnail_url = '',
1362+
string $preview_text = '',
1363+
array $subscriber_filter = []
13421364
) {
13431365
$options = [
1344-
'content' => $content,
1345-
'description' => $description,
1346-
'email_address' => $email_address,
1347-
'email_layout_template' => $email_layout_template,
1348-
'public' => $public,
1349-
'published_at' => (!is_null($published_at) ? $published_at->format('Y-m-d H:i:s') : ''),
1350-
'send_at' => (!is_null($send_at) ? $send_at->format('Y-m-d H:i:s') : ''),
1351-
'subject' => $subject,
1352-
'thumbnail_alt' => $thumbnail_alt,
1353-
'thumbnail_url' => $thumbnail_url,
1366+
'email_template_id' => $email_template_id,
1367+
'email_address' => $email_address,
1368+
'content' => $content,
1369+
'description' => $description,
1370+
'public' => $public,
1371+
'published_at' => (!is_null($published_at) ? $published_at->format('Y-m-d H:i:s') : ''),
1372+
'send_at' => (!is_null($send_at) ? $send_at->format('Y-m-d H:i:s') : ''),
1373+
'thumbnail_alt' => $thumbnail_alt,
1374+
'thumbnail_url' => $thumbnail_url,
1375+
'preview_text' => $preview_text,
1376+
'subject' => $subject,
13541377
];
1378+
if (count($subscriber_filter)) {
1379+
$options['subscriber_filter'] = $subscriber_filter;
1380+
}
13551381

13561382
// Iterate through options, removing blank entries.
13571383
foreach ($options as $key => $value) {
@@ -1366,15 +1392,18 @@ public function create_broadcast(
13661392
}
13671393

13681394
// Send request.
1369-
return $this->post('broadcasts', $options);
1395+
return $this->post(
1396+
endpoint: 'broadcasts',
1397+
args: $options
1398+
);
13701399
}
13711400

13721401
/**
13731402
* Retrieve a specific broadcast.
13741403
*
13751404
* @param integer $id Broadcast ID.
13761405
*
1377-
* @see https://developers.convertkit.com/#retrieve-a-specific-broadcast
1406+
* @see https://developers.convertkit.com/v4.html#get-a-broadcast
13781407
*
13791408
* @return false|object
13801409
*/
@@ -1389,7 +1418,7 @@ public function get_broadcast(int $id)
13891418
*
13901419
* @param integer $id Broadcast ID.
13911420
*
1392-
* @see https://developers.convertkit.com/#retrieve-a-specific-broadcast
1421+
* @see https://developers.convertkit.com/v4.html#get-stats
13931422
*
13941423
* @return false|object
13951424
*/
@@ -1401,24 +1430,26 @@ public function get_broadcast_stats(int $id)
14011430
/**
14021431
* Updates a broadcast.
14031432
*
1404-
* @param integer $id Broadcast ID.
1405-
* @param string $subject The broadcast email's subject.
1406-
* @param string $content The broadcast's email HTML content.
1407-
* @param string $description An internal description of this broadcast.
1408-
* @param boolean $public Specifies whether or not this is a public post.
1409-
* @param \DateTime $published_at Specifies the time that this post was published (applicable
1410-
* only to public posts).
1411-
* @param \DateTime $send_at Time that this broadcast should be sent; leave blank to create
1412-
* a draft broadcast. If set to a future time, this is the time that
1413-
* the broadcast will be scheduled to send.
1414-
* @param string $email_address Sending email address; leave blank to use your account's
1415-
* default sending email address.
1416-
* @param string $email_layout_template Name of the email template to use; leave blank to use your
1417-
* account's default email template.
1418-
* @param string $thumbnail_alt Specify the ALT attribute of the public thumbnail image
1419-
* (applicable only to public posts).
1420-
* @param string $thumbnail_url Specify the URL of the thumbnail image to accompany the broadcast
1421-
* post (applicable only to public posts).
1433+
* @param integer $id Broadcast ID.
1434+
* @param string $subject The broadcast email's subject.
1435+
* @param string $content The broadcast's email HTML content.
1436+
* @param string $description An internal description of this broadcast.
1437+
* @param boolean $public Specifies whether or not this is a public post.
1438+
* @param \DateTime $published_at Specifies the time that this post was published (applicable
1439+
* only to public posts).
1440+
* @param \DateTime $send_at Time that this broadcast should be sent; leave blank to create
1441+
* a draft broadcast. If set to a future time, this is the time that
1442+
* the broadcast will be scheduled to send.
1443+
* @param string $email_address Sending email address; leave blank to use your account's
1444+
* default sending email address.
1445+
* @param string $email_template_id ID of the email template to use; leave blank to use your
1446+
* account's default email template.
1447+
* @param string $thumbnail_alt Specify the ALT attribute of the public thumbnail image
1448+
* (applicable only to public posts).
1449+
* @param string $thumbnail_url Specify the URL of the thumbnail image to accompany the broadcast
1450+
* post (applicable only to public posts).
1451+
* @param string $preview_text Specify the preview text of the email.
1452+
* @param array<string,string> $subscriber_filter Filter subscriber(s) to send the email to.
14221453
*
14231454
* @see https://developers.convertkit.com/#create-a-broadcast
14241455
*
@@ -1433,22 +1464,28 @@ public function update_broadcast(
14331464
\DateTime $published_at = null,
14341465
\DateTime $send_at = null,
14351466
string $email_address = '',
1436-
string $email_layout_template = '',
1467+
string $email_template_id = '',
14371468
string $thumbnail_alt = '',
1438-
string $thumbnail_url = ''
1469+
string $thumbnail_url = '',
1470+
string $preview_text = '',
1471+
array $subscriber_filter = []
14391472
) {
14401473
$options = [
1441-
'content' => $content,
1442-
'description' => $description,
1443-
'email_address' => $email_address,
1444-
'email_layout_template' => $email_layout_template,
1445-
'public' => $public,
1446-
'published_at' => (!is_null($published_at) ? $published_at->format('Y-m-d H:i:s') : ''),
1447-
'send_at' => (!is_null($send_at) ? $send_at->format('Y-m-d H:i:s') : ''),
1448-
'subject' => $subject,
1449-
'thumbnail_alt' => $thumbnail_alt,
1450-
'thumbnail_url' => $thumbnail_url,
1474+
'email_template_id' => $email_template_id,
1475+
'email_address' => $email_address,
1476+
'content' => $content,
1477+
'description' => $description,
1478+
'public' => $public,
1479+
'published_at' => (!is_null($published_at) ? $published_at->format('Y-m-d H:i:s') : ''),
1480+
'send_at' => (!is_null($send_at) ? $send_at->format('Y-m-d H:i:s') : ''),
1481+
'thumbnail_alt' => $thumbnail_alt,
1482+
'thumbnail_url' => $thumbnail_url,
1483+
'preview_text' => $preview_text,
1484+
'subject' => $subject,
14511485
];
1486+
if (count($subscriber_filter)) {
1487+
$options['subscriber_filter'] = $subscriber_filter;
1488+
}
14521489

14531490
// Iterate through options, removing blank entries.
14541491
foreach ($options as $key => $value) {
@@ -1464,8 +1501,8 @@ public function update_broadcast(
14641501

14651502
// Send request.
14661503
return $this->put(
1467-
sprintf('broadcasts/%s', $id),
1468-
$options
1504+
endpoint: sprintf('broadcasts/%s', $id),
1505+
args: $options
14691506
);
14701507
}
14711508

@@ -1476,11 +1513,11 @@ public function update_broadcast(
14761513
*
14771514
* @since 1.0.0
14781515
*
1479-
* @see https://developers.convertkit.com/#destroy-webhook
1516+
* @see https://developers.convertkit.com/v4.html#delete-a-broadcast
14801517
*
14811518
* @return false|object
14821519
*/
1483-
public function destroy_broadcast(int $id)
1520+
public function delete_broadcast(int $id)
14841521
{
14851522
return $this->delete(sprintf('broadcasts/%s', $id));
14861523
}

0 commit comments

Comments
 (0)