First working version with downloads
authorChristian Weiske <cweiske@cweiske.de>
Wed, 6 Nov 2019 21:47:59 +0000 (22:47 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 6 Nov 2019 21:47:59 +0000 (22:47 +0100)
README.rst
bin/import-game-data.php
www/.htaccess
www/api/v1/discover/home [deleted file]
www/api/v1/discover/index.html [deleted file]

index b10ed4ffe6795067513cbc18b9528544a27d5044..bb6527702bb6ffcde88fa0268c842b393e10ca06 100644 (file)
@@ -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:
 
index a02dad7a27fe7031f0a2906f7d86015acf536614..b1ec6299b8d6b19efff511ea74503e31576eb332 100755 (executable)
@@ -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();
     }
index f5ab99b2249bdf949548cf286461a883355bab1b..111445fe84cdc061a3612f7f644217bb1b711a00 100644 (file)
@@ -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 (file)
index 0d009d3..0000000
+++ /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 (file)
index c725675..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-{
-    "rows": [
-        {
-            "showPrice": false,
-            "ranked": false,
-            "tiles": [],
-            "title": "test"
-        }
-    ],
-    "tiles": [
-    ],
-    "title": "DISCOVER"
-}