Skip to content

Commit 1dfd1c2

Browse files
committed
fix: Upload to diffy.org
1 parent 3d9b209 commit 1dfd1c2

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

src/cli.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,23 @@
147147
};
148148

149149
Diff2HtmlInterface.prototype.postToDiffy = function(diff, postType, callback) {
150-
var jsonParams = {udiff: diff};
150+
var jsonParams = {diff: diff};
151151

152-
http.post('http://diffy.org/api/new', jsonParams, function(err, response) {
152+
http.put('https://diffy.org/api/diff/', jsonParams, function(err, url) {
153153
if (err) {
154154
log.error(err);
155155
return;
156156
}
157157

158-
if (response.status !== 'error') {
159-
log.print('Link powered by diffy.org:');
160-
log.print(response.url);
161-
162-
if (postType === 'browser') {
163-
open(response.url);
164-
return callback(null, response.url);
165-
} else if (postType === 'pbcopy') {
166-
clipboardy.writeSync(response.url);
167-
return callback(null, response.url);
168-
}
169-
} else {
170-
log.error('Error: ' + response.statusCode);
158+
log.print('Link powered by https://diffy.org');
159+
log.print(url);
160+
161+
if (postType === 'browser') {
162+
open(url);
163+
return callback(null, url);
164+
} else if (postType === 'pbcopy') {
165+
clipboardy.writeSync(url);
166+
return callback(null, url);
171167
}
172168
});
173169
};

src/http-utils.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@
1111
function HttpUtils() {
1212
}
1313

14-
HttpUtils.prototype.post = function(url, payload, callback) {
14+
HttpUtils.prototype.put = function(url, payload, callback) {
1515
request({
1616
url: url,
17-
method: 'POST',
18-
form: payload
17+
method: 'PUT',
18+
headers: {},
19+
body: payload,
20+
json: true
1921
})
2022
.on('response', function(response) {
2123
response.on('data', function(body) {
2224
try {
23-
return callback(null, JSON.parse(body.toString('utf8')));
25+
var object = JSON.parse(body.toString('utf8'));
26+
if(object.id) {
27+
return callback(null, "https://diffy.org/diff/" + object.id);
28+
} else if (object.error) {
29+
return callback(new Error(object.error));
30+
}else {
31+
return callback(new Error(body.toString('utf8')));
32+
}
2433
} catch (err) {
2534
return callback(new Error('could not parse response'));
2635
}

test/cli-tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ describe('Cli', function() {
4242
});
4343

4444
describe('postToDiffy', function() {
45-
it('should call `http.post`', function() {
46-
var spy = sinon.stub(http, 'post');
45+
it('should call `http.put`', function() {
46+
var spy = sinon.stub(http, 'put');
4747
Cli.postToDiffy('a', 'b', 'callback');
4848
assert(spy.calledOnce);
49-
assert(spy.calledWith('http://diffy.org/api/new', { udiff: 'a' }));
49+
assert(spy.calledWith('https://diffy.org/api/diff/', { diff: 'a' }));
5050
});
5151
});
5252
});

0 commit comments

Comments
 (0)