Skip to content

Commit 3a8791b

Browse files
authored
Merge pull request #113 from Kit/add-get-link-clicks-for-broadcast-method
Add `get_broadcast_link_clicks` method
2 parents 7e6515a + 4f088b7 commit 3a8791b

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/ConvertKit_API_Traits.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,37 @@ public function get_broadcast_stats(int $id)
12131213
return $this->get(sprintf('broadcasts/%s/stats', $id));
12141214
}
12151215

1216+
/**
1217+
* List link clicks for a specific broadcast.
1218+
*
1219+
* @param integer $id Broadcast ID.
1220+
* @param string $after_cursor Return results after the given pagination cursor.
1221+
* @param string $before_cursor Return results before the given pagination cursor.
1222+
* @param integer $per_page Number of results to return.
1223+
*
1224+
* @since 2.2.1
1225+
*
1226+
* @see https://developers.kit.com/api-reference/broadcasts/get-link-clicks-for-a-broadcast
1227+
*
1228+
* @return false|mixed
1229+
*/
1230+
public function get_broadcast_link_clicks(
1231+
int $id,
1232+
string $after_cursor = '',
1233+
string $before_cursor = '',
1234+
int $per_page = 100
1235+
) {
1236+
// Send request.
1237+
return $this->get(
1238+
sprintf('broadcasts/%s/clicks', $id),
1239+
$this->build_total_count_and_pagination_params(
1240+
after_cursor: $after_cursor,
1241+
before_cursor: $before_cursor,
1242+
per_page: $per_page
1243+
)
1244+
);
1245+
}
1246+
12161247
/**
12171248
* Updates a broadcast.
12181249
*

tests/ConvertKitAPITest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4243,6 +4243,47 @@ public function testGetBroadcastStatsWithInvalidBroadcastID()
42434243
$this->api->get_broadcast_stats(12345);
42444244
}
42454245

4246+
/**
4247+
* Test that get_broadcast_link_clicks() returns the expected data.
4248+
*
4249+
* @since 2.2.1
4250+
*
4251+
* @return void
4252+
*/
4253+
public function testGetBroadcastLinkClicks()
4254+
{
4255+
// Get broadcast link clicks.
4256+
$result = $this->api->get_broadcast_link_clicks(
4257+
$_ENV['CONVERTKIT_API_BROADCAST_ID'],
4258+
per_page: 1
4259+
);
4260+
4261+
// Assert clicks and pagination exist.
4262+
$this->assertDataExists($result->broadcast, 'clicks');
4263+
$this->assertPaginationExists($result);
4264+
4265+
// Assert a single click was returned.
4266+
$this->assertCount(1, $result->broadcast->clicks);
4267+
4268+
// Assert has_previous_page and has_next_page are correct.
4269+
$this->assertFalse($result->pagination->has_previous_page);
4270+
$this->assertFalse($result->pagination->has_next_page);
4271+
}
4272+
4273+
/**
4274+
* Test that get_broadcast_link_clicks() throws a ClientException when an invalid
4275+
* broadcast ID is specified.
4276+
*
4277+
* @since 2.2.1
4278+
*
4279+
* @return void
4280+
*/
4281+
public function testGetBroadcastLinkClicksWithInvalidBroadcastID()
4282+
{
4283+
$this->expectException(ClientException::class);
4284+
$this->api->get_broadcast_link_clicks(12345);
4285+
}
4286+
42464287
/**
42474288
* Test that update_broadcast() throws a ClientException when an invalid
42484289
* broadcast ID is specified.

0 commit comments

Comments
 (0)