Skip to content

Commit df42271

Browse files
committed
Add eventbrite query node.
1 parent 5b6fe0f commit df42271

File tree

3 files changed

+179
-1
lines changed

3 files changed

+179
-1
lines changed

eventbrite/eventbrite.html

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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="eventbrite config">
18+
<div class="form-row">
19+
<label for="node-config-input-appKey"><i class="fa fa-bookmark"></i>App Key</label>
20+
<input class="input-append-left" type="text" id="node-config-input-appKey" style="width: 40%;" >
21+
</div>
22+
<div class="form-row">
23+
<label for="node-config-input-apiUserKey"><i class="fa fa-bookmark"></i>API User Key</label>
24+
<input class="input-append-left" type="password" id="node-config-input-apiUserKey" style="width: 40%;" >
25+
</div>
26+
<div class="form-tips">
27+
To obtain these credentials, visit the <a href="https://www.eventbrite.com/myaccount/apps/">Eventbrite My Applications</a>, login or sign up, then click "Create a new app". After entering the necessary details copy the App Key from the application list and click "API User Key" to obtain that key.
28+
</div>
29+
</script>
30+
31+
<script type="text/javascript">
32+
(function() {
33+
RED.nodes.registerType('eventbrite config',{
34+
category: 'config',
35+
defaults: { },
36+
credentials: {
37+
appKey: {type:"text",required:true},
38+
apiUserKey: {type: "password",required:true},
39+
},
40+
label: function() {
41+
return 'Eventbrite' + (this.appKey ? ' '+this.appKey : '');
42+
},
43+
exportable: false,
44+
});
45+
})();
46+
</script>
47+
48+
<script type="text/x-red" data-template-name="eventbrite">
49+
<div class="form-row">
50+
<label for="node-input-eventbrite"><i class="fa fa-user"></i> Eventbrite</label>
51+
<input type="text" id="node-input-eventbrite">
52+
</div>
53+
<div class="form-row">
54+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
55+
<input type="text" id="node-input-name" placeholder="Name">
56+
</div>
57+
</script>
58+
59+
<script type="text/x-red" data-help-name="eventbrite">
60+
<p>Eventbrite query node. Generates a message containing the events for the user associated with the API User Key.</p>
61+
</script>
62+
63+
<script type="text/javascript">
64+
RED.nodes.registerType('eventbrite',{
65+
category: 'social',
66+
color:"#C0DEED",
67+
defaults: {
68+
eventbrite: {type:"eventbrite config",required:true},
69+
name: {value:"Eventbrite"}
70+
},
71+
inputs:1,
72+
outputs:1,
73+
icon: "eventbrite.png",
74+
align: "right",
75+
label: function() {
76+
return this.name||'Eventbrite';
77+
}
78+
});
79+
</script>

eventbrite/eventbrite.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
var querystring = require('querystring');
21+
22+
function EventbriteNode(n) {
23+
RED.nodes.createNode(this, n);
24+
}
25+
RED.nodes.registerType("eventbrite config",EventbriteNode,{
26+
credentials: {
27+
appKey: { type:"text" },
28+
apiUserKey: { type: "password" },
29+
}
30+
});
31+
function eventbriteRequest(method, options, callback) {
32+
var url = "https://www.eventbrite.com/json/" + method +
33+
'?' + querystring.stringify(options);
34+
request.get({url:url, json:true}, callback);
35+
}
36+
37+
/**
38+
* Flattens JSON generated from XML that contains:
39+
*
40+
* { "orders": [ { "order" : { k1: v1, k2: k2, ... } }, ... ] }
41+
*
42+
* to:
43+
*
44+
* { "orders": [ { k1: v1, k2: k2, ... }, ... ] }
45+
*/
46+
function flattenTrivialHashes(data) {
47+
if (data === null) {
48+
return data;
49+
} else if (Array.isArray(data)) {
50+
return data.map(flattenTrivialHashes);
51+
} else if (typeof data === 'object') {
52+
var k = Object.keys(data);
53+
if (k.length == 1) {
54+
return flattenTrivialHashes(data[k[0]]);
55+
} else {
56+
var res = {};
57+
for (var key in data) {
58+
if (data.hasOwnProperty(key)) {
59+
res[key] = flattenTrivialHashes(data[key]);
60+
}
61+
}
62+
return res;
63+
}
64+
} else {
65+
return data;
66+
}
67+
}
68+
function EventbriteQueryNode(n) {
69+
RED.nodes.createNode(this,n);
70+
var credentials = RED.nodes.getCredentials(n.eventbrite);
71+
var node = this;
72+
if (credentials && credentials.appKey && credentials.apiUserKey) {
73+
this.on("input",function(msg) {
74+
node.status({fill:"blue",shape:"dot",text:"querying"});
75+
eventbriteRequest('user_list_tickets', {'app_key': credentials.appKey, 'user_key': credentials.apiUserKey}, function(err, res, data) {
76+
if (err) {
77+
node.error("Error: " + err);
78+
node.status({fill:"red",shape:"ring",text:"failed"});
79+
return;
80+
}
81+
if (data.error) {
82+
node.status({fill:"red",shape:"ring",text:data.error.error_message});
83+
} else {
84+
node.status({});
85+
}
86+
/* See:
87+
* http://developer.eventbrite.com/doc/users/user_list_tickets/
88+
* for response details.
89+
*/
90+
var orders = flattenTrivialHashes(data.user_tickets[1].orders);
91+
msg.payload = orders;
92+
node.send(msg);
93+
});
94+
});
95+
}
96+
}
97+
RED.nodes.registerType("eventbrite",EventbriteQueryNode);
98+
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"nodes" : {
1818
"pinboard": "pinboard/pinboard.js",
1919
"flickr": "flickr/flickr.js",
20-
"dropbox": "dropbox/dropbox.js"
20+
"dropbox": "dropbox/dropbox.js",
21+
"eventbrite": "eventbrite/eventbrite.js"
2122
}
2223
}
2324
}

0 commit comments

Comments
 (0)