├── .gitignore ├── LICENSE ├── README.md ├── bin └── unity-asset-store-api.js ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Kl0tl 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | unity-asset-store-api [![Dependency Status](https://gemnasium.com/Kl0tl/unity-asset-store-api.svg)](https://gemnasium.com/Kl0tl/unity-asset-store-api) 2 | ====================== 3 | 4 | A minimal REST api to query the [Unity Asset Store website](https://www.assetstore.unity3d.com). 5 | -------------------------------------------------------------------------------- /bin/unity-asset-store-api.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | var fs = require('fs'); 6 | 7 | var clc = require('cli-color'); 8 | var optimist = require('optimist'); 9 | 10 | var pkg = require('../package.json'); 11 | 12 | var api = require('../index'); 13 | 14 | var doc = [ 15 | pkg.description,, 16 | 17 | 'Usage:',, 18 | 19 | ' ' + clc.cyan('unity-asset-store-api') + ' [options]',, 20 | 21 | 'Options:',, 22 | 23 | ' ' + clc.magenta('-h --help') + ' Show this.', 24 | ' ' + clc.magenta('-o , --output ') + ' Write output to file.', 25 | ' ' + clc.magenta('-v --version') + ' Show version number.',, 26 | ].join('\n'); 27 | 28 | if (process.argv.length < 3) { 29 | writeDocToStdout(); 30 | } else { 31 | var argv = optimist.argv; 32 | 33 | if (argv.h || argv.help) { 34 | writeDocToStdout(); 35 | } else if (argv.v || argv.version) { 36 | writeVersionToStdout(); 37 | } else { 38 | api.get(argv._[0]) 39 | .then(JSON.stringify) 40 | .then(function (res) { 41 | var output = argv.o || argv.output; 42 | 43 | if (output) { 44 | return write(output, res); 45 | } 46 | 47 | process.stdout.write(res + '\n'); 48 | }) 49 | .catch(throwError); 50 | } 51 | } 52 | 53 | function throwError(err) { 54 | process.nextTick(function () { 55 | throw err; 56 | }); 57 | } 58 | 59 | function write(filename, contents) { 60 | return new Promise(function (resolve, reject) { 61 | fs.writeFile(filename, contents, function (err) { 62 | if (err) reject(err); 63 | else resolve(); 64 | }); 65 | }); 66 | } 67 | 68 | function writeDocToStdout() { 69 | process.stdout.write('\n' + doc + '\n'); 70 | } 71 | 72 | function writeVersionToStdout() { 73 | process.stdout.write(pkg.version + '\n'); 74 | } 75 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var querystring = require('querystring'); 4 | 5 | var Promise = require('native-promise-only'); 6 | var RoutePattern = require('route-pattern'); 7 | var request = require('request'); 8 | 9 | var token = '26c4202eb475d02864b40827dfff11a14657aa41'; 10 | 11 | var routes = { 12 | 'packages/search.json?query=:query&limit=:limit': function (options) { 13 | var packagesSearchUrl = 'https://www.assetstore.unity3d.com/api/en-US/search/xplr/search.json?'; 14 | 15 | return fetchRessource(packagesSearchUrl, options.queryParams); 16 | }, 17 | 18 | 'packages/:id': function (options) { 19 | var packageOverviewUrl = 'https://www.assetstore.unity3d.com/api/en-US/content/overview/:id.json?'; 20 | 21 | return fetchRessourceById(packageOverviewUrl, options); 22 | }, 23 | 24 | 'packages/:id/assets': function (options) { 25 | var formatedPackageUrl = 'packages/:id' 26 | .replace(':id', options.namedParams.id); 27 | 28 | return api.get(formatedPackageUrl, options.queryParams).then(function (res, err) { 29 | var formatedPackageAssetsUrl = formatedPackageUrl + '/assets/:version' 30 | .replace(':version', res.content.package_version_id); 31 | 32 | return api.get(formatedPackageAssetsUrl, options.queryParams); 33 | }); 34 | }, 35 | 36 | 'packages/:id/assets/:version': function (options) { 37 | var packageAssetsUrl = 'https://www.assetstore.unity3d.com/api/en-US/content/assets/:id/:version.json?'; 38 | var formatedPackageAssetsUrl = packageAssetsUrl 39 | .replace(':id', options.namedParams.id) 40 | .replace(':version', options.namedParams.version); 41 | 42 | return fetchRessource(formatedPackageAssetsUrl, options.queryParams); 43 | }, 44 | 45 | 'categories': function (options) { 46 | var categoriesUrl = 'https://www.assetstore.unity3d.com/api/en-US/home/categories.json?'; 47 | 48 | return fetchRessource(categoriesUrl, options.queryParams); 49 | }, 50 | 51 | 'categories/:id': function (options) { 52 | var categoryHeadUrl = 'https://www.assetstore.unity3d.com/api/en-US/head/category/:id.json?'; 53 | 54 | return fetchRessourceById(categoryHeadUrl, options); 55 | }, 56 | 57 | 'categories/:id/packages': function (options) { 58 | var categoryPackagesUrl = 'https://www.assetstore.unity3d.com/api/en-US/category/results/:id.json?' 59 | 60 | return fetchRessourceById(categoryPackagesUrl, options); 61 | }, 62 | 63 | 'publishers/:id': function (options) { 64 | var publisherOverviewUrl = 'https://www.assetstore.unity3d.com/api/en-US/publisher/overview/:id.json?'; 65 | 66 | return fetchRessourceById(publisherOverviewUrl, options); 67 | }, 68 | 69 | 'publishers/:id/packages': function (options) { 70 | var publisherPackagesUrl = 'https://www.assetstore.unity3d.com/api/en-US/publisher/results/:id.json?'; 71 | 72 | return fetchRessourceById(publisherPackagesUrl, options); 73 | } 74 | }; 75 | 76 | function fetchRessource(url, query) { 77 | return new Promise(function (resolve, reject) { 78 | request({ url: url, qs: query, headers: { 'X-Unity-Session': token } }, function (err, res, body) { 79 | if (err) reject(err); 80 | else resolve(JSON.parse(body)); 81 | }); 82 | }); 83 | } 84 | 85 | function fetchRessourceById(url, options) { 86 | var formatedUrl = url.replace(':id', options.namedParams.id); 87 | 88 | return fetchRessource(formatedUrl, options.queryParams); 89 | } 90 | 91 | var api = module.exports = { 92 | get: function (url, query) { 93 | var search = querystring.stringify(query); 94 | 95 | if (search) url += '?' + search; 96 | 97 | return new Promise(function (resolve, reject) { 98 | for (var route in routes) { 99 | var pattern = RoutePattern.fromString(route); 100 | var matches = pattern.match(url); 101 | 102 | if (matches) { 103 | var handler = routes[route]; 104 | return handler(matches).then(resolve, reject); 105 | } 106 | } 107 | 108 | reject(error404()); 109 | }); 110 | } 111 | }; 112 | 113 | function error404() { 114 | var err = new Error('Not Found'); 115 | err.status = 404; 116 | return err; 117 | } 118 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unity-asset-store-api", 3 | "version": "0.1.0", 4 | "description": "A minimal REST api to query the [Unity Asset Store website](https://www.assetstore.unity3d.com).", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/Kl0tl/unity-asset-store-api.git" 12 | }, 13 | "keywords": [ 14 | "unity", 15 | "unity3d", 16 | "rest", 17 | "api", 18 | "asset", 19 | "store" 20 | ], 21 | "author": "Cyril Sobierajewicz ", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/Kl0tl/unity-asset-store-api/issues" 25 | }, 26 | "homepage": "https://github.com/Kl0tl/unity-asset-store-api", 27 | "preferGlobal": true, 28 | "bin": { 29 | "unity-asset-store-api": "bin/unity-asset-store-api.js" 30 | }, 31 | "dependencies": { 32 | "cli-color": "^0.3.2", 33 | "native-promise-only": "^0.7.6-a", 34 | "optimist": "^0.6.1", 35 | "request": "^2.40.0", 36 | "route-pattern": "0.0.6" 37 | } 38 | } 39 | --------------------------------------------------------------------------------