Skip to content

Commit

Permalink
add stats API
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargaj committed Oct 10, 2017
1 parent b793348 commit 4d6b2b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions _rewrite.php
Expand Up @@ -11,6 +11,8 @@

"^\/+v1\/party\/?$" => "v1_party.php",

"^\/+v1\/stats\/?$" => "v1_stats.php",

"^\/+adhoc\/prods-from-year\/?$" => "adhoc_prods_year.php",
));
$r->addBootstrap("./functions.inc.php");
Expand Down
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -15,6 +15,7 @@ <h2>Endpoints</h2>
<dt>http://api.pouet.net/v1/group/?id=1</dt>
<dt>http://api.pouet.net/v1/search/prod/?q=[...]</dt>
<dt>http://api.pouet.net/v1/party/?id=1&amp;year=2000</dt>
<dt>http://api.pouet.net/v1/stats/</dt>
</dl>

<p>More to come, mostly on demand. Data structures are subject to change without notice.</p>
Expand Down
27 changes: 27 additions & 0 deletions v1_stats.php
@@ -0,0 +1,27 @@
<?
if (!defined("POUET_API")) exit();

$group = $_GET["id"] ? PouetGroup::Spawn((int)$_GET["id"]) : null;
if ($group)
{
$s = new BM_Query("prods");
$s->AddWhere(sprintf_esc("(prods.group1 = %d) or (prods.group2 = %d) or (prods.group3 = %d)",$group->id,$group->id,$group->id));
$prods = $s->perform();
PouetCollectPlatforms($prods);
PouetCollectAwards($prods);
}

$result = new stdClass();

$data = unserialize( file_get_contents( POUETAPI_POUET_ROOT_LOCAL . "/cache/pouetbox_stats.cache" ) );
if ($data)
{
$result->success = true;
$result->stats = $data;
}
else
{
$result->error = true;
}
output($result);
?>

0 comments on commit 4d6b2b9

Please sign in to comment.