Changeset fb0ede0 in tol for tol/stdlib/general/system/CurlApi/CurlFunctions.tol
- Timestamp:
- May 24, 2011, 3:28:37 PM (15 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 2ae8ad2
- Parents:
- 3f32a91
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/general/system/CurlApi/CurlFunctions.tol
r3f32a91 rfb0ede0 17 17 }; 18 18 19 Text _.autodoc.member.GetUrl = 20 "Download an URL.\n" 21 "Arguments:\n" 22 "Args is a NameBlock containing the named arguments for this function, which are:\n" 23 " - Text url : the target url, this is a required argument\n" 24 " - Text file : the destination file, this is an optional argument, if this argument is not given then the url contents is returned in the result of the funnction.\n" 25 " - Real timeout : set the maximum time in seconds that you allow the transfer operation to take. Do note that normally, name lookups may take a considerable time and that limiting the operation to less than a few minutes risks aborting perfectly normal operations. This is an optional argument, it defaults to 0 which means no timeout.\n" 26 " - Real connectiontimeout : set the maximum time in seconds that you allow the connection to the server to take. This only limits the connection phase, once it has connected, this option is of no more use. This is an optional argument, it defaults to 0 which means no timeout.\n" 27 " - Real verbose : when True display a lot of verbose information about its operations. Very useful for protocol debugging and understanding.\n" 28 "Result:\n" 29 "The result is a Set containing information about the transfer. If the transfer is successful it returns a Set with the following fields:\n" 30 " - Real connectTime : the time, in seconds, it took from the start until the connect to the remote host (or proxy) was completed.\n" 31 " - Real fileTime: the remote time of the retrieved document (in number of seconds since 1 jan 1970 in the GMT/UTC time zone). If you get -1, it can be because of many reasons (unknown, the server hides it or the server doesn't support the command that tells document time etc) and the time of the document is unknown.\n" 32 " - Real totalTime : the total transaction time, in seconds, for the transfer, including name resolving, TCP connect etc.\n" 33 " - Real sizeDownload : the total amount of bytes that were downloaded.\n" 34 " - Real speedDownload : the average download speed, measured in bytes/second, for the complete download.\n" 35 " - Text nameData : the name of the field containing the downloaded data. It could take two values, \"file\" if the download was requested to be saved into a file or \"bodyData\" if no file destination was specified in the invocation.\n" 36 " - Text file : the file where the downloaded data where saved.\n" 37 " - Text bodyData : the downloaded data if no destination file was specified.\n" 38 "If the transfer failed the result is a Set with the following fields:\n" 39 " - Real failStatus : the error code.\n" 40 " - Text explain : a string with a description of the error.\n" 41 "Examples:\n 42 // Ex. 1: request an http url and return the result in a variable. 43 Set result1 = CurlApi::GetUrl( [[ Text url = \"http://packages.tol-project.org/OfficialTolArchiveNetwork/repository.php?tol_package_version=1.1&tol_version=v2.0.1%20b.4&action=ping&key=658184943\", Real verbose=1, Real connecttimeout=3 ]] ); 44 If( result1::failStatus, { 45 WriteLn( \"CurlApi::GetUrl error: \"<<result1::details ) 46 }, { 47 WriteLn( \"CurlApi::GetUrl ok, the result is: \"<<result1::bodyData ) 48 } ); 49 50 // Ex. 2: request an http url and download the result into a file 51 Set result2 = CurlApi::GetUrl( [[ Text url = \"http://packages.tol-project.org/OfficialTolArchiveNetwork/repository.php?action=download&format=attachment&package=BysMcmc.4.4\", Text file=\"/tmp/BysMcmc.4.4.zip\", Real verbose=1, Real connecttimeout=3 ]] ); 52 If( result2::failStatus, { 53 WriteLn( \"CurlApi::GetUrl error: \"<<result2::details ) 54 }, { 55 WriteLn( \"CurlApi::GetUrl ok, the result was downloaded to: \"<<result2::file ) 56 } ); 57 58 // Ex. 3: request an ftp url and download the result into a file 59 Set result3 = CurlApi::GetUrl( [[ Text url = \"ftp://ftp.rediris.es//pub/OpenBSD/README\", Text file=\"/tmp/README\", Real verbose=1, Real connecttimeout=30 ]] ); 60 " 61 ; 19 62 Set GetUrl( NameBlock args ) 20 63 { … … 23 66 24 67 Text url = args::url; 25 Text file = args::file; 68 //Text file = getOptArg::file; 69 Text file = getOptArg( args, "file", "" ); 70 Real verbose = getOptArg( args, "verbose", 0 ); 71 Real connecttimeout = getOptArg( args, "connecttimeout", 5 ); 72 // un paquete no debe tardar mas de 60 segundos en bajar 73 Real timeout = getOptArg( args, "timeout", 60 ); 26 74 // otros argumentos opcionales seran tratados mas adelante 27 Real verbose = getOptArg( args, "verbose", 0 ); 28 Set cmd = [[ "::TolCurl::getUrl", url, file ]]; 75 Set cmd = [[ "::TolCurl::getUrl", url, 76 "-file", file, "-verbose", If( verbose, "1", "0" ), 77 "-connecttimeout", FormatReal(connecttimeout, "%.0f"), 78 "-timeout", FormatReal(timeout, "%.0f") ]]; 29 79 Set tclResult = Tcl_EvalEx( cmd ); 30 80 Real status = tclResult["status"]; 31 81 Set If( status, { 32 Set curlResult = { 82 Set curlResult = { 33 83 Eval( tclResult["result"] ) 34 84 } … … 38 88 } ) 39 89 }; 90 91 // Set result = CurlApi::GetUrl( [[ Text url = "http://packages.tol-project.org/OfficialTolArchiveNetwork/repository.php?tol_package_version=1.1&tol_version=v2.0.1%20b.4&action=ping&key=658184943", Real verbose=1, Real connecttimeout=3 ]] );
Note: See TracChangeset
for help on using the changeset viewer.
