File tree Expand file tree Collapse file tree 3 files changed +27
-22
lines changed Expand file tree Collapse file tree 3 files changed +27
-22
lines changed Original file line number Diff line number Diff line change 147
147
} ;
148
148
149
149
Diff2HtmlInterface . prototype . postToDiffy = function ( diff , postType , callback ) {
150
- var jsonParams = { udiff : diff } ;
150
+ var jsonParams = { diff : diff } ;
151
151
152
- http . post ( 'http ://diffy.org/api/new ', jsonParams , function ( err , response ) {
152
+ http . put ( 'https ://diffy.org/api/diff/ ', jsonParams , function ( err , url ) {
153
153
if ( err ) {
154
154
log . error ( err ) ;
155
155
return ;
156
156
}
157
157
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 ) ;
171
167
}
172
168
} ) ;
173
169
} ;
Original file line number Diff line number Diff line change 11
11
function HttpUtils ( ) {
12
12
}
13
13
14
- HttpUtils . prototype . post = function ( url , payload , callback ) {
14
+ HttpUtils . prototype . put = function ( url , payload , callback ) {
15
15
request ( {
16
16
url : url ,
17
- method : 'POST' ,
18
- form : payload
17
+ method : 'PUT' ,
18
+ headers : { } ,
19
+ body : payload ,
20
+ json : true
19
21
} )
20
22
. on ( 'response' , function ( response ) {
21
23
response . on ( 'data' , function ( body ) {
22
24
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
+ }
24
33
} catch ( err ) {
25
34
return callback ( new Error ( 'could not parse response' ) ) ;
26
35
}
Original file line number Diff line number Diff line change @@ -42,11 +42,11 @@ describe('Cli', function() {
42
42
} ) ;
43
43
44
44
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 ' ) ;
47
47
Cli . postToDiffy ( 'a' , 'b' , 'callback' ) ;
48
48
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' } ) ) ;
50
50
} ) ;
51
51
} ) ;
52
52
} ) ;
You can’t perform that action at this time.
0 commit comments