Skip to content

Commit 81a9afd

Browse files
authored
Merge pull request #20 from danieldevine/list-tweets
add list tweets lookup
2 parents b1f4993 + eaf4b8e commit 81a9afd

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

index.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@
2222

2323
$twitter = new \Coderjerk\BirdElephant\BirdElephant($credentials);
2424

25-
dump($twitter);
25+
try {
26+
$user = $twitter->user('coderjerk');
27+
$user_lists = $user->lists()->owned();
28+
$list_id = $user_lists->data[0]->id;
29+
$tweets = $twitter->lists()->tweets()->lookup($list_id);
30+
var_dump($tweets);
31+
} catch (Exception $e) {
32+
dump($e->getResponse()->getBody()->getContents());
33+
}

src/Lists.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Coderjerk\BirdElephant\Lists\Members;
77
use Coderjerk\BirdElephant\Lists\Follows;
88
use Coderjerk\BirdElephant\Lists\Lookup;
9+
use Coderjerk\BirdElephant\Lists\Tweets;
910
use GuzzleHttp\Exception\GuzzleException;
1011

1112
class Lists
@@ -81,6 +82,15 @@ public function follows(): Follows
8182
return new Follows($this->credentials);
8283
}
8384

85+
/**
86+
* @return Tweets
87+
* @throws GuzzleException
88+
*/
89+
public function tweets(): Tweets
90+
{
91+
return new Tweets($this->credentials);
92+
}
93+
8494
/**
8595
* @param string $list_id
8696
* @return object

src/Lists/Tweets.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Coderjerk\BirdElephant\Lists;
4+
5+
use Coderjerk\BirdElephant\ApiBase;
6+
use GuzzleHttp\Exception\GuzzleException;
7+
8+
class Tweets extends ApiBase
9+
{
10+
protected array $credentials;
11+
12+
protected string $path;
13+
14+
public function __construct($credentials)
15+
{
16+
$this->credentials = $credentials;
17+
}
18+
19+
/**
20+
* Gets the members of a given list
21+
*
22+
* @param string $list_id
23+
* @param array $params
24+
* @return object
25+
* @throws GuzzleException
26+
*/
27+
public function lookup(string $list_id, array $params = []): object
28+
{
29+
$path = "lists/{$list_id}/tweets";
30+
return $this->get($this->credentials, $path, $params, null, false, false);
31+
}
32+
}

0 commit comments

Comments
 (0)