-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeetup.js
More file actions
139 lines (108 loc) · 3.69 KB
/
meetup.js
File metadata and controls
139 lines (108 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* Meetup Data
* ==========================
* @constutor Meetup
* @param group String - the groupname
*/
var Meetup = function(group){
this.group = group;
this.url_base = 'https://api.meetup.com';
//Private Variable? - Sortof
var key = process.env.MEETUPKEY || '15865a185323203c58305f1a7b216c';
// Privledged Function
this.getKey = function(){
return key;
}
},
request = require('request');
/*
* @method _request - sends request to meetup.com's api
* @param path String - the suffix of the url
* @param callback Function - callback function
*/
Meetup.prototype._request = function(path, callback){
req = request(this.url_base + path, function(error, response, body){
if(error){
console.log(error);
callback(error);
}else if(response.statusCode == 200){
callback(JSON.parse(body).results);
}
});
}
/* @method getGroupInfo -Get basic Group Info
* @param callback Function -Just a Callback
*/
Meetup.prototype.getGroupInfo = function(callback){
var path = '/2/groups',
that = this;
path += '?key=' + this.getKey();
path += '&group_urlname=' + this.group;
path += '&page=1';
path += '&sign=true';
this._request(path, function(res){
callback(res[0]);
})
};
/*
* @method convertToISO - converts epoch time(time in milliseconds to UTC)
* @param epoch Interger - the epoch time
*/
Meetup.prototype.convertToISO = function(epoch, offset){
// -28800000 is the utc offset to pacific standard time
// adding a hour to offset to right time
// hard coded california offset ~ needs to be calculated
var d = new Date(epoch + offset),
pad = function(n){
return n<10 ? '0'+n : n
};
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds())+'Z'
}
/*
* @method getEvents - get events for meetup
* @param number Interger - number of events to get
* @param callback Function - callback function
*/
Meetup.prototype.getEvents = function(number, callback){
var path = '/2/events',
that = this;
path += '?key=' + this.getKey();
path += '&sign=true';
path += '&group_urlname=' + this.group;
path += '&page=' + number;
this._request(path, function(events){
for(var i in events){
events[i].time_ = that.convertToISO(events[i].time, events[i].utc_offset);
events[i].event_url = '/events/' + events[i].id;
//console.log(events[i].time_);
}
callback(events);
});
}
/* @method getMembers
* @param callback Function -Just a Callback
*/
Meetup.prototype.getMembers = function(callback){
var path = '/2/members',
that = this,
members = [];
path += '?group_urlname=' + this.group;
path += '&key=' + this.getKey();
this._request(path, function(res){
for(var i in res){
var member = res[i];
members.push({
name : member.name,
photo : (typeof member.photo === 'undefined') ? null : member.photo["thumb_link"],
activity: member.visited,
twitter : (typeof member.other_services.twitter === 'undefined') ? false : 'http://twitter.com/' + member.other_services.twitter.identifier.replace('@', '')
});
}
callback(members);
})
}
exports.Meetup = Meetup;