Skip to content

Commit 0331ab7

Browse files
committed
Split off the streaming from the clients into streaming clients
1 parent 74f34ea commit 0331ab7

22 files changed

+396
-60
lines changed

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/streaming-filter-hashtag-async.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
))->withAccessToken(
1717
$config['access_token']['token'],
1818
$config['access_token']['secret']
19-
);
19+
)->stream();
2020

2121
$hashtags = [];
2222

@@ -27,7 +27,9 @@
2727
}
2828
}
2929

30-
$client->filteredStream([
30+
$hashtags = array_unique($hashtags);
31+
32+
$client->filtered([
3133
'track' => implode(',', $hashtags),
3234
])->subscribeCallback(function ($document) {
3335
resource_pretty_print($document);

examples/streaming-filter-hashtag.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use ApiClients\Client\Twitter\Client;
4+
use function ApiClients\Foundation\resource_pretty_print;
5+
use function React\Promise\all;
6+
7+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
8+
$config = require 'resolve_config.php';
9+
10+
$client = (new Client(
11+
$config['consumer']['key'],
12+
$config['consumer']['secret']
13+
))->withAccessToken(
14+
$config['access_token']['token'],
15+
$config['access_token']['secret']
16+
)->stream();
17+
18+
$hashtags = [];
19+
20+
if (count($argv) > 1) {
21+
unset($argv[0]);
22+
foreach ($argv as $hashtag) {
23+
$hashtags[] = '#' . $hashtag;
24+
}
25+
}
26+
27+
$hashtags = array_unique($hashtags);
28+
29+
$client->filtered(
30+
function ($document) {
31+
resource_pretty_print($document);
32+
},
33+
[
34+
'track' => implode(',', $hashtags),
35+
]
36+
);

examples/streaming-filter-track-async.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
))->withAccessToken(
1818
$config['access_token']['token'],
1919
$config['access_token']['secret']
20-
);
20+
)->stream();
2121

2222
$users = [
2323
'WyriHaximus',
@@ -30,7 +30,9 @@
3030
}
3131
}
3232

33-
$client->filteredStream([
33+
$tracks = array_unique($tracks);
34+
35+
$client->filtered([
3436
'track' => implode(',', $tracks),
3537
])->subscribeCallback(function ($document) {
3638
resource_pretty_print($document);

examples/streaming-filter-track.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use ApiClients\Client\Twitter\Client;
4+
use function ApiClients\Foundation\resource_pretty_print;
5+
use function React\Promise\all;
6+
7+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
8+
$config = require 'resolve_config.php';
9+
10+
$client = (new Client(
11+
$config['consumer']['key'],
12+
$config['consumer']['secret']
13+
))->withAccessToken(
14+
$config['access_token']['token'],
15+
$config['access_token']['secret']
16+
)->stream();
17+
18+
$users = [
19+
'WyriHaximus',
20+
];
21+
22+
if (count($argv) > 1) {
23+
unset($argv[0]);
24+
foreach ($argv as $track) {
25+
$tracks[] = $track;
26+
}
27+
}
28+
29+
$tracks = array_unique($tracks);
30+
31+
$client->filtered(
32+
function ($document) {
33+
resource_pretty_print($document);
34+
},
35+
[
36+
'track' => implode(',', $tracks),
37+
]
38+
);

examples/streaming-filter-users-async.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
}
3131
}
3232

33-
$promises = [];
33+
$users = array_unique($users);
3434

35+
$promises = [];
3536
foreach ($users as $user) {
3637
$promises[] = $client->user($user);
3738
}
@@ -43,7 +44,7 @@
4344
$userIds[] = $user->idStr();
4445
}
4546

46-
$client->filteredStream([
47+
$client->stream()->filtered([
4748
'follow' => implode(',', $userIds),
4849
])->subscribeCallback(function ($document) {
4950
resource_pretty_print($document);

examples/streaming-filter-users.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use ApiClients\Client\Twitter\Client;
4+
use function ApiClients\Foundation\resource_pretty_print;
5+
use function React\Promise\all;
6+
7+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
8+
$config = require 'resolve_config.php';
9+
10+
$client = (new Client(
11+
$config['consumer']['key'],
12+
$config['consumer']['secret']
13+
))->withAccessToken(
14+
$config['access_token']['token'],
15+
$config['access_token']['secret']
16+
);
17+
18+
$users = [
19+
'WyriHaximus',
20+
];
21+
22+
if (count($argv) > 1) {
23+
unset($argv[0]);
24+
foreach ($argv as $user) {
25+
$users[] = $user;
26+
}
27+
}
28+
29+
$users = array_unique($users);
30+
31+
$userIds = [];
32+
foreach ($users as $user) {
33+
$userIds[] = $client->user($user)->idStr();
34+
}
35+
36+
$client->stream()->filtered(
37+
function ($document) {
38+
resource_pretty_print($document);
39+
},
40+
[
41+
'follow' => implode(',', $userIds),
42+
]
43+
);

examples/streaming-sample-async.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
))->withAccessToken(
1616
$config['access_token']['token'],
1717
$config['access_token']['secret']
18-
);
18+
)->stream();
1919

20-
$client->sampleStream()->subscribeCallback(function ($document) {
20+
$client->sample()->subscribeCallback(function ($document) {
2121
resource_pretty_print($document);
2222
});
2323

examples/streaming-sample-counters-async.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
))->withAccessToken(
1919
$config['access_token']['token'],
2020
$config['access_token']['secret']
21-
);
21+
)->stream();
2222

2323
$counters = [
2424
DeletedTweet::class => 0,
@@ -43,7 +43,7 @@
4343
}
4444
});
4545

46-
$client->sampleStream()->subscribeCallback(function ($document) use(&$counters) {
46+
$client->sample()->subscribeCallback(function ($document) use(&$counters) {
4747
$class = get_class($document);
4848

4949
if (!isset($counters[$class])) {

examples/streaming-sample.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use ApiClients\Client\Twitter\Client;
4+
use function ApiClients\Foundation\resource_pretty_print;
5+
6+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
7+
$config = require 'resolve_config.php';
8+
9+
(new Client(
10+
$config['consumer']['key'],
11+
$config['consumer']['secret']
12+
))->withAccessToken(
13+
$config['access_token']['token'],
14+
$config['access_token']['secret']
15+
)->stream()->sample(function ($document) {
16+
resource_pretty_print($document);
17+
}, function ($e) {
18+
echo (string)$e;
19+
});

0 commit comments

Comments
 (0)