PHP code example of developmint / npm-stats-api
1. Go to this page and download the library: Download developmint/npm-stats-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
developmint / npm-stats-api example snippets php
$client = new \GuzzleHttp\Client();
$npmStats = new \Developmint\NpmStats\NpmStats($client);
php
$npmStats->getStats('jquery');
php
$npmStats->getStats('jquery', NpmStats::LAST_DAY);
php
$npmStats->getStats('jquery', '2017-01-01');
php
$npmStats->getStats('jquery', '2014-02-07:2014-02-14');
php
array(4) {
["downloads"]=>
int(198672)
["start"]=>
string(10) "2017-10-10"
["end"]=>
string(10) "2017-10-10"
["package"]=>
string(6) "jquery"
}
php
$npmStats->getStats('jquery', NpmStats::LAST_WEEK, true);
php
array(4) {
["start"]=>
string(10) "2017-10-04"
["end"]=>
string(10) "2017-10-10"
["package"]=>
string(6) "jquery"
["downloads"]=>
array(7) {
[0]=>
array(2) {
["downloads"]=>
int(200678)
["day"]=>
string(10) "2017-10-04"
}
[1]=>
array(2) {
["downloads"]=>
int(195593)
["day"]=>
string(10) "2017-10-05"
}
[2]=>
array(2) {
["downloads"]=>
int(172132)
["day"]=>
string(10) "2017-10-06"
}
[3]=>
array(2) {
["downloads"]=>
int(51068)
["day"]=>
string(10) "2017-10-07"
}
[4]=>
array(2) {
["downloads"]=>
int(46892)
["day"]=>
string(10) "2017-10-08"
}
[5]=>
array(2) {
["downloads"]=>
int(171920)
["day"]=>
string(10) "2017-10-09"
}
[6]=>
array(2) {
["downloads"]=>
int(198672)
["day"]=>
string(10) "2017-10-10"
}
}
}
php
$npmStats->getStats('vue,express', NpmStats::LAST_WEEK);
php
$npmStats->getStats('vue,express', NpmStats::LAST_WEEK, true);
//Won't work
php
array(2) {
["vue"]=>
array(4) {
["downloads"]=>
int(3980980980098089080980983)
["package"]=>
string(5) "vue"
["start"]=>
string(10) "2017-10-10"
["end"]=>
string(10) "2017-10-10"
}
["express"]=>
array(4) {
["downloads"]=>
int(818264)
["package"]=>
string(7) "express"
["start"]=>
string(10) "2017-10-10"
["end"]=>
string(10) "2017-10-10"
}
}