-
-
Save mykiwi/5498457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
use React\Curry\Util as Curry; | |
$projects = array( | |
'react-php/react', | |
'cboden/Ratchet', | |
'nrk/predis-async', | |
'bergie/dnode-php', | |
'umpirsky/wisdom', | |
'igorw/evenement', | |
); | |
$fullRequest = function ($url, $callback) { | |
$callback(file_get_contents($url)); | |
}; | |
$parseResponse = function ($project, $body) { | |
$decoded = json_decode($body, true); | |
$latest = $decoded[0]['commit']; | |
$author = $latest['author']['name']; | |
$date = date('F j, Y', strtotime($latest['author']['date'])); | |
$message = preg_replace('#\n.*$#s', '', $latest['message']); | |
printf("\n"); | |
printf("Latest commit on %s was done by %s on %s\n", $project, $author, $date); | |
printf("%s\n", $message); | |
}; | |
printf("I'm telling you about %s projects.\n", count($projects)); | |
foreach ($projects as $project) { | |
$url = "https://api.github.com/repos/$project/commits"; | |
$fullRequest($url, Curry::bind($parseResponse, $project)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
use React\Curry\Util as Curry; | |
$loop = React\EventLoop\Factory::create(); | |
$dnsResolverFactory = new React\Dns\Resolver\Factory(); | |
$dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop); | |
$factory = new React\HttpClient\Factory(); | |
$client = $factory->create($loop, $dnsResolver); | |
$projects = array( | |
'react-php/react', | |
'cboden/Ratchet', | |
'nrk/predis-async', | |
'bergie/dnode-php', | |
'umpirsky/wisdom', | |
'igorw/evenement', | |
); | |
$fullRequest = function ($url, $callback) use ($client) { | |
$request = $client->request('GET', $url); | |
$request->on('response', function ($response) use ($callback) { | |
$buffer = ''; | |
$response->on('data', function ($data) use (&$buffer) { | |
$buffer .= $data; | |
}); | |
$response->on('end', function () use (&$buffer, $callback) { | |
$callback($buffer); | |
}); | |
}); | |
$request->end(); | |
}; | |
$parseResponse = function ($project, $body) { | |
$decoded = json_decode($body, true); | |
$latest = $decoded[0]['commit']; | |
$author = $latest['author']['name']; | |
$date = date('F j, Y', strtotime($latest['author']['date'])); | |
$message = preg_replace('#\n.*$#s', '', $latest['message']); | |
printf("\n"); | |
printf("Latest commit on %s was done by %s on %s\n", $project, $author, $date); | |
printf("%s\n", $message); | |
}; | |
printf("I'm telling you about %s projects.\n", count($projects)); | |
foreach ($projects as $project) { | |
$url = "https://api.github.com/repos/$project/commits"; | |
$fullRequest($url, Curry::bind($parseResponse, $project)); | |
} | |
$loop->run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"repositories": [ | |
{ | |
"type": "vcs", | |
"url": "https://github.com/arnaud-lb/react" | |
} | |
], | |
"minimum-stability": "dev", | |
"require": { | |
"react/react": "dev-http-client", | |
"react/curry": "dev-master" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment