@@ -5,30 +5,36 @@ var https = require('https');
5
5
var fs = require ( 'fs' ) ;
6
6
7
7
var collections = {
8
- 'guide' : 'http ://docs.google.com/feeds/default/private/full/folder%3A0B9PsajIPqzmANGUwMGVhZmYtMTk1ZC00NTdmLWIxMDAtZGI5YWNlZjQ2YjZl/contents' ,
9
- 'api' : 'http ://docs.google.com/feeds/default/private/full/folder%3A0B7Ovm8bUYiUDYjMwYTc2YWUtZTgzYy00YjIxLThlZDYtYWJlOTFlNzE2NzEw/contents' ,
10
- 'tutorial' : 'http ://docs.google.com/feeds/default/private/full/folder%3A0B9PsajIPqzmAYWMxYWE3MzYtYzdjYS00OGQxLWJhZjItYzZkMzJiZTRhZjFl/contents' ,
11
- 'cookbook' : 'http ://docs.google.com/feeds/default/private/full/folder%3A0B7Ovm8bUYiUDNzkxZWM5ZTItN2M5NC00NWIxLTg2ZDMtMmYwNDY1NWM1MGU4/contents' ,
12
- 'misc' : 'http ://docs.google.com/feeds/default/private/full/folder%3A0B7Ovm8bUYiUDZjVlNmZkYzQtMjZlOC00NmZhLWI5MjAtMGRjZjlkOGJkMDBi/contents'
8
+ 'guide' : 'https ://docs.google.com/feeds/default/private/full/folder%3A0B9PsajIPqzmANGUwMGVhZmYtMTk1ZC00NTdmLWIxMDAtZGI5YWNlZjQ2YjZl/contents' ,
9
+ 'api' : 'https ://docs.google.com/feeds/default/private/full/folder%3A0B7Ovm8bUYiUDYjMwYTc2YWUtZTgzYy00YjIxLThlZDYtYWJlOTFlNzE2NzEw/contents' ,
10
+ 'tutorial' : 'https ://docs.google.com/feeds/default/private/full/folder%3A0B9PsajIPqzmAYWMxYWE3MzYtYzdjYS00OGQxLWJhZjItYzZkMzJiZTRhZjFl/contents' ,
11
+ 'cookbook' : 'https ://docs.google.com/feeds/default/private/full/folder%3A0B7Ovm8bUYiUDNzkxZWM5ZTItN2M5NC00NWIxLTg2ZDMtMmYwNDY1NWM1MGU4/contents' ,
12
+ 'misc' : 'https ://docs.google.com/feeds/default/private/full/folder%3A0B7Ovm8bUYiUDZjVlNmZkYzQtMjZlOC00NmZhLWI5MjAtMGRjZjlkOGJkMDBi/contents'
13
13
} ;
14
14
15
15
console . log ( 'Google Docs...' ) ;
16
16
17
17
var flag = process && process . argv [ 2 ] ;
18
- if ( flag == '--login' )
19
- askPassword ( function ( password ) {
20
- login ( process . argv [ 3 ] , password ) ;
21
- } ) ;
22
- else if ( flag == '--fetch' ) {
18
+ if ( flag == '--login' ) {
19
+ var username = process . argv [ 3 ] ;
20
+ if ( username ) {
21
+ askPassword ( function ( password ) {
22
+ login ( username , password ) ;
23
+ } ) ;
24
+ } else {
25
+ console . log ( 'Missing username!' ) ;
26
+ }
27
+ } else if ( flag == '--fetch' ) {
23
28
var collection = process . argv [ 3 ] ;
24
29
if ( collection ) {
25
30
fetch ( collection , collections [ collection ] ) ;
26
31
} else {
27
32
for ( collection in collections )
28
33
fetch ( collection , collections [ collection ] ) ;
29
34
}
30
- } else
35
+ } else {
31
36
help ( ) ;
37
+ }
32
38
33
39
function help ( ) {
34
40
console . log ( 'Synopsys' ) ;
@@ -147,34 +153,36 @@ function getAuthToken(){
147
153
148
154
function request ( method , url , options , response ) {
149
155
var url = url . match ( / h t t p ( s ? ) : \/ \/ ( .+ ?) ( \/ .* ) / ) ;
150
- var request = ( url [ 1 ] ? https : http ) . request ( {
156
+ var isHttps = url [ 1 ] ;
157
+ var request = ( isHttps ? https : http ) . request ( {
151
158
host : url [ 2 ] ,
152
159
port : ( url [ 1 ] ? 443 : 80 ) ,
153
160
path : url [ 3 ] ,
154
161
method : method
155
162
} , function ( res ) {
156
163
switch ( res . statusCode ) {
157
- case 200 : {
164
+ case 200 :
158
165
var data = [ ] ;
159
166
res . setEncoding ( 'utf8' ) ;
160
- res . on ( 'end' , function ( ) {
161
- response ( data . join ( '' ) ) ;
162
- } ) ;
163
- res . on ( 'data' , function ( chunk ) {
164
- data . push ( chunk ) ;
165
- } ) ;
166
- res . on ( 'error' , function ( e ) {
167
- console . log ( e ) ;
168
- } ) ;
167
+ res . on ( 'end' , function ( ) { response ( data . join ( '' ) ) ; } ) ;
168
+ res . on ( 'close' , function ( ) { response ( data . join ( '' ) ) ; } ) ; // https
169
+ res . on ( 'data' , function ( chunk ) { data . push ( chunk ) ; } ) ;
170
+ res . on ( 'error' , function ( e ) { console . log ( e ) ; } ) ;
169
171
break ;
170
- }
171
- case 401 : {
172
+ case 401 :
172
173
console . log ( 'Eror: Login credentials expired! Please login.' ) ;
173
174
break ;
174
- }
175
- default : {
176
- console . log ( res ) ;
177
- }
175
+ default :
176
+ var data = [ ] ;
177
+ console . log ( 'ERROR: ' , res . statusCode ) ;
178
+ console . log ( 'REQUEST URL: ' , url [ 0 ] ) ;
179
+ console . log ( 'REQUEST POST: ' , options . data ) ;
180
+ console . log ( 'REQUEST HEADERS: ' , options . headers ) ;
181
+ console . log ( 'RESPONSE HEADERS: ' , res . headers ) ;
182
+ res . on ( 'end' , function ( ) { console . log ( 'BODY: ' , data . join ( '' ) ) ; } ) ;
183
+ res . on ( 'close' , function ( ) { console . log ( 'BODY: ' , data . join ( '' ) ) ; } ) ; // https
184
+ res . on ( 'data' , function ( chunk ) { data . push ( chunk ) ; } ) ;
185
+ res . on ( 'error' , function ( e ) { console . log ( e ) ; } ) ;
178
186
}
179
187
} ) ;
180
188
for ( var header in options . headers ) {
0 commit comments