summaryrefslogtreecommitdiffstats
path: root/SendGrid/SendGridMail/Transport/Web.cs
diff options
context:
space:
mode:
authorBrandon West <brawest@gmail.com>2013-01-12 11:01:30 -0700
committerBrandon West <brawest@gmail.com>2013-01-12 11:01:30 -0700
commitce34793a0a9ccbdd8076bc713e4fe389372bec16 (patch)
tree3d72347af026671ec3398574bfdca8dfdf4e6604 /SendGrid/SendGridMail/Transport/Web.cs
parent0011c7d7633ca413f99a6b59fea4475e6953afe7 (diff)
downloadsendgrid-csharp-ce34793a0a9ccbdd8076bc713e4fe389372bec16.zip
sendgrid-csharp-ce34793a0a9ccbdd8076bc713e4fe389372bec16.tar.gz
sendgrid-csharp-ce34793a0a9ccbdd8076bc713e4fe389372bec16.tar.bz2
add todos and remove failing test for now
Diffstat (limited to 'SendGrid/SendGridMail/Transport/Web.cs')
-rw-r--r--SendGrid/SendGridMail/Transport/Web.cs28
1 files changed, 17 insertions, 11 deletions
diff --git a/SendGrid/SendGridMail/Transport/Web.cs b/SendGrid/SendGridMail/Transport/Web.cs
index 2df0c95..27dceb6 100644
--- a/SendGrid/SendGridMail/Transport/Web.cs
+++ b/SendGrid/SendGridMail/Transport/Web.cs
@@ -12,7 +12,8 @@ namespace SendGridMail.Transport
public class Web : ITransport
{
#region Properties
- public const String BaseURl = "http://sendgrid.com/api/";
+ //TODO: Make this configurable
+ public const String BaseURl = "https://sendgrid.com/api/";
public const String Endpoint = "mail.send";
public const String JsonFormat = "json";
public const String XmlFormat = "xml";
@@ -69,6 +70,8 @@ namespace SendGridMail.Transport
private void AttachFiles(ISendGrid message, RestRequest request)
{
+ //TODO: think the files are being sent in the POST data... but we need to add them as params as well
+
var files = FetchFileBodies(message);
files.ForEach(kvp => request.AddFile(Path.GetFileName(kvp.Key), kvp.Key));
@@ -77,9 +80,9 @@ namespace SendGridMail.Transport
var name = file.Key;
var stream = file.Value;
var writer = new Action<Stream>(
- delegate(Stream stream2)
+ delegate(Stream s)
{
- stream.CopyTo(stream2);
+ stream.CopyTo(s);
}
);
@@ -87,13 +90,16 @@ namespace SendGridMail.Transport
}
}
- private void CheckForErrors(IRestResponse response)
- {
- //TODO: Check the response status: RestResponse.Status will be set to ResponseStatus.Error, otherwise it will be ResponseStatus.Completed.
- var status = response.Content;
- var stream = new MemoryStream(Encoding.UTF8.GetBytes(status));
-
+ private void CheckForErrors (IRestResponse response)
+ {
+ //transport error
+ if (response.ResponseStatus == ResponseStatus.Error) {
+ throw new Exception(response.ErrorMessage);
+ }
+ //TODO: check for HTTP errors... don't throw exceptions just pass info along?
+ var content = response.Content;
+ var stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
using (var reader = XmlReader.Create(stream))
{
@@ -108,11 +114,11 @@ namespace SendGridMail.Transport
case "message": // success
bool errors = reader.ReadToNextSibling("errors");
if (errors)
- throw new ProtocolViolationException(status);
+ throw new ProtocolViolationException(content);
else
return;
case "error": // failure
- throw new ProtocolViolationException(status);
+ throw new ProtocolViolationException(content);
default:
throw new ArgumentException("Unknown element: " + reader.Name);
}