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 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 } ;
Original file line number Diff line number Diff line change 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 }
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments