Skip to content

Commit

Permalink
add place text-search api
Browse files Browse the repository at this point in the history
  • Loading branch information
jettcalleja committed Nov 23, 2016
1 parent acf0f74 commit dcf5fdc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/config/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
"sensor": "string",
"types": "string"
},
"place-text": {
"location": "string",
"radius": "string",
"language": "string",
"maxprice": "number",
"minprice": "number",
"opennow": "boolean",
"pagetoken": "string",
"sensor": "string",
"type": "string",
"types": "string",
"zagatselected": "string",
"query": "string"
},
"place-details": {
"placeid": "string",
"extensions": "string",
Expand Down Expand Up @@ -120,6 +134,7 @@
"geocode": "/maps/api/geocode/json",
"place-details": "/maps/api/place/details/json",
"place-search": "/maps/api/place/nearbysearch/json",
"place-text": "/maps/api/place/textsearch/json",
"place-autocomplete":"/maps/api/place/autocomplete/json",
"static-map": "/maps/api/staticmap",
"timezone": "/maps/api/timezone/json",
Expand Down
10 changes: 10 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var ACCEPTED_CONFIG_KEYS = _constants.ACCEPTED_CONFIG_KEYS;
var GOOGLEMAPS_ENDPOINTS = _constants.GOOGLEMAPS_ENDPOINTS;

var api = {
placeText: require('./placeText'),
placeSearch: require('./placeSearch'),
placeDetails: require('./placeDetails'),
placeAutocomplete: require('./placeAutocomplete'),
Expand Down Expand Up @@ -82,6 +83,15 @@ var GoogleMapsAPI = function(config, request) {
*/
GoogleMapsAPI.prototype.placeSearch = api.placeSearch

/**
* Endpoint: /maps/api/place/textsearch/json
* Google documentation reference: https://developers.google.com/places/documentation/search
*
* TODO: Maps API for Work customers should not include a client or signature parameter with their requests.
* TODO: params zagatselected
*/
GoogleMapsAPI.prototype.placeText = api.placeText

/**
*
* Endpoint: '/maps/api/place/details/json'
Expand Down
40 changes: 40 additions & 0 deletions lib/placeText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Modules from the community: package.json
*/
var check = require('check-types');

/**
* Internal modules
*/
var _makeRequest = require('./utils/makeRequest');
var _assignParams = require('./utils/assignParams');
var _jsonParser = require('./utils/jsonParser');

var _constants = require('./config/constants');

var ACCEPTED_PARAMS = _constants.ACCEPTED_PARAMS;
var GOOGLEMAPS_ENDPOINTS = _constants.GOOGLEMAPS_ENDPOINTS;

module.exports = function(params, callback) {

if (typeof callback !== 'function') {
throw new TypeError('callback must be present');
}

if (this.config.key == null) {
return callback(new Error('The placeSearch API requires a key. You can add it to the config.'));
}

if (!check.object(params)) {
return callback(new TypeError('params must be an object'));
}

var args = _assignParams({}, params, ACCEPTED_PARAMS['place-text']);

if (args.query == null) {
return callback(new Error('params.query is required'));
}

return _makeRequest(this.request, this.config, GOOGLEMAPS_ENDPOINTS['place-text'], args, _jsonParser(callback));

};

0 comments on commit dcf5fdc

Please sign in to comment.