/
url-get.js
97 lines (71 loc) · 2.02 KB
/
url-get.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
'use strict';
var _ = require('lodash');
var googleapis = require('googleapis');
var urlshortener = googleapis.urlshortener('v1');
module.exports = {
friendlyName: 'URL get',
description: 'Expand a short URL',
extendedDescription: 'You can call this method to expand any goo.gl short URL. For example, to expand http://goo.gl/fbsS to narmal URL',
cacheable: true,
sync: false,
idempotent: false,
inputs: {
shortUrl: {
example: 'http://goo.gl/xKbRu3',
description: 'Short URL',
required: true
},
projection: {
example: 'ANALYTICS_TOP_STRINGS', // ANALYTICS_CLICKS | ANALYTICS_TOP_STRINGS | FULL
description: 'Additional information to return.'
},
fields: {
example: 'analytics,created,id,kind,longUrl,status',
description: 'Selector specifying which fields to include in a partial response'
},
key: {
example: 'AIzaSyAYVDlaoVs_GZw9JNvSclRWH_PEMKII6tc',
description: 'Your api key',
whereToGet: {
url: 'https://developers.google.com/url-shortener/v1/getting_started#APIKey'
}
}
},
exits: {
invalidParameter: {
description: 'Invalid field parameter passed'
},
dailyLimitExceededUnreg: {
description: 'Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.'
},
success: {
variableName: 'result',
description: 'Done.'
}
},
fn: function(inputs, exits) {
var params = {};
// Mergind given objects
_.merge(params, inputs);
// Make API call
urlshortener.url.get(params, function(err, response) {
if (err) {
if (!err.code) {
return exits.error(err);
}
switch (err.code) {
case 400:
return exits.invalidParameter(err);
break;
case 403:
return exits.dailyLimitExceededUnreg(err);
break;
default:
return exits.error(err);
break;
}
}
return exits.success(response);
});
}
};