-
Notifications
You must be signed in to change notification settings - Fork 2
Structure
Tao Peter Wang edited this page Aug 5, 2016
·
7 revisions
The Geofence Server is built on Node.js with express module.
The server responds to the following requests on port 3000:
/db/user-fetch
- Method: GET
- Queries user information: balance
- Query Parameters: userId
/db/user-create
- Method: POST
- Creates or finds (and logs in) a user
- Body Parameters: userId, gcmToken
/db/task-add
- Method: POST
- Adds a task for other users to complete
- Body Parameters: userId, taskName, cost, expiresAt, refreshRate, locationName, lat, lng, radius, answersLeft, [taskActions]
/db/task-respond
- Method: POST
- Submits a response to a task
- Body Parameters: userId, taskId, [taskResponses]
/db/task-sync
- Method: GET
- Syncs changes between local storage and server database, returns a change log
- Query Parameters: lastUpdated
/db/task-fetch
- Method: GET
- Pulls a single task from server
- Query Parameters: taskId
/db/task-deactivate/{taskId}
- Method: GET
- Deactivate a task
/db/task-delete/{taskId}
- Method: GET
- Delete a task permanently
/db/response-fetch
- Method: GET
- Fetch all responses to a task
- Query Parameters: taskId
To send update notifications to client apps, write a separate update.js file utilizing code below
const request = require('request');
options = {
url: "https://gcm-http.googleapis.com/gcm/send",
method: "POST",
json: true, // this automatically adds "Content-Type": "application/json" to header
headers: {
"Authorization": "key=whatever-the-latest-key-is"
}
}
options.body = {
to: "/topics/global",
data: {
update: "1",
version: "{Version}"
}
}
request(options, function(err, res, body) {
if (err) {
console.error(err);
}
});