forked from steve21124/hoodie-plugin-social
-
Notifications
You must be signed in to change notification settings - Fork 0
/
social_api.js
190 lines (163 loc) · 6.42 KB
/
social_api.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* Copyright 2013-2014 Xiatron LLC
*/
//var twitterAPI = require('simple-twitter');
var twitterAPI = require('ntwitter');
module.exports = function() {
/*
* Twitter social methods
*/
this.twitter = function(creds) {
//establish a new twitter client
var twitterClient = new twitterAPI({
consumer_key: creds.consumerKey, //consumer key
consumer_secret: creds.consumerSecret, //consumer secret
access_token_key: creds.accessToken, //access token
access_token_secret: creds.accessSecret //access token secret
});
//tweet
this.setStatus = function(status, callback) {
//post the tweet then fire the callback
twitterClient.updateStatus(status, callback);
}
//get profile
this.getProfile = function(options, callback) {
var params = {};
if (options && options.user_id) {
params['user_id'] = options.user_id;
} else if (options && options.user_name) {
params['screen_name'] = options.user_name;
} else {
params['user_id'] = creds.id;
}
//make the call
twitterClient.get('/users/show.json', params, callback);
}
//get contacts
this.getContacts = function(options, callback) {
var params = {};
if (options && options.user_id) {
params['user_id'] = options.user_id;
} else if (options && options.user_name) {
params['screen_name'] = options.user_name;
} else {
params['user_id'] = creds.id;
}
//make the call
twitterClient.get('/friends/list.json', params, callback);
}
//get followers
this.getFollowers = function(options, callback) {
var params = {};
if (options && options.user_id) {
params['user_id'] = options.user_id;
} else if (options && options.user_name) {
params['screen_name'] = options.user_name;
} else {
params['user_id'] = creds.id;
}
//make the call
twitterClient.get('/followers/list.json', params, callback);
}
}
/*
* Facebook social methods
*/
this.facebook = function(creds) {
//establish a new facebook client
var facebookClient = require('fbgraph');
facebookClient.setAccessToken(creds.accessToken);
//post
this.setStatus = function(status, callback) {
//post to the wall then fire the callback
facebookClient.post('me/feed', { message: status }, callback);
}
//get profile
this.getProfile = function(options, callback) {
var param;
if (options && options.user_id) {
param = options.user_id;
} else if (options && options.user_name) {
param = options.user_name;
} else {
param = 'me';
}
//make the call
facebookClient.get(param, callback);
}
//get contacts
this.getContacts = function(options, callback) {
var param; //facebook only supports 'me' but we'll build the params anyway in case that changes
if (options && options.user_id) {
param = options.user_id+'/friends';
} else if (options && options.user_name) {
param = options.user_name+'/friends';
} else {
param = 'me/friends';
}
//make the call
facebookClient.get(param, callback);
}
//get followers
this.getFollowers = function(options, callback) {
var param; //facebook only supports 'me' but we'll build the params anyway in case that changes
if (options && options.user_id) {
param = options.user_id+'/subscribers';
} else if (options && options.user_name) {
param = options.user_name+'/subscribers';
} else {
param = 'me/subscribers';
}
//make the call
facebookClient.get(param, callback);
}
}
/*
* Google+ social methods - stubbed out for future use
*/
this.google = function(creds) {
//establish a new facebook client
var googleClient = require('googleapis');
//post
this.setStatus = function(payload, callback) {
var params = { userId: 'me', collection: 'vault', access_token: creds.accessToken };
googleClient.discover('plus', 'v1').execute(function(err, client) {
client.plus.moments.insert(params, payload).execute(callback);
});
}
//get profile
this.getProfile = function(options, callback) {
var params = { access_token: creds.accessToken };
if (options && options.user_id) {
params['userId'] = options.user_id;
} else if (options && options.user_name) {
params['userId'] = options.user_name;
} else {
params['userId'] = 'me';
}
//make the call
googleClient.discover('plus', 'v1').execute(function(err, client) {
client.plus.people.get(params).execute(callback);
});
}
//get contacts
this.getContacts = function(options, callback) {
var params = { access_token: creds.accessToken, collection: 'visible' };
if (options && options.user_id) {
params['userId'] = options.user_id;
} else if (options && options.user_name) {
params['userId'] = options.user_name;
} else {
params['userId'] = 'me';
}
//make the call
googleClient.discover('plus', 'v1').execute(function(err, client) {
client.plus.people.list(params).execute(callback);
});
}
//get followers
this.getFollowers = function(options, callback) {
callback(null, 'This is not supported by the Google Plus API');
}
}
}