lib/curl: revamp and move the curl_mail example to a nitunit
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 7 Jun 2015 13:29:06 +0000 (09:29 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sun, 7 Jun 2015 19:41:46 +0000 (15:41 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/curl/curl.nit
lib/curl/examples/curl_mail.nit [deleted file]
tests/sav/curl_mail.res [deleted file]

index 7b1918c..8c58646 100644 (file)
@@ -194,6 +194,33 @@ class CurlHTTPRequest
 end
 
 # CURL Mail Request
+#
+# ~~~
+# # Craft mail
+# var mail = new CurlMail("sender@example.org",
+#                            to=["to@example.org"], cc=["bob@example.org"])
+#
+# mail.headers_body["Content-Type:"] = """text/html; charset="UTF-8""""
+# mail.headers_body["Content-Transfer-Encoding:"] = "quoted-printable"
+#
+# mail.body = "<h1>Here you can write HTML stuff.</h1>"
+# mail.subject = "Hello From My Nit Program"
+#
+# # Set mail server
+# var error = mail.set_outgoing_server("smtps://smtp.example.org:465",
+#                                      "user@example.org", "mypassword")
+# if error != null then
+#     print "Mail Server Error: {error}"
+#     exit 0
+# end
+#
+# # Send
+# error = mail.execute
+# if error != null then
+#     print "Transfer Error: {error}"
+#     exit 0
+# end
+# ~~~
 class CurlMail
        super CurlRequest
        super NativeCurlCallbacks
diff --git a/lib/curl/examples/curl_mail.nit b/lib/curl/examples/curl_mail.nit
deleted file mode 100644 (file)
index d791611..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Mail sender sample using the Curl module
-module curl_mail
-
-import curl
-
-var curl = new Curl
-var mail_request = new CurlMailRequest(curl)
-
-# Networks
-var response: nullable CurlResponse = mail_request.set_outgoing_server("smtps://smtp.example.org:465", "user@example.org", "mypassword")
-if response isa CurlResponseFailed then
-       print "Error code : {response.error_code}"
-       print "Error msg : {response.error_msg}"
-end
-
-# Headers
-mail_request.from = "Billy Bob"
-mail_request.to = ["user@example.org"]
-mail_request.cc = ["bob@example.org"]
-mail_request.bcc = null
-
-var headers_body = new HeaderMap
-headers_body["Content-Type:"] = "text/html; charset=\"UTF-8\""
-headers_body["Content-Transfer-Encoding:"] = "quoted-printable"
-mail_request.headers_body = headers_body
-
-# Content
-mail_request.body = "<h1>Here you can write HTML stuff.</h1>"
-mail_request.subject = "Hello From My Nit Program"
-
-# Others
-mail_request.verbose = false
-
-# Send mail
-response = mail_request.execute
-if response isa CurlResponseFailed then
-       print "Error code : {response.error_code}"
-       print "Error msg : {response.error_msg}"
-else if response isa CurlMailResponseSuccess then
-       print "Mail Sent"
-else
-       print "Unknown Curl Response type"
-end
diff --git a/tests/sav/curl_mail.res b/tests/sav/curl_mail.res
deleted file mode 100644 (file)
index 5e63d7f..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-Error code : 6
-Error msg : Couldn't resolve host name