Skip to content

Commit 7005355

Browse files
author
Chris Wiechmann
committed
Removed debugger statements
1 parent a7d0683 commit 7005355

File tree

10 files changed

+228
-11
lines changed

10 files changed

+228
-11
lines changed

api-builder-plugin-fn-aws-athena/src/actions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const aws = require("aws-sdk");
1212
* @return {undefined}
1313
*/
1414
function query(req, outputs, options) {
15-
debugger;
1615
const awsConfig = this.pluginConfig.aws;
1716
const db = req.params.db;
1817
const table = req.params.table;

api-builder-plugin-fn-aws-athena/test/test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const { MockRuntime } = require('@axway/api-builder-sdk');
33

44
const getPlugin = require('../src');
55
const actions = require('../src/actions');
6-
debugger;
76
const validPluginConfig = require('./config/aws-athena.testconfig').pluginConfig['@axway-api-builder-ext/api-builder-plugin-fn-aws-athena'];
87
const invalidPluginConfig = require('./config/aws-athena.incomplete').pluginConfig['@axway-api-builder-ext/api-builder-plugin-fn-aws-athena'];
98

@@ -116,7 +115,6 @@ describe('Valid PluginConfig tests', () => {
116115

117116
const result = await flowNode.query({ table: 'elb_logs', db: 'sampledb', fields: 'elb_name, request_ip'});
118117

119-
debugger;
120118
expect(result.callCount).to.equal(1);
121119
expect(result.output).to.equal('next');
122120
expect(result.args).to.be.an('Array');
@@ -131,7 +129,6 @@ describe('Valid PluginConfig tests', () => {
131129

132130
const result = await flowNode.query({ table: 'elb_logs', db: 'sampledb', fields: 'elb_name, request_port', limit: '1' });
133131

134-
debugger;
135132
expect(result.callCount).to.equal(1);
136133
expect(result.output).to.equal('next');
137134
expect(result.args).to.be.an('Array');

api-builder-plugin-fn-google-maps/src/elevation.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ function elevation(req, outputs, options) {
4040
key: apiKey,
4141
locations: locations
4242
}
43-
debugger;
4443
client
4544
.elevation({
4645
params: params,

api-builder-plugin-fn-google-maps/src/google-maps.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,52 @@ flow-nodes:
368368
context: $.error
369369
schema:
370370
type: string
371+
# Reverse-Geocoding API
372+
reverseGeocode:
373+
name: Reverse Geocoding
374+
description: Reverse geocoding request and response (address lookup)
375+
parameters:
376+
latlng:
377+
description: 'The latitude and longitude values specifying the location for which you wish to obtain the closest, human-readable address.'
378+
required: false
379+
schema:
380+
type: string
381+
place_id:
382+
description: 'The place ID of the place for which you wish to obtain the human-readable address. The place ID is a unique identifier that can be used with other Google APIs. For example, you can use the `placeID` returned by the Roads API to get the address for a snapped point. The place ID may only be specified if the request includes an API key or a Google Maps APIs Premium Plan client ID.'
383+
required: false
384+
schema:
385+
type: string
386+
language:
387+
description: 'The language in which to return results. Google often updates the supported languages, so this list may not be exhaustive.'
388+
required: false
389+
schema:
390+
type: string
391+
result_type:
392+
description: 'A filter of one or more address types, separated by a pipe (`|`). If the parameter contains multiple address types, the API returns all addresses that match any of the types. A note about processing: The `result_type` parameter does not restrict the search to the specified address type(s). Rather, the `result_type` acts as a post-search filter: the API fetches all results for the specified `latlng`, then discards those results that do not match the specified address type(s). Note: This parameter is available only for requests that include an API key or a client ID.'
393+
required: false
394+
schema:
395+
type: array
396+
location_type:
397+
description: 'A filter of one or more location types, separated by a pipe (`|`). If the parameter contains multiple location types, the API returns all addresses that match any of the types. A note about processing: The `location_type` parameter does not restrict the search to the specified location type(s). Rather, the `location_type` acts as a post-search filter: the API fetches all results for the specified `latlng`, then discards those results that do not match the specified location type(s). Note: This parameter is available only for requests that include an API key or a client ID.'
398+
required: false
399+
schema:
400+
type: array
401+
outputs:
402+
next:
403+
name: Next
404+
description: Success
405+
context: $.result
406+
schema:
407+
type: string
408+
notFound:
409+
name: Not found
410+
description: The given address could not be found.
411+
context: $.notFound
412+
schema:
413+
type: string
414+
error:
415+
name: Error
416+
description: An error occured.
417+
context: $.error
418+
schema:
419+
type: string

api-builder-plugin-fn-google-maps/src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { directions } = require('./directions')
44
const { distance } = require('./distance')
55
const { elevation } = require('./elevation')
66
const { geocode } = require('./geocode')
7+
const { reverseGeocode } = require('./reverseGeocode')
78
const { findPlaceFromText } = require('./places/findPlaceFromText')
89
const { textSearch } = require('./places/textSearch')
910
const { placeDetails } = require('./places/placeDetails')
@@ -16,14 +17,14 @@ const { placesNearby } = require('./places/placesNearby')
1617
*/
1718
async function getPlugin(pluginConfig, options) {
1819
const sdk = new SDK();
19-
debugger;
20-
sdk.load(path.resolve(__dirname, 'google-maps.yml'), { directions, distance, elevation, geocode });
20+
sdk.load(path.resolve(__dirname, 'google-maps.yml'), { directions, distance, elevation, geocode, reverseGeocode });
2121
sdk.load(path.resolve(__dirname, 'google-maps-places.yml'), { findPlaceFromText, textSearch, placeDetails, placesNearby });
2222
const plugin = sdk.getPlugin();
2323
plugin.flownodes['googleMaps'].methods.directions.action = directions.bind({pluginConfig});
2424
plugin.flownodes['googleMaps'].methods.distance.action = distance.bind({pluginConfig});
2525
plugin.flownodes['googleMaps'].methods.elevation.action = elevation.bind({pluginConfig});
2626
plugin.flownodes['googleMaps'].methods.geocode.action = geocode.bind({pluginConfig});
27+
plugin.flownodes['googleMaps'].methods.reverseGeocode.action = reverseGeocode.bind({pluginConfig});
2728

2829
plugin.flownodes['googleMapsPlaces'].methods.findPlaceFromText.action = findPlaceFromText.bind({pluginConfig});
2930
plugin.flownodes['googleMapsPlaces'].methods.textSearch.action = textSearch.bind({pluginConfig});

api-builder-plugin-fn-google-maps/src/places/findPlaceFromText.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ function findPlaceFromText(req, outputs, options) {
5454
fields: fields,
5555
locationbias: locationbias
5656
}
57-
debugger;
5857
client
5958
.findPlaceFromText({
6059
params: params,

api-builder-plugin-fn-google-maps/src/places/placeDetails.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ function placeDetails(req, outputs, options) {
2222
const sessiontoken = req.params.sessiontoken;
2323
const fields = req.params.fields;
2424

25-
debugger;
26-
2725
if(typeof this.pluginConfig.google === 'undefined') {
2826
options.logger.error('Google-Configuration not found. Please make sure conf/google-maps.default.js is present and configured.');
2927
return outputs.error(null, {message: 'Google-Configuration not found. Please make sure conf/google-maps.default.js is present and configured.'});
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const maps = new require("@googlemaps/google-maps-services-js");
2+
3+
/**
4+
* Action method.
5+
* @param {object} req - The flow request context passed in at runtime. The
6+
* parameters are resolved as `req.params` and the available authorization
7+
* credentials are passed in as `req.authorizations`.
8+
* @param {object} outputs - A set of output callbacks. Use it to signal an
9+
* event and pass the output result back to the runtime. Only use an
10+
* output callback once and only after all asyncronous tasks complete.
11+
* @param {object} options - The additional options provided from the flow
12+
* engine.
13+
* @param {object} The logger from API Builder that can be used to log messages
14+
* to the console. See https://docs.axway.com/bundle/API_Builder_4x_allOS_en/page/logging.html
15+
*
16+
* @return {undefined}
17+
*/
18+
function reverseGeocode(req, outputs, options) {
19+
if ((req.params == null) || (!req.params.latlng && !req.params.place_id)) {
20+
options.logger.error('You must at least provide latlng or place_id');
21+
return outputs.error(null, {message:'You must at least provide latlng or place_id'});
22+
}
23+
const latlng = req.params.latlng;
24+
const place_id = req.params.place_id;
25+
const language = req.params.language;
26+
const result_type = req.params.result_type;
27+
const location_type = req.params.location_type;
28+
29+
const apiKey = this.pluginConfig.google.credentials.apiKey;
30+
31+
if(typeof apiKey === 'undefined')
32+
{
33+
options.logger.error('Google API-Key is missing. Please complete your configuration in conf/google-maps.default.js');
34+
return outputs.error(null, {message: 'Google API-Key is missing. Please complete your configuration in conf/google-maps.default.js'});
35+
}
36+
37+
const client = new maps.Client({});
38+
39+
var params = {
40+
key: apiKey,
41+
language: language,
42+
result_type: result_type,
43+
location_type: location_type
44+
}
45+
46+
if(typeof latlng != 'undefined') {
47+
params.latlng = latlng;
48+
}
49+
if(typeof place_id != 'undefined') {
50+
params.place_id = place_id;
51+
}
52+
53+
client
54+
.reverseGeocode({
55+
params: params,
56+
timeout: 10000 // milliseconds
57+
})
58+
.then(response => {
59+
if(response.data.status == 'ZERO_RESULTS') {
60+
return outputs.notFound(null, response.data);
61+
} else if(response.data.status != 'OK') {
62+
options.logger.error(`Error: ` + JSON.stringify(response.data));
63+
return outputs.error(null, {message: response.data});
64+
} else {
65+
return outputs.next(null, response.data);
66+
}
67+
})
68+
.catch(error => {
69+
options.logger.error('Error: ' + JSON.stringify(error.response.data));
70+
return outputs.error(null, {message: error.response.data});
71+
})
72+
}
73+
74+
module.exports = {
75+
reverseGeocode
76+
};
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
const { expect } = require('chai');
2+
const { MockRuntime } = require('@axway/api-builder-sdk');
3+
4+
const getPlugin = require('../src');
5+
const actions = require('../src/reverseGeocode');
6+
7+
const validPluginConfig = require('./config/google-maps.testconfig').pluginConfig['@axway-api-builder-ext/api-builder-plugin-fn-google-maps'];
8+
const invalidPluginConfig = require('./config/google-maps.incomplete').pluginConfig['@axway-api-builder-ext/api-builder-plugin-fn-google-maps'];
9+
10+
describe('Google-Maps Reverse-Geocode-API Tests', () => {
11+
let runtime;
12+
before(async () => invalidRuntime = new MockRuntime(await getPlugin(invalidPluginConfig)));
13+
before(async () => runtime = new MockRuntime(await getPlugin(validPluginConfig)));
14+
15+
describe('#constructor', () => {
16+
it('should define flow-nodes', () => {
17+
expect(actions).to.be.an('object');
18+
expect(actions.reverseGeocode).to.be.a('function');
19+
expect(runtime).to.exist;
20+
const flownode = runtime.getFlowNode('googleMaps');
21+
expect(flownode).to.be.a('object');
22+
expect(flownode.name).to.equal('Google Maps');
23+
});
24+
25+
it('should define valid flow-nodes', () => {
26+
expect(runtime.validate()).to.not.throw;
27+
});
28+
});
29+
30+
describe('#reverseGeocode', () => {
31+
it('should error when neither latLng or place_id is given', async () => {
32+
const flowNode = runtime.getFlowNode('googleMaps');
33+
34+
const result = await flowNode.reverseGeocode({
35+
place_id: null,
36+
latlng: null
37+
});
38+
39+
expect(result.callCount).to.equal(1);
40+
expect(result.output).to.equal('error');
41+
expect(result.args[0]).to.equal(null);
42+
expect(result.context).to.be.an('Object');
43+
expect(result.context.error).to.have.property('message', 'You must at least provide latlng or place_id');
44+
});
45+
46+
it('should error if not configured - API-Key is missing', async () => {
47+
const flowNode = invalidRuntime.getFlowNode('googleMaps');
48+
49+
const result = await flowNode.reverseGeocode({
50+
place_id: 'ChIJQxkLC8ZQqEcRdfnVRF5vXVs'
51+
});
52+
53+
expect(result.callCount).to.equal(1);
54+
expect(result.output).to.equal('error');
55+
expect(result.args[0]).to.equal(null);
56+
expect(result.context).to.be.an('Object');
57+
expect(result.context.error).to.have.property('message', 'Google API-Key is missing. Please complete your configuration in conf/google-maps.default.js');
58+
});
59+
60+
it('Invalid request with no params given at all', async () => {
61+
const flowNode = runtime.getFlowNode('googleMaps');
62+
63+
const result = await flowNode.reverseGeocode({});
64+
65+
expect(result.callCount).to.equal(1);
66+
expect(result.output).to.equal('error');
67+
expect(result.args[0]).to.equal(null);
68+
expect(result.context).to.be.an('Object');
69+
expect(result.context.error).to.have.property('message', 'You must at least provide latlng or place_id');
70+
});
71+
72+
it('Valid request with a given place_id', async () => {
73+
const flowNode = runtime.getFlowNode('googleMaps');
74+
75+
const result = await flowNode.reverseGeocode({
76+
place_id: 'ChIJQxkLC8ZQqEcRdfnVRF5vXVs'
77+
});
78+
79+
expect(result.callCount).to.equal(1);
80+
expect(result.output).to.equal('next');
81+
expect(result.args[0]).to.equal(null);
82+
expect(result.context).to.be.an('Object');
83+
expect(result.context.result).to.deep.include({ status: 'OK' });
84+
});
85+
86+
it('Request with an invalid place_id', async () => {
87+
const flowNode = runtime.getFlowNode('googleMaps');
88+
89+
const result = await flowNode.reverseGeocode({
90+
place_id: 'ChIJQxkLC8ZQqEcRdabVRF5vXVs'
91+
});
92+
93+
expect(result.callCount).to.equal(1);
94+
expect(result.output).to.equal('notFound');
95+
expect(result.args[0]).to.equal(null);
96+
expect(result.context).to.be.an('Object');
97+
expect(result.context.notFound).to.deep.include({ status: 'ZERO_RESULTS' });
98+
});
99+
});
100+
});

api-builder-plugin-fn-xml-node/src/xmlToJson.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ function xmlToJson(req, cb) {
5656
console.log(e.message);
5757
cb.error(null, 'Failed to convert XML to JSON.');
5858
}
59-
//debugger;
6059
if(typeof result === 'undefined') {
6160
cb.error(null, 'Failed to convert XML to JSON.');
6261
}

0 commit comments

Comments
 (0)