-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (43 loc) · 1.2 KB
/
index.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
var get = require("get-json");
var debug = require("debug")('flickr-client');
var querystring = require("querystring");
var node = require("is-node");
var auth;
module.exports = setup;
function setup (options) {
if (typeof options == 'function') return options;
auth = options || {};
return client;
}
function client (query, options, callback) {
var token = '';
var sig = '';
var qs = '';
if (typeof options == 'function') {
callback = options;
options = undefined;
}
if (options) {
qs = '&' + querystring.stringify(options);
}
if (auth.token) token = '&auth_token=' + auth.token;
if (auth.sig) sig = '&auth_sig=' + auth.sig;
var url = 'https://api.flickr.com/services/rest/?method=flickr.'
+ query
+ '&api_key='
+ auth.key
+ '&format=json'
+ (node ? '&nojsoncallback=1' : '')
+ token + sig + qs;
debug('Requesting %s', url);
if (node) {
get(url, done);
} else {
get(url, { param: 'jsoncallback' }, done);
}
function done (error, response) {
if (error) return callback(error);
if (response.stat == 'fail') return callback(new Error(response.message));
return callback(undefined, response);
}
}