Skip to content

Commit a1c8ab8

Browse files
authored
Merge pull request ExpDev07#95 from gribok/master
Multiple changes for testing, api endpoints and versioning
2 parents 14b0d20 + 779e329 commit a1c8ab8

File tree

15 files changed

+57
-18
lines changed

15 files changed

+57
-18
lines changed

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Makefile for coronavirus-tracker-api
3+
# ~~~~~~~~~~~~~~~~~~~~~
4+
#
5+
# Combines scripts for common tasks.
6+
#
7+
8+
PYTHON ?= python3
9+
10+
PHONY: all check test
11+
12+
all: test pylint
13+
14+
APP = app
15+
TEST = tests
16+
17+
test:
18+
$(PYTHON) `which py.test` -s -v $(TEST)
19+
20+
lint:
21+
pylint $(APP) || true

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ You will need the following things properly installed on your computer.
160160

161161
### Running Tests
162162

163-
* `py.test -s -v tests/`
163+
* `make test`
164164

165165
### Linting
166166

167-
* `pylint app/`
167+
* `make lint`
168168

169169
### Building
170170

app/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from flask import Flask
22
from flask_cors import CORS
33

4+
#see PEP396
5+
__version__ = '2.0'
6+
47
def create_app():
58
"""
69
Construct the core application.
@@ -16,6 +19,9 @@ def create_app():
1619
with app.app_context():
1720
# Import routes.
1821
from . import routes
22+
#register api endpoints
23+
app.register_blueprint(routes.rest_api_v1)
24+
app.register_blueprint(routes.rest_api_v2)
1925

2026
# Return created app.
21-
return app
27+
return app

app/config/__init__.py

Whitespace-only changes.

app/data/__init__.py

Whitespace-only changes.

app/routes/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
from flask import redirect, current_app as app
22

3-
# API version 1.
4-
from .v1 import confirmed, deaths, recovered, all
3+
#follow the import order to avoid circular dependency
4+
from flask import Blueprint
5+
rest_api_v1 = Blueprint("rest_api_v1", __name__, url_prefix="")
6+
rest_api_v2 = Blueprint("rest_api_v2", __name__, url_prefix="/v2")
57

68
# API version 2.
79
from .v2 import locations, latest
810

11+
# API version 1.
12+
from .v1 import confirmed, deaths, recovered, all
13+
914
# Redirect to project page on index.
1015
@app.route('/')
1116
def index():
12-
return redirect('https://github.com/ExpDev07/coronavirus-tracker-api', 302)
17+
return redirect('https://github.com/ExpDev07/coronavirus-tracker-api', 302)

app/routes/v1/__init__.py

Whitespace-only changes.

app/routes/v1/all.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from flask import jsonify
22
from flask import current_app as app
33
from ...services.location.jhu import get_category
4+
from ...routes import rest_api_v1
45

5-
@app.route('/all')
6+
@rest_api_v1.route('/all')
67
def all():
78
# Get all the categories.
89
confirmed = get_category('confirmed')
@@ -21,4 +22,4 @@ def all():
2122
'deaths': deaths['latest'],
2223
'recovered': recovered['latest'],
2324
}
24-
})
25+
})

app/routes/v1/confirmed.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from flask import jsonify
22
from flask import current_app as app
33
from ...services.location.jhu import get_category
4+
from ...routes import rest_api_v1
45

5-
@app.route('/confirmed')
6+
@rest_api_v1.route('/confirmed')
67
def confirmed():
7-
return jsonify(get_category('confirmed'))
8+
return jsonify(get_category('confirmed'))

app/routes/v1/deaths.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from flask import jsonify
22
from flask import current_app as app
33
from ...services.location.jhu import get_category
4+
from ...routes import rest_api_v1
45

5-
@app.route('/deaths')
6+
@rest_api_v1.route('/deaths')
67
def deaths():
7-
return jsonify(get_category('deaths'))
8+
return jsonify(get_category('deaths'))

0 commit comments

Comments
 (0)