node-red-node-web-nodes
Version:
A collection of Node-RED nodes for popular web services.
307 lines (297 loc) • 18.9 kB
HTML
<!--
Copyright 2014, 2015 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="google places">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i>Node Name</label>
<input type="text" id="node-input-name" placeholder="Node Name">
</div>
<br />
<div class="form-row">
<label for="node-input-reqType"><i class="fa fa-tasks"></i> Request Type </label>
<select type="text" id="node-input-reqType" style="width:72%;">
<option value="placesNearby">Places Nearby</option>
<option value="placesText"> Places Text</option>
<option value="placesDetails">Place Details</option>
</select>
</div>
<br />
<div class="form-row">
<label for="node-input-googleAPI"><i class="fa fa-user"></i> Google API Key</label>
<input type="text" id="node-input-googleAPI">
</div>
<br />
<div class="form-row node-input-geocodeBy-row-coordinates placesText">
<label for="node-input-query"><i class="fa fa-question"></i> Query</label>
<input type="text" id="node-input-query" placeholder="Query">
</div>
<br class="placesText">
<div class="form-row node-input-geocodeBy-row-coordinates placesNearby placesText">
<label for="node-input-lat"><i class="fa fa-globe"></i> Latitude</label>
<input type="text" id="node-input-lat" placeholder="Latitude">
</div>
<div class="form-row node-input-geocodeBy-row-coordinates placesNearby placesText">
<label for="node-input-lon"><i class="fa fa-globe"></i> Longitude</label>
<input type="text" id="node-input-lon" placeholder="Longitude">
</div>
<div class="form-row placesDetails">
<label for="node-input-placeId"><i class="fa fa-barcode"></i> Place Id</label>
<input type="text" id="node-input-placeId" placeholder="Place Id">
</div>
<br class="placesNearby placesDetails">
<div class="form-row placesNearby placesRadius placesText">
<label for="node-input-radius"><i class="fa fa-flag"></i> Radius (m)</label>
<input type="text" id="node-input-radius" placeholder="Radius">
</div>
<div class="form-row placesNearby">
<label for="node-input-rankBy"><i class="fa fa-tasks"></i> Rank by </label>
<select type="text" id="node-input-rankBy" style="width:72%;">
<option value="prominence">Prominence</option>
<option value="distance">Distance</option>
</select>
</div>
<div class="form-row placesNearby">
<label for="node-input-keyword"><i class="fa fa-info"></i> Keyword</label>
<input type="text" id="node-input-keyword" placeholder="Keyword">
</div>
<div class="form-row placesNearby placesDetails placesText">
<label for="node-input-language"><i class="fa fa-language"></i> Language</label>
<input type="text" id="node-input-language" placeholder="Language">
</div>
<div class="form-row placesNearby placesText">
<label for="node-input-minPrice"><i class="fa fa-usd"></i> Min Price</label>
<input type="text" id="node-input-minPrice" placeholder="Min Price">
</div>
<div class="form-row placesNearby placesText">
<label for="node-input-maxPrice"><i class="fa fa-usd"></i> Max Price</label>
<input type="text" id="node-input-maxPrice" placeholder="Max Price">
</div>
<div class="form-row placesNearby">
<label for="node-input-placeName"><i class="fa fa-building"></i> Name</label>
<input type="text" id="node-input-placeName" placeholder="Name">
</div>
<div class="form-row placesNearby placesText">
<label for="node-input-types"><i class="fa fa-check-square-o"></i> Types</label>
<input type="text" id="node-input-types" placeholder="Types">
</div>
<div class="form-row placesDetails">
<label for="node-input-extensions"><i class="fa fa-code"></i> Extensions</label>
<input type="text" id="node-input-extensions" placeholder="Extensions">
</div>
<div class="form-row placesNearby placesText">
<label> </label>
<input type="checkbox" id="node-input-openNow" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-openNow" style="width: 70%;">Open Now?</label>
</div>
<div class="form-row placesNearby placesText">
<label for="node-input-outputnumber"><i class="fa fa-sign-out"></i> Output</label>
<select id="node-input-outputnumber" style="width:15% !important">
<option value=1>1</option>
<option value=5>5</option>
<option value=10>10</option>
<option value=15>15</option>
<option value=20>20</option>
</select>
result<span id="node-input-outputnumber-plural">s</span>
as <select id="node-input-outputas" style='width:40% !important'>
<option value="multiple">multiple messages</option>
<option value="single">a single message</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="google places">
<p>Utilizes the Google Places API in order to find and learn more about local establishments.</p>
<p>The node can be configured to send three different types of Places requests by toggling the <code>reqType</code> parameter in the node.</p>
<br>
<p>Google Places Nearby</p>
<p>Input Parameters:</p>
<p><code>Name</code> - Name of the node</p>
<p><code>reqType</code> - Toggle to switch between a Places Nearby, Places Text, and Places Details request.</p>
<p>All of the following parameters can be supplied as part of the top level <code>msg</code> object.</p>
<p><code>msg.key</code> - Your application's API key. This key identifies your application for purposes of quota management. <b><i>(Required)</i></b></p>
<p><code>msg.location.lat</code> - Latitude point to be sent to Google in order to be converted to a human-readable address. <b><i>(Required)</i></b></p>
<p><code>msg.location.lon</code> - Longitude point to be sent to Google in order to be converted to a human-readable address. <b><i>(Required)</i></b></p>
<br>
<p><code>msg.location.radius</code> - Defines the distance (in meters) within which to return place results. The maximum allowed radius is 50000 meters. <b><i>(Required if rankby=prominence. If rankby=distance, radius is not allowed)</i></b></p>
<p><code>msg.keyword</code> - A term to be matched against all content that Google has indexed for this place, including but not limited to name, type, and address, as well as customer reviews and other third-party content.</p>
<p><code>msg.language</code> - The language in which to return results.</p>
<p><code>msg.minprice</code> - Restricts results to only those places within the specified price level. Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive.</p>
<p><code>msg.maxprice</code> - Restricts results to only those places within the specified price level. Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive.</p>
<p><code>msg.name</code> - The name of the business to search for.</p>
<p><code>msg.types</code> - Restricts the results to places matching at least one of the specified types. Types should be separated with a pipe symbol (type1|type2|etc). (<a href="https://developers.google.com/places/documentation/supported_types">Click here</a> for supported types)</p>
<p><code>msg.opennow</code> - If set to true, will only return results that are currently open now.</p>
<br>
<p>Return values:</p>
<p><code>msg.status</code> - Will either be 'OK' or provide an error state.</p>
<p>If <code>msg.status</code> returned 'OK':
<p><code>msg.location</code> - Will contain <code>lat</code>, <code>lon</code>, and <code>address</code></p>
<p><code>msg.placeid</code> - A unique identifier for a place. To retrieve information about the place, pass this identifier in the placeId field of a Places API request.</p>
<p><code>msg.payload</code> - <br>
<code>{<br>
<b>placeid</b> - A unique identifier for a place. To retrieve information about the place, pass this identifier in the placeId field of a Places API request.<br>
<b>name</b> - The name of the establishment<br>
<b>vicinity</b> - Contains a feature name of a nearby location. Often this feature refers to a street or neighborhood within the given results.<br>
<b>types</b> - Contains an array of feature types describing the given result<br>
<b>pricelevel</b> - The price level of the place, on a scale of 0 to 4 (0-Free 1-Inexpensive 2-Moderate 3-Expensive 4-Very Expensive).<br>
<b>rating</b> - Contains the place's rating, from 1.0 to 5.0, based on aggregated user reviews.<br>
<b>opennow</b> - Boolean that shows whether the establishment is currently open.<br>
}</code>
<br>
<p>Otherwise:</p>
<p><code>msg.error</code> will contain a more detailed error message, if available</p>
<br><br>
<p>Google Places Text</p>
<p>Input Parameters:</p>
<p><code>Name</code> - Name of the node</p>
<p><code>reqType</code> - Toggle to switch between a Places Nearby, Places Text, and Places Details request.</p>
<p>All of the following parameters can be supplied as part of the top level <code>msg</code> object.</p>
<p><code>msg.key</code> - Your application's API key. This key identifies your application for purposes of quota management. <b><i>(Required)</i></b></p>
<p><code>msg.query</code> - The text string on which to search, for example: "restaurant". The Google Places service will return candidate matches based on this string and order the results based on their perceived relevance. <b><i>(Required)</i></b></p>
<br>
<p><code>msg.location.lat</code> - Latitude point to be sent to Google in order to be converted to a human-readable address.</p>
<p><code>msg.location.lon</code> - Longitude point to be sent to Google in order to be converted to a human-readable address.</p>
<p><code>msg.location.radius</code> - Defines the distance (in meters) within which to return place results. The maximum allowed radius is 50000 meters.</p>
<p><code>msg.keyword</code> - A term to be matched against all content that Google has indexed for this place, including but not limited to name, type, and address, as well as customer reviews and other third-party content.</p>
<p><code>msg.language</code> - The language in which to return results.</p>
<p><code>msg.minprice</code> - Restricts results to only those places within the specified price level. Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive.</p>
<p><code>msg.maxprice</code> - Restricts results to only those places within the specified price level. Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive.</p>
<p><code>msg.types</code> - Restricts the results to places matching at least one of the specified types. Types should be separated with a pipe symbol (type1|type2|etc). (<a href="https://developers.google.com/places/documentation/supported_types">Click here</a> for supported types)</p>
<p><code>msg.opennow</code> - If set to true, will only return results that are currently open now.</p>
<br>
<p>Return values:</p>
<p><code>msg.status</code> - Will either be 'OK' or provide an error state.</p>
<p>If <code>msg.status</code> returned 'OK':
<p><code>msg.title</code> - The name of the establishment.
<p><code>msg.location</code> - Will contain <code>lat</code>, <code>lon</code>, and <code>address</code></p>
<p><code>msg.placeid</code> - A unique identifier for a place. To retrieve information about the place, pass this identifier in the placeId field of a Places API request.</p>
<p><code>msg.payload</code> - Will contain the name and address of the result.
<p><code>msg.detailsJson</code> - <br>
<code>{<br>
<b>placeid</b> - A unique identifier for a place. To retrieve information about the place, pass this identifier in the placeId field of a Places API request.<br>
<b>name</b> - The name of the establishment<br>
<b>address</b> - Human readable address of the establishment<br>
<b>types</b> - Contains an array of feature types describing the given result<br>
<b>pricelevel</b> - The price level of the place, on a scale of 0 to 4 (0-Free 1-Inexpensive 2-Moderate 3-Expensive 4-Very Expensive).<br>
<b>rating</b> - Contains the place's rating, from 1.0 to 5.0, based on aggregated user reviews.<br>
}</code>
<br>
<p>Otherwise:</p>
<p><code>msg.error</code> will contain a more detailed error message, if available</p>
<br><br>
<p>Google Places Details</p>
<p>Input Parameters:</p>
<p><code>Name</code> - Name of the node</p>
<p><code>reqType</code> - Toggle to switch between a Places Nearby, Places Text, and Places Details request.</p>
<p>All of the following parameters can be supplied as part of the top level <code>msg</code> object.</p>
<p><code>msg.key</code> - Your application's API key. This key identifies your application for purposes of quota management. <b><i>(Required)</i></b></p>
<p><code>msg.placeid</code> - A unique identifier that is returned from a Google Places request. <b><i>(Required)</i></b></p>
<br>
<p><code>msg.language</code> - The language in which to return results.</p>
<p><code>msg.extensions</code> - Indicates if the Place Details response should include additional fields. Additional fields may include Premium data, requiring an additional license, or values that are not commonly requested. Extensions are currently experimental. Supported values for the extensions parameter are {review_summary}.</p>
<br>
<p>Return values:</p>
<p><code>msg.status</code> - Will either be 'OK' or provide an error state.</p>
<p>If <code>msg.status</code> returned 'OK':
<p><code>msg.location</code> - Will contain <code>lat</code>, <code>lon</code>, and <code>address</code></p>
<p><code>msg.payload</code> - <br>
<code>{<br>
<b>name</b> - The name of the establishment<br>
<b>address</b> - Human readable address of the establishment<br>
<b>phone</b> - Locally formatted phone number for the establishment<br>
<b>website</b> - The web address for the establishment<br>
<b>rating</b> - Contains the place's rating, from 1.0 to 5.0, based on aggregated user reviews.<br>
<b>pricelevel</b> - The price level of the place, on a scale of 0 to 4 (0-Free 1-Inexpensive 2-Moderate 3-Expensive 4-Very Expensive).<br>
<b>opennow</b> - Boolean that shows whether the establishment is currently open.<br>
<b>open</b> - Will return the day (0-6) and time (0000-2359) that the establishment is open.
<b>close</b> - Will return any day (0-6) that the establishment is closed.
<b>permanently_closed</b> - Will return true if the establishment is permanently closed.<br>
}</code>
<br>
<p>Otherwise:</p>
<p><code>msg.error</code> will contain a more detailed error message, if available</p>
<br><br>
<p>For more information, please visit the <a href="https://developers.google.com/maps/documentation/geocoding/">Google Geocoding API Developer Docs</a>
</script>
<script type="text/javascript">
RED.nodes.registerType('google places',{
category: 'social',
color: '#ff9999',
defaults: {
reqType: {value:""},
googleAPI: {type:"google-api-config", required: false},
name: {value:""},
lat: {value:""},
lon: {value:""},
query: {value:""},
radius: {value:""},
rankBy: {value:""},
keyword: {value:""},
language: {value:""},
minPrice: {value:""},
maxPrice: {value:""},
placeName: {value:""},
placeId: {value:""},
extensions: {value:""},
openNow: {value:""},
types: {value:""},
outputnumber:{value:"1"},
outputas:{value:"single"}
},
inputs:1,
outputs:1,
icon: "logo_maps.png",
label: function() {
if(this.reqType === 'placesNearby')
return this.name||"Places Nearby Search";
else if(this.reqType === 'placesText')
return this.name||"Places Text Search";
else if(this.reqType === 'placesDetails')
return this.name||"Places Details Search";
else
return this.name||"Google Places";
},
oneditprepare: function() {
$("#node-input-reqType").change(function() {
if ($(this).val() === 'placesNearby') {
$(".placesDetails").hide();
$(".placesText").hide();
$(".placesNearby").show();
} else if ($(this).val() === 'placesDetails') {
$(".placesNearby").hide();
$(".placesText").hide();
$(".placesDetails").show();
} else if ($(this).val() === 'placesText') {
$(".placesNearby").hide();
$(".placesDetails").hide();
$(".placesText").show();
}
});
$("#node-input-rankBy").change(function() {
if ($(this).val() === 'prominence') {
$(".placesRadius").show();
} else if ($(this).val() === 'distance') {
$(".placesRadius").hide();
}
});
var updateOptions = function() {
var outputnumber = $("#node-input-outputnumber option:selected").val();
if (outputnumber === 1) {
$("#node-input-outputnumber-plural").hide();
} else {
$("#node-input-outputnumber-plural").show();
}
};
updateOptions();
$("#node-input-outputnumber").change(updateOptions);
}
});
</script>