From: Alexis Laferrière Date: Thu, 6 Mar 2014 20:05:25 +0000 (-0500) Subject: lib/curl: clean up surperfluous types X-Git-Tag: v0.6.5~46^2~5 X-Git-Url: http://nitlanguage.org lib/curl: clean up surperfluous types Signed-off-by: Alexis Laferrière --- diff --git a/lib/curl/curl.nit b/lib/curl/curl.nit index 856c5bd..d3d3ca5 100644 --- a/lib/curl/curl.nit +++ b/lib/curl/curl.nit @@ -37,7 +37,7 @@ class Curl # Get an HTTP Request object to perform your own fun http_request(url: String): nullable CurlRequest do - var err: CURLCode + var err err = self.prim_curl.easy_setopt(new CURLOption.follow_location, 1) if not err.is_ok then return null @@ -75,7 +75,7 @@ class CurlRequest do if not self.curl.is_ok then return answer_failure(0, "Curl instance is not correctly initialized") - var err: CURLCode + var err err = self.curl.prim_curl.easy_setopt(new CURLOption.verbose, self.verbose) if not err.is_ok then return answer_failure(err.to_i, err.to_s) @@ -110,16 +110,16 @@ class CurlHTTPRequest end # Execute HTTP request with settings configured through attribute - redef fun execute: CurlResponse + redef fun execute do if not self.curl.is_ok then return answer_failure(0, "Curl instance is not correctly initialized") - var success_response: CurlResponseSuccess = new CurlResponseSuccess - + var success_response = new CurlResponseSuccess var callback_receiver: CurlCallbacks = success_response if self.delegate != null then callback_receiver = self.delegate.as(not null) - var err: CURLCode + var err + # Callbacks err = self.curl.prim_curl.register_callback(callback_receiver, new CURLCallbackType.header) if not err.is_ok then return answer_failure(err.to_i, err.to_s) @@ -153,19 +153,19 @@ class CurlHTTPRequest # Download to file given resource fun download_to_file(output_file_name: nullable String): CurlResponse do - var success_response: CurlFileResponseSuccess = new CurlFileResponseSuccess + var success_response = new CurlFileResponseSuccess var callback_receiver: CurlCallbacks = success_response if self.delegate != null then callback_receiver = self.delegate.as(not null) - var err: CURLCode + var err err = self.curl.prim_curl.register_callback(callback_receiver, new CURLCallbackType.header) if not err.is_ok then return answer_failure(err.to_i, err.to_s) err = self.curl.prim_curl.register_callback(callback_receiver, new CURLCallbackType.stream) if not err.is_ok then return answer_failure(err.to_i, err.to_s) - var opt_name:nullable String + var opt_name if not output_file_name == null then opt_name = output_file_name else if not self.url.substring(self.url.length-1, self.url.length) == "/" then @@ -253,7 +253,7 @@ class CurlMailRequest # Check Curl initialisation if not self.curl.is_ok then return answer_failure(0, "Curl instance is not correctly initialized") - var err: CURLCode + var err # Host & Protocol err = is_supported_outgoing_protocol(host) @@ -273,12 +273,11 @@ class CurlMailRequest end # Execute Mail request with settings configured through attribute - redef fun execute: CurlResponse + redef fun execute do if not self.curl.is_ok then return answer_failure(0, "Curl instance is not correctly initialized") - var success_response: CurlMailResponseSuccess = new CurlMailResponseSuccess - var err: CURLCode + var success_response = new CurlMailResponseSuccess var content = "" # Headers if self.headers != null then @@ -298,6 +297,8 @@ class CurlMailRequest if self.bcc != null and self.bcc.length > 0 then g_rec.append(self.bcc.as(not null)) if g_rec.length < 1 then return answer_failure(0, "The mail recipients can not be empty") + + var err err = self.curl.prim_curl.easy_setopt(new CURLOption.mail_rcpt, g_rec.to_curlslist) if not err.is_ok then return answer_failure(err.to_i, err.to_s) @@ -365,10 +366,10 @@ abstract class CurlResponseSuccessIntern super CurlCallbacks super CurlResponse - var headers: HashMap[String, String] = new HashMap[String, String] + var headers = new HashMap[String, String] # Receive headers from request due to headers callback registering - redef fun header_callback(line: String) + redef fun header_callback(line) do var splitted = line.split_with(':') if splitted.length > 1 then @@ -382,8 +383,8 @@ end class CurlResponseSuccess super CurlResponseSuccessIntern - var body_str: String = "" - var status_code: Int = 0 + var body_str = "" + var status_code = 0 # Receive body from request due to body callback registering redef fun body_callback(line: String) @@ -401,14 +402,14 @@ end class CurlFileResponseSuccess super CurlResponseSuccessIntern - var status_code: Int = 0 - var speed_download: Int = 0 - var size_download: Int = 0 - var total_time: Int = 0 + var status_code = 0 + var speed_download = 0 + var size_download = 0 + var total_time = 0 private var i_file: nullable OFile = null # Receive bytes stream from request due to stream callback registering - redef fun stream_callback(buffer: String, size: Int, count: Int) + redef fun stream_callback(buffer, size, count) do self.i_file.write(buffer, size, count) end @@ -437,7 +438,7 @@ class HeaderMap assert curlNotInitialized: curl.is_init else print "to_url_encoded required a valid instance of CCurl Object." end - var str: String = "" + var str = "" var length = self.length var i = 0 for k, v in self do