UNPKG

node-red-node-web-nodes

Version:

A collection of Node-RED nodes for popular web services.

305 lines (282 loc) 13.8 kB
<!-- Copyright 2014 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="foursquare-credentials"> <div id="node-config-foursquare-app-keys"> <div class="form-row"> <p style="margin-top: 10px;"><b>1.</b> Create your own app at <a href="https://foursquare.com/developers/apps" target="_blank" style="text-decoration:underline;">foursquare.com</a></p> </div> <div class="form-tips" id="node-config-foursquare-tooltip"> </div> <div class="form-row"> <p style="margin-top: 10px;"><b>2.</b> Copy the app details here:</p> </div> <div class="form-row"> <label style="margin-left: 10px; margin-right: -10px;" for="node-config-input-client_id"><i class="fa fa-user"></i> Client ID</label> <input type="password" id="node-config-input-client_id"> </div> <div class="form-row"> <label style="margin-left: 10px; margin-right: -10px;" for="node-config-input-client_secret"><i class="fa fa-key"></i> Client Secret</label> <input type="password" id="node-config-input-client_secret"> </div> <div class="form-row"> <label>&nbsp;</label> <a class="btn" id="node-config-start-auth" href="#" target="_blank">Authenticate with Foursquare</a> </div> </div> <div id="node-config-foursquare-user"> <div class="form-row"> <label><i class="fa fa-user"></i> Foursquare User</label><span id="node-config-foursquare-displayname" class="input-xlarge uneditable-input"></span> </div> <input type="hidden" id="node-config-input-displayname"> </div> </script> <script type="text/javascript"> (function() { RED.nodes.registerType('foursquare-credentials',{ category: 'config', defaults: { displayname: {value:""} }, credentials: { displayname: {type:"text", required: true}, clientid: {type:"password",required:true}, clientsecret: {type: "password",required:true}, accesstoken: {type: "password", required:true} }, label: function() { return this.displayname; }, exportable: false, oneditprepare: function() { var id = this.id; var pathname = document.location.pathname; if (pathname.slice(-1) != "/") { pathname += "/"; } var callback = location.protocol + "//" + location.hostname + (location.port?":"+location.port:"")+ pathname + "foursquare-credentials"; $("#node-config-foursquare-tooltip").html("<p>Please configure the authorized <b>Redirect URIs</b> of your app to include the following url:</p>\n<code>"+callback+"</code>"); function updateFoursquareAuthButton() { var v1 = $("#node-config-input-client_id").val(); var v2 = $("#node-config-input-client_secret").val(); $("#node-config-start-auth").toggleClass("disabled",(v1.length === 0 || v2.length === 0)); } $("#node-config-input-client_id").on('change keydown paste input',updateFoursquareAuthButton); $("#node-config-input-client_secret").on('change keydown paste input',updateFoursquareAuthButton); function updateFoursquareScreenName(sn) { $("#node-config-foursquare-app-keys").hide(); $("#node-config-foursquare-user").show(); $("#node-config-input-displayname").val(sn); $("#node-config-foursquare-displayname").html(sn); } function pollFoursquareCredentials(e) { $.getJSON('credentials/foursquare-credentials/'+id,function(data) { if (data.displayname) { $("#node-config-dialog-ok").button("enable"); updateFoursquareScreenName(data.displayname); delete window.foursquareConfigNodeIntervalId; } else { window.foursquareConfigNodeIntervalId = window.setTimeout(pollFoursquareCredentials,2000); } }); } updateFoursquareAuthButton(); if (this.displayname) { updateFoursquareScreenName(this.displayname); } else { $("#node-config-foursquare-app-keys").show(); $("#node-config-foursquare-user").hide(); $("#node-config-dialog-ok").button("disable"); } $("#node-config-start-auth").mousedown(function(e) { var client_id = $("#node-config-input-client_id").val(); var client_secret = $("#node-config-input-client_secret").val(); var pathname = document.location.pathname; if (pathname.slice(-1) != "/") { pathname += "/"; } var callback = encodeURIComponent(location.protocol+"//"+location.hostname+ (location.port?":"+location.port:"")+ pathname+"foursquare-credentials/auth/callback"); var url = 'foursquare-credentials/auth?id='+id+'&callback='+callback+'&clientid='+client_id+"&clientsecret="+client_secret; $(this).attr("href",url); window.foursquareConfigNodeIntervalId = window.setTimeout(pollFoursquareCredentials,2000); }); $("#node-config-start-auth").click(function(e) { var key = $("#node-config-input-client_id").val(); var secret = $("#node-config-input-client_secret").val(); if (key === "" || secret === "") { e.preventDefault(); } }); }, oneditsave: function() { if (window.foursquareConfigNodeIntervalId) { window.clearTimeout(window.foursquareConfigNodeIntervalId); delete window.foursquareConfigNodeIntervalId; } }, oneditcancel: function(adding) { if (window.foursquareConfigNodeIntervalId) { window.clearTimeout(window.foursquareConfigNodeIntervalId); delete window.foursquareConfigNodeIntervalId; } } }); })(); </script> <!-- foursquare query node --> <script type="text/x-red" data-template-name="foursquare"> <div class="form-row"> <label for="node-input-foursquare"><i class="fa fa-user"></i> Log in as</label> <input type="text" id="node-input-foursquare"> </div> <div class="form-row"> <label for="node-input-section">&nbsp;<i class="fa fa-filter"></i> Explore</label> recommended <select id="node-input-section" style="width:30% !important"> <option value="empty"></option> <option value="food">food venues</option> <option value="drinks">drink venues</option> <option value="coffee">coffee shops</option> <option value="shops">shops</option> <option value="arts">cultural venues</option> <option value="outdoors">outdoor venues</option> <option value="sights">sights</option> <option value="all">venues</option> </select>&nbsp;nearby </div> <div class="form-row"> <label>&nbsp;</label>which are open <select id="node-input-openday" style='width:50% !important'> <option value="today">today</option> <option value="any">on any day of the week</option></select> </div> <div class="form-row"> <label>&nbsp;</label>at <select id="node-input-opentime" style='width:50% !important'> <option value="currenttime">the current time of day</option> <option value="any">any time of day</option> </select> </div> <div class="form-row"> <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="10">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</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> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name"> </div> </script> <script type="text/x-red" data-help-name="foursquare"> <p>Foursquare query node.</p> <p>Can be used to <ul> <li>explore recommended venues of a particular type near a given latitude and longitude </li> </ul></p> <p>The type of venue to explore can be passed in as settings on the node or as the <b>msg.payload.section</b> of the message input. Valid entries are: <ul> <li>food</li> <li>drinks</li> <li>coffee</li> <li>shops</li> <li>arts</li> <li>outdoors</li> <li>sights</li> <li>all</li> </ul> The value set on the node will take precedence over the contents of <b>msg.payload.section</b>. </p> <p>The number of results to return from the query and how to return them (either as a single message or as multiple messages) are settings on the node.</p> <p>The node sets the following properties <ul> <li><b>payload</b> - the JSON of the recommended venue</li> <li><b>title</b> - the name of the recommended venue</li> <li><b>location.lat</b> - the latitude of the recommended venue</li> <li><b>location.lon</b> - the longitude of the recommended venue</li> <li><b>location.city</b> - the city where the recommended venue is</li> <li><b>location.country</b> - the country where the recommended venue is</li> <li><b>location.name</b> - the name of the recommended venue</li> </ul> The exact location of these properties depends on the number of results chosen to be returned along with how to return them: <ul> <li>If the node output value is set to one then for both returning as a single message and as multiple messages, the node returns a msg for the first in an ordered list of recommended venues near the provided latitude and longitude. The returned msg has the payload, location and name properties. </li> <li>If the node output value is set to more than one to be returned as a single message the node sets <b>msg.payload</b> to be an array of <b>msg</b>'s, each one corresponding to a recommended venue and ordered according to the <a href="https://foursquare.com/">Foursquare</a> venues explore API. The first element in the array is the most highly recommended venue and the length of the array is the output value set on the node or the number of venues found, whichever is smaller. Each element in this array has the payload, title, location and name properties. </li> <li>If the node output value is set to more than one but to be returned as a multiple then the node sends multiple msgs, each one representing a recommended venue. </ul> For further information about the Foursquare API see <a href="https://developer.foursquare.com/docs/venues/explore">Explore Recommended and Popular Venues</a>.</p> <p>Data provided by <a href="https://foursquare.com/">Foursquare</a>.</p> </script> <script type="text/javascript"> (function() { RED.nodes.registerType('foursquare',{ category: 'social', color:"#C0DEED", defaults: { foursquare: {type:"foursquare-credentials",required:true}, section: {value:""}, outputnumber:{value:"1"}, outputas:{value:"single"}, openday:{value:"today"}, opentime:{value:"currenttime"}, name: {value:""} }, inputs:1, outputs:1, icon: "foursquare.png", label: function() { return this.name||'foursquare'; }, oneditprepare: function() { 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>