-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathindex.js
More file actions
166 lines (165 loc) · 7.28 KB
/
index.js
File metadata and controls
166 lines (165 loc) · 7.28 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
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
var config = require('./lib/config');
var token = require('./lib/token');
var tag = require('./lib/tag');
var info = require('./lib/info');
var languages = require('./lib/languages');
var callback = require('./lib/callback');
var color = require('./lib/color');
var feedback = require('./lib/feedback');
var usage = require('./lib/usage');
module.exports = global.Clarifai = {
initialize: function(options) {
config.set('apiEndpoint', options.apiEndpoint || process.env.API_ENDPOINT || 'https://api.clarifai.com');
config.set('clientId', options.clientId || process.env.CLIENT_ID);
config.set('clientSecret', options.clientSecret || process.env.CLIENT_SECRET);
token.delete();
},
/**
* Gets a token from the API using client credentials
* @method getToken
* @param {Function} callback A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the token string or rejected with an error
*/
getToken: function(_callback) {
var promise = token.get();
callback.handle(promise, _callback);
return promise;
},
/**
* Sets the token to use for the API
* @method setToken
* @param {String} _token The token you are setting
* @return {Boolean} true if token has valid fields, false if not
*/
setToken: function(_token) {
return token.set(_token);
},
/**
* Deletes the token
* @method deleteToken
*/
deleteToken: function() {
token.delete();
},
/**
* Gets tags given a url
* @method getTagsByUrl
* @param {String} or {Array} url A publicly accessible url of the image.
* @param {Object} options Object with keys explained below: (optional)
* @param {String} model The model used to tag the image (optional)
* @param {String} language The language used to tag the image (optional)
* @param {String} or {Array} selectClasses Restrict the tags returned
* @param {String} or {Array} localId Provide a localId for each url to simplify tracking requests (optional)
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getTagsByUrl: function(url, options, _callback) {
var callbackFn = _callback;
if ( typeof options === 'function' ) {
callbackFn = options;
};
var promise = tag.getByUrl(url, options);
callback.handle(promise, callbackFn);
return promise;
},
/**
* Gets tags given image bytes
* @method getTagsByImageBytes
* @param {String} image bytes Base64 encoded image bytes.
* @param {Object} options Object with keys explained below: (optional)
* @param {String} model The model used to tag the image (optional)
* @param {String} language The language used to tag the image (optional)
* @param {String} or {Array} selectClasses Restrict the tags returned
* @param {String} or {Array} localId Provide a localId for each url to simplify tracking requests (optional)
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getTagsByImageBytes: function(imageBytes, options, _callback) {
var callbackFn = _callback;
if ( typeof options === 'function' ) {
callbackFn = options;
};
var promise = tag.getByImageBytes(imageBytes, options);
callback.handle(promise, callbackFn);
return promise;
},
/**
* Gets API info
* @method getInfo
* @param {Function} callback A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getInfo: function(_callback) {
var promise = info.get();
callback.handle(promise, _callback);
return promise;
},
/**
* Gets languages supported by the API
* @method getLanguages
* @param {Function} callback A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getLanguages: function(_callback) {
var promise = languages.get();
callback.handle(promise, _callback);
return promise;
},
/**
* Gets colors given a url
* @method getColorByUrl
* @param {String} or {Array} url A publicly accessible url of the image.
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getColorsByUrl: function(url, _callback) {
var promise = color.getByUrl(url);
callback.handle(promise, _callback);
return promise;
},
/**
* Gets colors given image bytes
* @method getColorsByImageBytes
* @param {String} url A publicly accessible url of the image.
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getColorsByImageBytes: function(imageBytes, _callback) {
var promise = color.getByImageBytes(imageBytes);
callback.handle(promise, _callback);
return promise;
},
/**
* Gets API usage
* @method getUsage
* @param {Function} callback A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getUsage: function(_callback) {
var promise = usage.get();
callback.handle(promise, _callback);
return promise;
},
/**
* Provide feedback for a url or list of urls
* @method createFeedback
* @param {String} or {Array} url A publicly accessible url of the image.
* @param {Object} options Object with keys explained below: (optional)
* @param {String} or {Array} addTags Add additional tags that are relevant to the given image(s) (optional)
* @param {String} or {Array} removeTags Remove tags that are not relevant to the given image(s) (optional)
* @param {String} or {Array} similarUrls Tell the system two or more images are similar (optional)
* @param {String} or {Array} disSimilarUrls Tell the system two or more images are dissimilar (optional)
* @param {String} or {Array} searchClick Tell the system that the search result was relevant to the query (optional)
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
createFeedback: function(url, options, _callback) {
var callbackFn = _callback;
if ( typeof options === 'function' ) {
callbackFn = options;
};
var promise = feedback.create(url, options);
callback.handle(promise, callbackFn);
return promise;
}
};