Skip to content

Commit

Permalink
Merge main into sweep/graphql-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Oct 29, 2023
2 parents ec1d538 + 9017a7d commit cbabcc7
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 56 deletions.
7 changes: 6 additions & 1 deletion Spacefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ micros:
commands:
- npm run generateoas
run: node server.js
dev: node server.js
dev: node server.js
presets:
env:
- name: COUNTRY_OF_QUERY
description: Country parameter to be defaulted for all requests
default: "US"
5 changes: 4 additions & 1 deletion fly.production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ primary_region = "sin"
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]
processes = ["app"]

[env]
COUNTRY_OF_QUERY = "IN"
6 changes: 5 additions & 1 deletion fly.staging.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ primary_region = "sin"
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]
processes = ["app"]

[env]
COUNTRY_OF_QUERY = "IN"
LOGGING = true
27 changes: 19 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ const router = Express.Router();

const toList = (apps) => ({ results: apps });


router.use((req, res, next) => {

if (!req.query.country) {
req.query.country = process.env.COUNTRY_OF_QUERY || 'US';;
}

next();
});


const cleanUrls = (req) => (app) => Object.assign({}, app, {
playstoreUrl: app.url,
url: buildUrl(req, 'apps/' + app.appId),
Expand All @@ -33,7 +44,7 @@ router.get('/apps/', function (req, res, next) {
return next();
}

const opts = Object.assign({ term: req.query.q }, req.query);
const opts = Object.assign({ term: req.query.q, country: req.query.country }, req.query);

gplay.search(opts)
.then((apps) => apps.map(cleanUrls(req)))
Expand Down Expand Up @@ -88,7 +99,7 @@ router.get('/apps/', function (req, res, next) {

/* App detail */
router.get('/apps/:appId', function (req, res, next) {
const opts = Object.assign({ appId: req.params.appId }, req.query);
const opts = Object.assign({ appId: req.params.appId, country: req.query.country }, req.query);
gplay.app(opts)
.then(cleanUrls(req))
.then(res.json.bind(res))
Expand All @@ -97,7 +108,7 @@ router.get('/apps/:appId', function (req, res, next) {

/* Similar apps */
router.get('/apps/:appId/similar', function (req, res, next) {
const opts = Object.assign({ appId: req.params.appId }, req.query);
const opts = Object.assign({ appId: req.params.appId, country: req.query.country }, req.query);
gplay.similar(opts)
.then((apps) => apps.map(cleanUrls(req)))
.then(toList)
Expand All @@ -107,7 +118,7 @@ router.get('/apps/:appId/similar', function (req, res, next) {

/* Data Safety */
router.get('/apps/:appId/datasafety', function (req, res, next) {
const opts = Object.assign({ appId: req.params.appId }, req.query);
const opts = Object.assign({ appId: req.params.appId, country: req.query.country }, req.query);
gplay.datasafety(opts)
.then(toList)
.then(res.json.bind(res))
Expand All @@ -116,7 +127,7 @@ router.get('/apps/:appId/datasafety', function (req, res, next) {

/* App permissions */
router.get('/apps/:appId/permissions', function (req, res, next) {
const opts = Object.assign({ appId: req.params.appId }, req.query);
const opts = Object.assign({ appId: req.params.appId, country: req.query.country }, req.query);
gplay.permissions(opts)
.then(toList)
.then(res.json.bind(res))
Expand All @@ -125,7 +136,7 @@ router.get('/apps/:appId/permissions', function (req, res, next) {

/* App reviews */
router.get('/apps/:appId/reviews', function (req, res, next) {
const opts = Object.assign({ appId: req.params.appId }, req.query);
const opts = Object.assign({ appId: req.params.appId, country: req.query.country }, req.query);
const includeUserData = req.query.userdata === 'true';
const includeReplies = req.query.replies == 'true'

Expand Down Expand Up @@ -195,7 +206,7 @@ router.get('/apps/:appId/reviews', function (req, res, next) {
});
/* Apps by developer */
router.get('/developers/:devId/', function (req, res, next) {
const opts = Object.assign({ devId: req.params.devId }, req.query);
const opts = Object.assign({ devId: req.params.devId, country: req.query.country }, req.query);

gplay.developer(opts)
.then((apps) => apps.map(cleanUrls(req)))
Expand All @@ -216,7 +227,7 @@ router.get('/developers/', (req, res) =>

/* List of apps by category and collection */
router.get('/lists/', function (req, res, next) {
const opts = Object.assign({ term: req.query.q }, req.query);
const opts = Object.assign({ term: req.query.q, country: req.query.country }, req.query);
if (!req.query.category || !req.query.collection) {
return res.status(400).json({ message: 'Both category and collection parameters are required.' });
}
Expand Down
Loading

0 comments on commit cbabcc7

Please sign in to comment.