diff options
-rw-r--r-- | SendGrid/SendGridMail/Transport/Web.cs | 28 | ||||
-rwxr-xr-x | SendGrid/Tests/TestStreamedFileBody.cs | 35 | ||||
-rw-r--r--[-rwxr-xr-x] | SendGrid/Tests/Tests.csproj | 15 |
3 files changed, 23 insertions, 55 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); } diff --git a/SendGrid/Tests/TestStreamedFileBody.cs b/SendGrid/Tests/TestStreamedFileBody.cs deleted file mode 100755 index 271b194..0000000 --- a/SendGrid/Tests/TestStreamedFileBody.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
-using SendGridMail;
-
-namespace Tests
-{
- [TestFixture]
- public class TestStreamedFileBody
- {
- [Test]
- public void TestGetContent()
- {
- var name = "foo";
- var file = "bar";
- var boundary = "raz";
-
- var memoryStream = new MemoryStream();
- var stream = new StreamWriter(memoryStream);
- stream.Write(file);
- stream.Flush();
- stream.Close();
-
- //var streamedFile = new StreamedFileBody(memoryStream, name);
- //var bytes = streamedFile.GetContent(boundary);
- //var result = System.Text.Encoding.ASCII.GetString(bytes);
- //var expected = "--raz\r\nContent-Disposition: form-data; name=\"files[foo]\"; filename=\"foo\"\r\nContent-Type: image/png\r\n\r\nbar\r\n";
- //Assert.AreEqual(expected, result, "message formated correctly");
-
- }
- }
-}
diff --git a/SendGrid/Tests/Tests.csproj b/SendGrid/Tests/Tests.csproj index cdfd9b7..ec8f6ab 100755..100644 --- a/SendGrid/Tests/Tests.csproj +++ b/SendGrid/Tests/Tests.csproj @@ -10,13 +10,12 @@ <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Tests</RootNamespace>
<AssemblyName>Tests</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
+ <DebugSymbols>True</DebugSymbols>
<DebugType>full</DebugType>
- <Optimize>false</Optimize>
+ <Optimize>False</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
@@ -24,17 +23,13 @@ </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
+ <Optimize>True</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="CodeScales.Http, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\SendGridMail\lib\CodeScales.Http.dll</HintPath>
- </Reference>
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference>
@@ -54,6 +49,9 @@ <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
+ <Reference Include="CodeScales.Http">
+ <HintPath>..\SendGridMail\lib\CodeScales.Http.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="TestHeader.cs" />
@@ -61,7 +59,6 @@ <Compile Include="TestJsonUtils.cs" />
<Compile Include="TestSendgrid.cs" />
<Compile Include="TestSendgridMessageSetup.cs" />
- <Compile Include="TestStreamedFileBody.cs" />
<Compile Include="TestTreeNode.cs" />
<Compile Include="TestUtils.cs" />
<Compile Include="Transport\TestWeb.cs" />
|