From 78ed9b8b83fa0592501c6333fd31ec02a5335d4d Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 6 Nov 2019 22:47:59 +0100 Subject: [PATCH] First working version with downloads --- README.rst | 2 +- bin/import-game-data.php | 126 +++++++++++++++++++++++++++++---- www/.htaccess | 9 +++ www/api/v1/discover/home | 13 ---- www/api/v1/discover/index.html | 13 ---- 5 files changed, 123 insertions(+), 40 deletions(-) delete mode 100644 www/api/v1/discover/home delete mode 100644 www/api/v1/discover/index.html diff --git a/README.rst b/README.rst index b10ed4f..bb65277 100644 --- a/README.rst +++ b/README.rst @@ -17,7 +17,7 @@ OUYA config change - Add:: OUYA_SERVER_URL=http://stouyapi.boo - OUYA_STATUS_SERVER_URL=http://stouyapi.boo + OUYA_STATUS_SERVER_URL=http://stouyapi.boo/api/v1/status Notes: diff --git a/bin/import-game-data.php b/bin/import-game-data.php index a02dad7..b1ec629 100755 --- a/bin/import-game-data.php +++ b/bin/import-game-data.php @@ -24,21 +24,33 @@ foreach ($gameFiles as $gameFile) { error('JSON invalid at ' . $gameFile); } addMissingGameProperties($game); - //FIXME: add missing properties? $games[$game->package] = $game; + + writeJson( + 'api/v1/details-data/' . $game->package . '.json', + buildDetails($game) + ); + writeJson( - 'api/v1/apps/' . $game->package, + 'api/v1/apps/' . $game->package . '.json', buildApps($game) ); + $latestRelease = getLatestRelease($game); writeJson( - 'api/v1/details-data/' . $game->package . '.json', - buildDetails($game) + 'api/v1/apps/' . $latestRelease->uuid . '.json', + buildApps($game) + ); + + writeJson( + 'api/v1/apps/' . $latestRelease->uuid . '-download.json', + buildAppDownload($game, $latestRelease) ); //exit(2); - + } -//FIXME: build discover section +writeJson('api/v1/discover.json', buildDiscover($games)); +writeJson('api/v1/discover-data/home.json', buildDiscoverHome($games)); /** * Build api/v1/apps/$package @@ -46,7 +58,7 @@ foreach ($gameFiles as $gameFile) { function buildApps($game) { $latestRelease = getLatestRelease($game); - + // http://cweiske.de/ouya-store-api-docs.htm#get-https-devs-ouya-tv-api-v1-apps-xxx return [ 'app' => [ @@ -56,12 +68,12 @@ function buildApps($game) 'description' => $game->description, 'gamerNumbers' => $game->players, 'genres' => $game->genres, - + 'website' => $game->website, 'contentRating' => $game->contentRating, 'premium' => $game->premium, 'firstPublishedAt' => $game->firstPublishedAt, - + 'likeCount' => $game->rating->likeCount, 'ratingAverage' => $game->rating->average, 'ratingCount' => $game->rating->count, @@ -89,6 +101,18 @@ function buildApps($game) ]; } +function buildAppDownload($game, $release) +{ + return [ + 'app' => [ + 'fileSize' => $release->size, + 'version' => $release->uuid, + 'contentRating' => $game->contentRating, + 'downloadLink' => $release->url, + ] + ]; +} + /** * Build /app/v1/details?app=org.example.game */ @@ -123,7 +147,7 @@ function buildDetails($game) 'fp_url' => $screenshot, ]; } - + // http://cweiske.de/ouya-store-api-docs.htm#get-https-devs-ouya-tv-api-v1-details return [ 'type' => 'Game', @@ -179,9 +203,85 @@ function buildDetails($game) 'heroImage' => [ 'url' => null, ], - + 'promotedProduct' => null, - ]; + ]; +} + +function buildDiscover(array $games) +{ + $data = [ + 'title' => 'DISCOVER', + 'rows' => [], + 'tiles' => [], + ]; + $tileMap = []; + + $rowAll = [ + 'title' => 'ALL GAMES', + 'showPrice' => false, + 'ranked' => false, + 'tiles' => [], + ]; + foreach ($games as $game) { + $tilePos = count($tileMap); + $data['tiles'][$tilePos] = buildDiscoverGameTile($game); + $tileMap[$game->package] = $tilePos; + + $rowAll['tiles'][] = $tilePos; + } + $data['rows'][] = $rowAll; + + return $data; +} + +function buildDiscoverHome(array $games) +{ + //we do not want anything here for now + $data = [ + 'title' => 'home', + 'rows' => [ + [ + 'title' => 'FEATURED', + 'showPrice' => false, + 'ranked' => false, + 'tiles' => [], + ] + ], + 'tiles' => [], + ]; + return $data; +} + +function buildDiscoverGameTile($game) +{ + $latestRelease = getLatestRelease($game); + return [ + 'gamerNumbers' => $game->players, + 'genres' => $game->genres, + 'url' => 'ouya://launcher/details?app=' . $game->package, + 'latestVersion' => [ + 'apk' => [ + 'md5sum' => $latestRelease->md5sum, + ], + 'versionNumber' => $latestRelease->name, + 'uuid' => $latestRelease->uuid, + ], + 'inAppPurchases' => $game->inAppPurchases, + 'promotedProduct' => null, + 'premium' => $game->premium, + 'type' => 'app', + 'package' => $game->package, + 'updated_at' => strtotime($latestRelease->date), + 'updatedAt' => $latestRelease->date, + 'title' => $game->title, + 'image' => $game->media->discover, + 'contentRating' => $game->contentRating, + 'rating' => [ + 'count' => $game->rating->count, + 'average' => $game->rating->average, + ], + ]; } function addMissingGameProperties($game) @@ -210,7 +310,7 @@ function addMissingGameProperties($game) if (!isset($game->firstPublishedAt)) { $game->firstPublishedAt = gmdate('c'); } - + if (!isset($game->rating)) { $game->rating = new stdClass(); } diff --git a/www/.htaccess b/www/.htaccess index f5ab99b..111445f 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -3,3 +3,12 @@ RewriteEngine on #rewrite details GET parameter RewriteCond %{QUERY_STRING} ^app=([^&]+) RewriteRule ^api/v1/details /api/v1/details-data/%1.json? + +RewriteRule ^api/v1/apps/(.*)/download$ /api/v1/apps/$1-download.json? [END] +RewriteRule ^api/v1/apps/(.*)$ /api/v1/apps/$1.json? [END] + +RewriteRule ^api/v1/discover/?$ /api/v1/discover.json [END] +RewriteRule ^api/v1/discover/(.+)$ /api/v1/discover-data/$1.json [END] + +#this one wants a 204 status code +RewriteRule ^api/v1/status$ - [R=204,NC,L] diff --git a/www/api/v1/discover/home b/www/api/v1/discover/home deleted file mode 100644 index 0d009d3..0000000 --- a/www/api/v1/discover/home +++ /dev/null @@ -1,13 +0,0 @@ -{ - "rows": [ - { - "showPrice": false, - "ranked": false, - "tiles": [], - "title": "FEATURED" - } - ], - "tiles": [ - ], - "title": "home" -} diff --git a/www/api/v1/discover/index.html b/www/api/v1/discover/index.html deleted file mode 100644 index c725675..0000000 --- a/www/api/v1/discover/index.html +++ /dev/null @@ -1,13 +0,0 @@ -{ - "rows": [ - { - "showPrice": false, - "ranked": false, - "tiles": [], - "title": "test" - } - ], - "tiles": [ - ], - "title": "DISCOVER" -} -- 2.30.2