Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new endpoint for fetching data from lists #39

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ npm-debug.log
Dockerfile
.dockerignore
.github
fly.toml
fly.production.toml
fly.staging.toml
.gitpod.yml
.gitignore
.eslintrc
Expand Down
31 changes: 22 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI/CD Pipeline
on:
workflow_dispatch:
push:
branches: ["main"]
branches: ["main", "dev"]
paths: ["!PostmanCollections/**", "!./github/**"]

jobs:
Expand Down Expand Up @@ -38,14 +38,14 @@ jobs:

- name: Run Tests
run: npm test

- name: Upload HTML Report
uses: actions/upload-artifact@v2
with:
name: html-report
path: newman/*.html


build_and_push_docker_image:
needs: build_and_test
runs-on: ubuntu-latest
Expand All @@ -71,8 +71,10 @@ jobs:
- name: Build and Push Docker Image
run: |
docker buildx create --use
docker buildx build --platform linux/amd64 -t ghcr.io/${{ github.repository }}:latest --push .
docker buildx build --platform linux/amd64 -t ghcr.io/${{ github.repository }}:main --push .
docker buildx build --platform linux/amd64 -t ghcr.io/${{ github.repository }}:dev --push .
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
docker buildx build --platform linux/amd64 -t ghcr.io/${{ github.repository }}:main --push .
fi
docker buildx stop

deploy_to_fly:
Expand All @@ -86,17 +88,28 @@ jobs:
- name: Get FlyCtl
uses: superfly/flyctl-actions/setup-flyctl@master

- name: Determine File Based on Branch
id: determine-env
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
cp fly.production.toml fly.toml
echo "DEPLOY_TARGET=Fly" >> $GITHUB_ENV
else
cp fly.staging.toml fly.toml
echo "DEPLOY_TARGET=FlyDev" >> $GITHUB_ENV
fi


- name: start deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: Fly
env: ${{ env.DEPLOY_TARGET }}

- name: Deploy to Fly
run: |
flyctl deploy --remote-only
run: flyctl deploy
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

Expand All @@ -116,4 +129,4 @@ jobs:
path: ~/.fly
key: ${{ runner.os }}-flyctl
restore-keys: |
${{ runner.os }}-flyctl-
${{ runner.os }}-flyctl-
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ ports:
onOpen: open-preview
name: Google Play API
description: Website Preview
visibility: private
visibility: public
protocol: https
356 changes: 221 additions & 135 deletions PostmanCollections/GooglePlayAPI.postman_collection.json

Large diffs are not rendered by default.

File renamed without changes.
22 changes: 22 additions & 0 deletions fly.staging.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "gplayapidev"
primary_region = "sin"

[build]
image = "ghcr.io/srikanthlogic/google-play-api:dev"

[services]
[services.http]
ports = ["http"]

[http_service]
protocol = "tcp"
internal_port = 3000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]
29 changes: 23 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ router.get('/apps/', function (req, res, next) {

/* App list */
router.get('/apps/', function (req, res, next) {
function paginate (apps) {
function paginate(apps) {
const num = parseInt(req.query.num || '60');
const start = parseInt(req.query.start || '0');

Expand Down Expand Up @@ -124,7 +124,7 @@ router.get('/apps/:appId/permissions', function (req, res, next) {

/* App reviews */
router.get('/apps/:appId/reviews', function (req, res, next) {
function paginate (apps) {
function paginate(apps) {
const page = parseInt(req.query.page || '0');

const subpath = '/apps/' + req.params.appId + '/reviews/';
Expand Down Expand Up @@ -176,14 +176,31 @@ router.get('/developers/', (req, res) =>
example: buildUrl(req, '/developers/' + qs.escape('Wikimedia Foundation'))
}));

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

gplay.list(opts)
.then((apps) => apps.map(cleanUrls(req)))
.then(toList)
.then(res.json.bind(res))
.catch(next);
});

function errorHandler (err, req, res, next) {
/* Category list */
router.get('/categories/', async (req, res, next) => {
try {
res.json(Object.keys(gplay.category));
} catch (error) {
next(error); // Pass the error to Express's error-handling middleware
}
});


function errorHandler(err, req, res, next) {
res.status(400).json({ message: err.message });
next();
}
Expand Down
Loading