Skip to content

Commit f62918f

Browse files
committed
Proposed JSON communication, some structure in controller, changed handler to received a raw JSON
1 parent 3c7fcf3 commit f62918f

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

application/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def inject_profiler():
4444
# Enable jinja2 loop controls extension
4545
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
4646

47-
# Pull in URL dispatch routes
47+
# Pull in URL dispatch routes - here all blueprints are registered
4848
app.register_blueprint(home)
4949
# app.register_blueprint(external_api)
5050
app.register_blueprint(handler)

application/controller/controller.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,30 @@
1212
from application import app
1313

1414
from servers import police
15-
16-
def main():
15+
#takes python object representation fo the received JSON object
16+
def main(data):
17+
location = data["location"]
18+
if location:
19+
processLocation(location)
20+
features = data["features"]
21+
if features:
22+
processFeatures(features)
1723
#test response will be the response from
1824
#the module taking care of a communication
1925
#with some external API
2026
#we parse that response with the PARSER
2127
#and return it to the request handler
2228
test_response = police.getCategories()
29+
2330
temp = test_response.read()
2431

25-
return temp
32+
return temp
33+
def processLocation(location):
34+
#TODO
35+
return
36+
#takes array fo features
37+
def processFeatures(features):
38+
for feature in features:
39+
#TODO
40+
print feature['name']
41+

application/request_handler/handler.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@
2727
calls the controller method which returns the JSON object which the client expect,
2828
and then finally, send the result(the json) back to the client
2929
'''
30+
'''
31+
body of the request has to contain JSON object with the following schema:
32+
{ "location" : "Some location name or null",
33+
"features" : [{"name" : "feature_name","args" : {"arg_name":"value"}}
34+
]
35+
}
36+
'''
37+
3038
@handler.route('/app/', methods=['POST'])
3139
def handleReq():
3240
#extract the data sent from the client
3341
#the POST request's body should contain a key-value pair and the name of the key is 'data'
34-
input_data = request.form['data']
35-
result = controller.main()
42+
print "inside POST request handler"
43+
input_data = request.data
44+
print "data received ",input_data
45+
input_data = json.loads(input_data)
46+
result = controller.main(input_data)
3647
return result
3748

3849

example_request.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{ "location" : "Some location name or null",
2+
"features" : [{"name" : "feature_name","args" : {"arg_name":"value"}},
3+
{"name" : "new_name","args" : {"arg_name":"value"}}
4+
]
5+
}

geoJSONproposed.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{ "type": "FeatureCollection",
2+
"features": [
3+
{ "type": "Feature",
4+
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
5+
"properties": {
6+
"name": "value0",
7+
"value": 0.0
8+
}
9+
},
10+
{ "type": "Feature",
11+
"geometry": {
12+
"type": "LineString",
13+
"coordinates": [
14+
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
15+
]
16+
},
17+
"properties": {
18+
"name": "value0",
19+
"value": 0.0
20+
}
21+
},
22+
{ "type": "Feature",
23+
"geometry": {
24+
"type": "Polygon",
25+
"coordinates": [
26+
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
27+
[100.0, 1.0], [100.0, 0.0] ]
28+
]
29+
},
30+
"properties": {
31+
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]}
32+
}
33+
}
34+
],
35+
""
36+
}

0 commit comments

Comments
 (0)