Skip to content

Commit a8b27a3

Browse files
committed
Merge pull request #22 from hbeeken/foursquare-input
Foursquare input and query nodes
2 parents 92cb05e + 1e131b7 commit a8b27a3

File tree

4 files changed

+495
-1
lines changed

4 files changed

+495
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"delicious": "delicious/delicious.js",
2222
"pinboard": "pinboard/pinboard.js",
2323
"flickr": "flickr/flickr.js",
24-
"dropbox": "dropbox/dropbox.js"
24+
"dropbox": "dropbox/dropbox.js",
25+
"swarm":"swarm/swarm.js"
2526
}
2627
},
2728
"devDependencies": {

swarm/icons/swarm.png

463 Bytes
Loading

swarm/swarm.html

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
<!--
2+
Copyright 2014 IBM Corp.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<script type="text/x-red" data-template-name="swarm-credentials">
18+
<div id="node-config-swarm-app-keys">
19+
<div class="form-row">
20+
<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>
21+
</div>
22+
<div class="form-tips" id="node-config-swarm-tooltip">
23+
</div>
24+
<div class="form-row">
25+
<p style="margin-top: 10px;"><b>2.</b> Copy the app details here:</p>
26+
</div>
27+
<div class="form-row">
28+
<label style="margin-left: 10px; margin-right: -10px;" for="node-config-input-client_id"><i class="fa fa-user"></i> Client ID</label>
29+
<input type="password" id="node-config-input-client_id">
30+
</div>
31+
<div class="form-row">
32+
<label style="margin-left: 10px; margin-right: -10px;" for="node-config-input-client_secret"><i class="fa fa-key"></i> Client Secret</label>
33+
<input type="password" id="node-config-input-client_secret">
34+
</div>
35+
<div class="form-row">
36+
<label>&nbsp;</label>
37+
<a class="btn" id="node-config-start-auth" href="#" target="_blank">Authenticate with Swarm</a>
38+
</div>
39+
</div>
40+
<div id="node-config-swarm-user">
41+
<div class="form-row">
42+
<label><i class="fa fa-user"></i> Swarm User</label><span id="node-config-swarm-displayname" class="input-xlarge uneditable-input"></span>
43+
</div>
44+
<input type="hidden" id="node-config-input-displayname">
45+
</div>
46+
47+
</script>
48+
49+
<script type="text/javascript">
50+
(function() {
51+
RED.nodes.registerType('swarm-credentials',{
52+
category: 'config',
53+
defaults: {
54+
displayname: {value:""}
55+
},
56+
credentials: {
57+
displayname: {type:"text", required: true},
58+
clientid: {type:"password",required:true},
59+
clientsecret: {type: "password",required:true},
60+
accesstoken: {type: "password", required:true}
61+
},
62+
label: function() {
63+
return this.displayname;
64+
},
65+
exportable: false,
66+
oneditprepare: function() {
67+
var id = this.id;
68+
69+
var pathname = document.location.pathname;
70+
if (pathname.slice(-1) != "/") {
71+
pathname += "/";
72+
}
73+
var callback = location.protocol + "//" +
74+
location.hostname + ":" + location.port +
75+
pathname + "swarm-credentials";
76+
$("#node-config-swarm-tooltip").html("<p>Please configure the authorized <b>Redirect URIs</b> of your app to include the following url:</p>\n<code>"+callback+"</code>");
77+
78+
function updateSwarmAuthButton() {
79+
var v1 = $("#node-config-input-client_id").val();
80+
var v2 = $("#node-config-input-client_secret").val();
81+
82+
$("#node-config-start-auth").toggleClass("disabled",(v1.length === 0 || v2.length === 0));
83+
84+
}
85+
$("#node-config-input-client_id").on('change keydown paste input',updateSwarmAuthButton);
86+
$("#node-config-input-client_secret").on('change keydown paste input',updateSwarmAuthButton);
87+
88+
function updateSwarmScreenName(sn) {
89+
$("#node-config-swarm-app-keys").hide();
90+
$("#node-config-swarm-user").show();
91+
$("#node-config-input-displayname").val(sn);
92+
$("#node-config-swarm-displayname").html(sn);
93+
}
94+
95+
function pollSwarmCredentials(e) {
96+
$.getJSON('credentials/swarm-credentials/'+id,function(data) {
97+
if (data.displayname) {
98+
$("#node-config-dialog-ok").button("enable");
99+
updateSwarmScreenName(data.displayname);
100+
delete window.swarmConfigNodeIntervalId;
101+
} else {
102+
window.swarmConfigNodeIntervalId = window.setTimeout(pollswarmCredentials,2000);
103+
}
104+
});
105+
}
106+
107+
updateSwarmAuthButton();
108+
109+
if (this.displayname) {
110+
updateSwarmScreenName(this.displayname);
111+
} else {
112+
$("#node-config-swarm-app-keys").show();
113+
$("#node-config-swarm-user").hide();
114+
$("#node-config-dialog-ok").button("disable");
115+
}
116+
117+
$("#node-config-start-auth").mousedown(function(e) {
118+
var client_id = $("#node-config-input-client_id").val();
119+
var client_secret = $("#node-config-input-client_secret").val();
120+
var pathname = document.location.pathname;
121+
if (pathname.slice(-1) != "/") {
122+
pathname += "/";
123+
}
124+
var callback = encodeURIComponent(location.protocol+"//"+location.hostname+":"+location.port+pathname+"swarm-credentials/auth/callback");
125+
var url = 'swarm-credentials/auth?id='+id+'&callback='+callback+'&clientid='+client_id+"&clientsecret="+client_secret;
126+
$(this).attr("href",url);
127+
window.swarmConfigNodeIntervalId = window.setTimeout(pollSwarmCredentials,2000);
128+
});
129+
$("#node-config-start-auth").click(function(e) {
130+
var key = $("#node-config-input-client_id").val();
131+
var secret = $("#node-config-input-client_secret").val();
132+
if (key === "" || secret === "") {
133+
e.preventDefault();
134+
}
135+
});
136+
137+
},
138+
139+
oneditsave: function() {
140+
if (window.swarmConfigNodeIntervalId) {
141+
window.clearTimeout(window.swarmConfigNodeIntervalId);
142+
delete window.swarmConfigNodeIntervalId;
143+
}
144+
},
145+
oneditcancel: function(adding) {
146+
if (window.swarmConfigNodeIntervalId) {
147+
window.clearTimeout(window.swarmConfigNodeIntervalId);
148+
delete window.swarmConfigNodeIntervalId;
149+
}
150+
}
151+
152+
});
153+
})();
154+
</script>
155+
156+
<!-- Swarm input node -->
157+
<script type="text/x-red" data-template-name="swarm in">
158+
<div class="form-row">
159+
<label for="node-input-swarm"><i class="fa fa-user"></i> Log in as</label>
160+
<input type="text" id="node-input-swarm">
161+
</div>
162+
<div class="form-row">
163+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
164+
<input type="text" id="node-input-name">
165+
</div>
166+
</script>
167+
168+
<script type="text/x-red" data-help-name="swarm in">
169+
<p>Swarm input node.</p>
170+
<p>Polls every 15 minutes for the latest Swarm check-ins that have been registered by the authenticated
171+
user since the node was registered. If a new check-in has been made within the polling interval
172+
then <b>msg.payload</b> is set to be the JSON of the most recent new check-in.
173+
The properties of the <a href="https://foursquare.com/">Swarm</a> check-in are documented at
174+
<a href="https://developer.foursquare.com/docs/responses/checkin">Checkin Response</a>.</p>
175+
<p>Data provided by <a href="https://foursquare.com/">Foursquare</a>.</p>
176+
</script>
177+
178+
<script type="text/javascript">
179+
(function() {
180+
RED.nodes.registerType('swarm in',{
181+
category: 'social',
182+
color:"#C0DEED",
183+
defaults: {
184+
swarm: {type:"swarm-credentials",required:true},
185+
name: {value:""}
186+
},
187+
inputs:0,
188+
outputs:1,
189+
icon: "swarm.png",
190+
label: function() {
191+
return this.name||'swarm';
192+
}
193+
});
194+
})();
195+
</script>
196+
197+
<!-- swarm query node -->
198+
<script type="text/x-red" data-template-name="swarm">
199+
<div class="form-row">
200+
<label for="node-input-swarm"><i class="fa fa-user"></i> Log in as</label>
201+
<input type="text" id="node-input-swarm">
202+
</div>
203+
<div class="form-row">
204+
<label for="node-input-request">&nbsp;<i class="fa fa-filter"></i> Request</label>
205+
<select id="node-input-request" style="width:73% !important">
206+
<option value="get-most-recent-checkin">get most recent check in</option>
207+
</select>
208+
</div>
209+
<div class="form-row">
210+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
211+
<input type="text" id="node-input-name">
212+
</div>
213+
</script>
214+
215+
<script type="text/x-red" data-help-name="swarm">
216+
<p>Swarm query node.</p>
217+
<p>Can be used to search
218+
<ul>
219+
<li>all Swarm check-ins by the authenticated user.</li>
220+
</ul></p>
221+
<p>The node sets <b>msg.payload</b> to be the JSON of the most recent check-in
222+
since the node was registered. The properties of the
223+
<a href="https://swarm.com/">Swarm</a> check-in are documented at
224+
<a href="https://developer.foursquare.com/docs/responses/checkin">Checkin Response</a>.</p>
225+
<p>Data provided by <a href="https://foursquare.com/">Foursquare</a>.</p>
226+
</script>
227+
228+
<script type="text/javascript">
229+
(function() {
230+
RED.nodes.registerType('swarm',{
231+
category: 'social',
232+
color:"#C0DEED",
233+
defaults: {
234+
swarm: {type:"swarm-credentials",required:true},
235+
request: {value:"get-most-recent-checkin"},
236+
name: {value:""}
237+
},
238+
inputs:1,
239+
outputs:1,
240+
align: "right",
241+
icon: "swarm.png",
242+
label: function() {
243+
return this.name||'swarm';
244+
}
245+
});
246+
})();
247+
</script>
248+
249+
250+
251+

0 commit comments

Comments
 (0)