Skip to content

Commit 2b43b46

Browse files
committed
Update to work with latest API changes
1 parent b3a41ee commit 2b43b46

2 files changed

Lines changed: 12 additions & 28 deletions

File tree

lib/index.js

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var request = require('request');
44

5-
var API_URL = 'https://api.filepreviews.io/v1/?url=',
5+
var API_URL = 'https://api.filepreviews.io/v1/',
66
FilePreviews;
77

88
FilePreviews = function(options) {
@@ -32,13 +32,13 @@ FilePreviews.prototype.submitJobToAPI = function(url, options, callback) {
3232
}
3333
}
3434

35-
var error = 'API request error: ',
36-
requestUrl = this.getAPIRequestURL(url, options);
35+
var error = 'API request error: ';
3736

38-
this._log('API request to: ' + requestUrl);
37+
this._log('API request to: ' + API_URL);
3938

4039
var requestOptions = {
41-
url: requestUrl
40+
url: API_URL,
41+
json: this.getAPIRequestData(url, options)
4242
};
4343

4444
if (this.apiKey) {
@@ -47,12 +47,12 @@ FilePreviews.prototype.submitJobToAPI = function(url, options, callback) {
4747
};
4848
}
4949

50-
request.get(requestOptions, function(err, result) {
50+
request.post(requestOptions, function(err, result) {
5151
if (err) console.error(err);
5252

5353
if (result.statusCode === 200 || result.statusCode === 403) {
5454
this._log('Got response ' + result.statusCode);
55-
var data = JSON.parse(result.body);
55+
var data = result.body;
5656
this._pollForMetadata(data.metadata_url, options, function(err, metadata) {
5757
if (err) {
5858
callback(err);
@@ -118,24 +118,16 @@ FilePreviews.prototype._log = function(msg) {
118118
return this;
119119
};
120120

121-
FilePreviews.prototype.getAPIRequestURL = function(url, options) {
121+
FilePreviews.prototype.getAPIRequestData = function(url, options) {
122122
if (arguments.length === 1) {
123123
if (Object.prototype.toString.call(options) === '[object Function]') {
124124
options = false;
125125
}
126126
}
127127

128-
var extraParams = '';
129-
130128
if (options) {
131129

132-
if (options.metadata) {
133-
extraParams = '&metadata=' + options.metadata.join(',');
134-
}
135-
136-
if (options.format) {
137-
extraParams = '&format=' + options.format;
138-
}
130+
options.url = url;
139131

140132
if (options.size) {
141133
var size = '';
@@ -148,19 +140,11 @@ FilePreviews.prototype.getAPIRequestURL = function(url, options) {
148140
size = size + 'x' + options.size.height;
149141
}
150142

151-
extraParams = extraParams + '&size=' + size;
143+
options.sizes = [size];
152144
}
153145
}
154146

155-
return API_URL + url + extraParams;
156-
};
157-
158-
FilePreviews.prototype.getFilename = function(url) {
159-
return url.split('/').pop();
160-
};
161-
162-
FilePreviews.prototype.getPreviewFilename = function(filename) {
163-
return filename.substr(0, filename.lastIndexOf('.')) || filename;
147+
return options;
164148
};
165149

166150
module.exports = FilePreviews;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "filepreviews",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "Client library for FilePreviews.io - Generate image previews and metadata from almost any kind of file",
55
"main": "./lib/index.js",
66
"repository": {

0 commit comments

Comments
 (0)