Google Places API Gateway

A simple Java API management gateway for the Google Place Search API.

View the Project on GitHub pkoenig10/google-places-api-gateway

Google Places API Gateway

A simple Java API management gateway for the Google Place Search API. The gateway writes all requests and response to a database and allows users to query this database to analyze gateway usage. The gateway also supports user authentication to only allow access to registered users and to track user activity on the gateway.

Documenatation for the Google Place Search API can be found at https://developers.google.com/places/documentation/search

Installation and Setup

To run the gateway simply pull the source code from this repostory. Open the Java project and run the file Gateway.java. The default configuration listens on port 8080 and writes searches and results to a local SQLite database. The port number can be changed in the source code. The database connection information can be changed in the gateway.properties file, which is read by the gateway on startup.

Database Configuration

The connection database requires three tables

Searches table

The following command creates a correctly formatted searches table on an SQLite database

CREATE TABLE searches (
id serial primary key,
sessionid uuid not null,
timestamp timestamp not null,
searchtype text,
user text,
query text,
key text,
location text,
radius text,
keyword text,
language text,
minprice text,
maxprice text,
name text,
opennow text,
rankby text,
types text,
pagetoken text,
zagatselected text);

Results table

The following command creates a correctly formatted results table on an SQLite database

CREATE TABLE results (
id serial primary key,
sessionid uuid not null,
timestamp timestamp not null,
user text,
placeid text,
lat real,
lng real);

Users table

The following command creates a correctly formatted users table on an SQLite database

CREATE TABLE users (
id serial primary key,
sessionid uuid not null,
username text not null,
salt text not null,
passhash text not null);

Search Requests

Search request allow for using the Google Place Search API to search for places based on a number of parameters. The Google Place Search API consists of three types of searches

A gateway place search request is a HTTP request of the following form

http://<hostname>:<port>/google-places-api-gateway/<searchtype>?<parameters>

hostname is the hostname of the gateway.

port is the port the gateway is listening on.

seachtype is one of the following values

parameters are the parameters for the search. For each search type, the gateway requires all required parameters and supports all optional parameters detailed in the Google Place Search API documentation. In addition the gateway also supports the following optional parameters

Query Requests

Query requests allow for querying the database of past searches and results. There are two types of gateway queries

Search Query

A gateway search query request is a HTTP request of the following form

http://<hostname>:<port>/google-places-api-gateway/searchquery?<parameters>

hostname is the hostname of the gateway.

port is the port the gateway is listening on.

parameters are the parameters for the query. For any specified parameter, the query will only return records with values equal to that parameter. A Search Query supports all required and optional search parameters for any type of search detailed in the Google Place Search API documentation. In addition the gateway also supports the following Search Query parameters

Result Query

A gateway result query request is a HTTP request of the following form

http://<hostname>:<port>/google-places-api-gateway/resultquery?<parameters>

hostname is the hostname of the gateway.

port is the port the gateway is listening on.

parameters are the parameters for the query. For any specified parameter, the query will only return records with values equal to that parameter. The gateway supports the following Result Query parameters

User Requests

The gateway supports user authentication to only allow access to registered users. The gateway can be configured to allow or deny requests from users who do not provide credentials in their request. User request allow for new users to be added to the database.

A gateway Add User request is a HTTP request of the following form

http://<hostname>:<port>/google-places-api-gateway/adduser?newusername=<username>&newpassword=<password>

hostname is the hostname of the gateway.

port is the port the gateway is listening on.

username is the username of the user to be added

password is the password of the user to be added

The gateway will return an error response if the new username already exists in the database.

Output

All output is returned in JavaScript Object Notation (JSON). All repsonses have the following fields

The output for search requests is simply forwarded repsonse from the Google Place Search API. The output is identical to the output detailed in the Google Place Search API documentation.

The output for query requests contains the results of the query are placed in the results field. The status field indiciates whether the query was successul.

The output for query requests contains an empty results field. The status field indiciates whether the request was successful.

Status Codes

The output for search requests contains status codes detailed in the Google Place Search API documentation. In addition the gateway may also output the following status codes