Skip to content

Commit acc82f0

Browse files
committed
Add delicious out node
1 parent ee4627b commit acc82f0

File tree

3 files changed

+190
-0
lines changed

3 files changed

+190
-0
lines changed

delicious/delicious.html

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
18+
<script type="text/x-red" data-template-name="delicious-user">
19+
<div class="form-row">
20+
<label for="node-config-input-username"><i class="fa fa-user"></i> User</label>
21+
<input type="text" id="node-config-input-username">
22+
</div>
23+
<div class="form-row">
24+
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
25+
<input type="password" id="node-config-input-password">
26+
</div>
27+
</script>
28+
29+
<script type="text/x-red" data-template-name="delicious out">
30+
<div class="form-row">
31+
<label for="node-input-name"><i class="fa fa-user"></i> User</label>
32+
<input type="text" id="node-input-user">
33+
</div>
34+
<div class="form-row">
35+
<label for="node-input-tags"><i class="fa fa-tags"></i> Tags</label>
36+
<input type="text" id="node-input-tags" placeholder="comma-separated tags to add">
37+
</div>
38+
<div class="form-row">
39+
<label>&nbsp;</label>
40+
<input type="checkbox" id="node-input-private" style="display: inline-block; width: auto; vertical-align: top;">
41+
<label for="node-input-private" style="width: 70%;">Mark as private?</label>
42+
</div>
43+
<div class="form-row">
44+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
45+
<input type="text" id="node-input-name" placeholder="Name">
46+
</div>
47+
</script>
48+
49+
<script type="text/x-red" data-help-name="delicious out">
50+
<p>Saves bookmarks to <a target="_blank" href="http://delicious.com">Delicious</a>.</p>
51+
<p>The incoming message can provide the following properties:
52+
<ul>
53+
<li><b>payload</b> - the url to save (required)</li>
54+
<li><b>title</b> - the title for the bookmark (required)</li>
55+
<li><b>description</b> - the description for the bookmark (optional)</li>
56+
</ul>
57+
</p>
58+
</script>
59+
60+
<script type="text/javascript">
61+
RED.nodes.registerType('delicious-user',{
62+
category: 'config',
63+
defaults: {
64+
username: {value:"", required:true},
65+
},
66+
credentials: {
67+
password: { type:"password"}
68+
},
69+
label: function() {
70+
return this.username;
71+
}
72+
});
73+
74+
RED.nodes.registerType('delicious out',{
75+
category: 'social',
76+
defaults: {
77+
user: { type:"delicious-user", required: true },
78+
tags: { value:"" },
79+
private: { value: false},
80+
name: { value:"" }
81+
},
82+
color:"#C0DEED",
83+
inputs:1,
84+
outputs:0,
85+
icon: "delicious.png",
86+
align: "right",
87+
label: function() {
88+
return this.name||"Delicious";
89+
},
90+
labelStyle: function() {
91+
return this.name?"node_label_italic":"";
92+
}
93+
});
94+
95+
</script>

delicious/delicious.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
module.exports = function(RED) {
18+
"use strict";
19+
var request = require("request");
20+
21+
function DeliciousUserNode(n) {
22+
RED.nodes.createNode(this,n);
23+
this.username = n.username;
24+
}
25+
RED.nodes.registerType("delicious-user",DeliciousUserNode,{
26+
credentials: {
27+
password: { type:"password"}
28+
}
29+
});
30+
31+
32+
function DeliciousOutNode(n) {
33+
RED.nodes.createNode(this,n);
34+
var node = this;
35+
this.tags = n.tags;
36+
this.toread = n.toread;
37+
this.private = n.private;
38+
39+
this.user = RED.nodes.getNode(n.user);
40+
if (this.user) {
41+
this.on("input", function(msg) {
42+
if (!msg.payload) {
43+
node.warn("url must be provided in msg.payload");
44+
return;
45+
}
46+
if (!msg.title) {
47+
node.warn("msg.title must be provided");
48+
}
49+
var options = {
50+
url: "https://api.delicious.com/v1/posts/add?"+
51+
"url="+encodeURIComponent(msg.payload)+
52+
"&description="+encodeURIComponent(msg.title)+
53+
"&auth_token="+node.user.credentials.token+
54+
"&shared="+((node.private !== false)?"no":"yes"),
55+
auth: {
56+
user: node.user.username,
57+
password: node.user.credentials.password
58+
}
59+
}
60+
// TODO: allow tags to be added by the message
61+
if (node.tags) {
62+
options.url += "&tags="+encodeURIComponent(node.tags)
63+
}
64+
if (msg.description) {
65+
options.url += "&extended="+encodeURIComponent(msg.description)
66+
}
67+
68+
node.status({fill:"blue",shape:"dot",text:"saving"});
69+
70+
request.get(options, function(err,res,body) {
71+
if (err) {
72+
node.error(err);
73+
node.status({fill:"red",shape:"ring",text:"failed"});
74+
} else {
75+
if (body.indexOf('code="done"') != -1) {
76+
node.status({});
77+
} else {
78+
//TODO: This API only returns XML. Need to parse out error messages
79+
node.error(body);
80+
node.status({fill:"red",shape:"ring",text:"failed"});
81+
}
82+
}
83+
}).on('error',function(err) {
84+
node.error(err);
85+
node.status({fill:"red",shape:"ring",text:err.code});
86+
});
87+
88+
});
89+
} else {
90+
this.error("missing credentials");
91+
}
92+
93+
}
94+
RED.nodes.registerType("delicious out",DeliciousOutNode);
95+
}

delicious/icons/delicious.png

221 Bytes
Loading

0 commit comments

Comments
 (0)