Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved to Hammock

  • Loading branch information...
commit 897a3fcbcfe1fdd81bc18c1583c412a944b7cc9f 1 parent cfe2d83
Daniel danielcrenna authored
BIN  lib/Hammock.dll
View
Binary file not shown
BIN  lib/Newtonsoft.Json.dll
View
Binary file not shown
BIN  lib/RestSharp.dll
View
Binary file not shown
1  src/Postmark.Tests/Postmark.Tests.csproj
View
@@ -61,6 +61,7 @@
<ItemGroup>
<None Include="app.config" />
<None Include="app.config.example" />
+ <None Include="Copy of app.config.example" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Postmark\Postmark.csproj">
10 src/Postmark/Postmark.csproj
View
@@ -34,13 +34,13 @@
<DocumentationFile>bin\Release\Postmark.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <Reference Include="Hammock, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c148cfba29ed1a4d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\lib\Newtonsoft.Json.dll</HintPath>
+ <HintPath>..\..\lib\Hammock.dll</HintPath>
</Reference>
- <Reference Include="RestSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\restsharp\RestSharp\bin\Release\RestSharp.dll</HintPath>
+ <HintPath>..\..\lib\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
@@ -80,6 +80,6 @@
</Target>
-->
<PropertyGroup>
- <PostBuildEvent>"$(SolutionDir)..\lib\ILMerge.exe" /t:library /out:"$(TargetDir)Postmark.dll" "$(TargetDir)Newtonsoft.Json.dll" "$(TargetDir)RestSharp.dll" "$(TargetDir)$(TargetName).dll"</PostBuildEvent>
+ <PostBuildEvent>"$(SolutionDir)..\lib\ILMerge.exe" /t:library /out:"$(TargetDir)Postmark.dll" "$(TargetDir)Newtonsoft.Json.dll" "$(TargetDir)Hammock.dll" "$(TargetDir)$(TargetName).dll" /Internalize</PostBuildEvent>
</PropertyGroup>
</Project>
23 src/Postmark/PostmarkClient.cs
View
@@ -54,11 +54,12 @@
using System.Collections.Specialized;
using System.Net.Mail;
+using Hammock;
+using Hammock.Web;
using Newtonsoft.Json;
using PostmarkDotNet.Converters;
using PostmarkDotNet.Serializers;
using PostmarkDotNet.Validation;
-using RestSharp;
/*
del /q "$(TargetDir)$(TargetName).dll"
@@ -104,7 +105,7 @@ public PostmarkClient(string serverToken)
ServerToken = serverToken;
_client = new RestClient
{
- BaseUrl = "http://api.postmarkapp.com/email"
+ Authority = "http://api.postmarkapp.com"
};
}
@@ -164,15 +165,15 @@ public PostmarkResponse SendMessage(PostmarkMessage message)
{
var request = NewRequest();
- request.AddParameter("Accept", "application/json", ParameterType.HttpHeader);
- request.AddParameter("Content-Type", "application/json; charset=utf-8", ParameterType.HttpHeader);
- request.AddParameter("X-Postmark-Server-Token", ServerToken, ParameterType.HttpHeader);
- request.AddParameter("User-Agent", "Postmark.NET", ParameterType.HttpHeader);
+ request.AddHeader("Accept", "application/json");
+ request.AddHeader("Content-Type", "application/json; charset=utf-8");
+ request.AddHeader("X-Postmark-Server-Token", ServerToken);
+ request.AddHeader("User-Agent", "Postmark.NET");
ValidatePostmarkMessage(message);
CleanPostmarkMessage(message);
- request.AddBody(message);
+ request.Entity = message;
return GetResponse(request);
}
@@ -203,7 +204,7 @@ private static void ValidatePostmarkMessage(PostmarkMessage message)
private PostmarkResponse GetResponse(RestRequest request)
{
- var response = _client.Execute(request);
+ var response = _client.Request(request);
PostmarkResponse result;
switch ((int) response.StatusCode)
@@ -243,9 +244,9 @@ private static RestRequest NewRequest()
{
var request = new RestRequest
{
- Verb = Method.POST,
- RequestFormat = RequestFormat.Json,
- JsonSerializer = _serializer
+ Method = WebMethod.Post,
+ Serializer = _serializer,
+
};
return request;
89 src/Postmark/Serializers/PostmarkSerializer.cs
View
@@ -1,15 +1,18 @@
-using System.IO;
+using System;
+using System.IO;
+using System.Text;
+using Hammock.Serialization;
using Newtonsoft.Json;
-using RestSharp.Serializers;
namespace PostmarkDotNet.Serializers
{
- internal class PostmarkSerializer : ISerializer
+ internal class PostmarkSerializer : ISerializer, IDeserializer
{
- private readonly Newtonsoft.Json.JsonSerializer _serializer;
-
- public PostmarkSerializer(JsonSerializerSettings settings) {
- _serializer = new Newtonsoft.Json.JsonSerializer
+ private readonly JsonSerializer _serializer;
+
+ public PostmarkSerializer(JsonSerializerSettings settings)
+ {
+ _serializer = new JsonSerializer
{
ConstructorHandling = settings.ConstructorHandling,
ContractResolver = settings.ContractResolver,
@@ -19,27 +22,67 @@ internal class PostmarkSerializer : ISerializer
NullValueHandling = settings.NullValueHandling
};
- foreach(var converter in settings.Converters) {
+ foreach (var converter in settings.Converters)
+ {
_serializer.Converters.Add(converter);
}
}
- public string Serialize(object obj) {
- using (var stringWriter = new StringWriter()) {
- using (var jsonTextWriter = new JsonTextWriter(stringWriter)) {
- jsonTextWriter.Formatting = Formatting.Indented;
- jsonTextWriter.QuoteChar = '"';
+ #region IDeserializer Members
+
+ public virtual object Deserialize(string content, Type type)
+ {
+ using (var stringReader = new StringReader(content))
+ {
+ using (var jsonTextReader = new JsonTextReader(stringReader))
+ {
+ return _serializer.Deserialize(jsonTextReader, type);
+ }
+ }
+ }
+
+ public virtual T Deserialize<T>(string content)
+ {
+ using (var stringReader = new StringReader(content))
+ {
+ using (var jsonTextReader = new JsonTextReader(stringReader))
+ {
+ return _serializer.Deserialize<T>(jsonTextReader);
+ }
+ }
+ }
+
+ #endregion
- _serializer.Serialize(jsonTextWriter, obj);
+ #region ISerializer Members
- var result = stringWriter.ToString();
- return result;
- }
- }
- }
+ public virtual string Serialize(object instance, Type type)
+ {
+ using (var stringWriter = new StringWriter())
+ {
+ using (var jsonTextWriter = new JsonTextWriter(stringWriter))
+ {
+ jsonTextWriter.Formatting = Formatting.Indented;
+ jsonTextWriter.QuoteChar = '"';
+
+ _serializer.Serialize(jsonTextWriter, instance);
+
+ var result = stringWriter.ToString();
+ return result;
+ }
+ }
+ }
+
+ public virtual string ContentType
+ {
+ get { return "application/json"; }
+ }
+
+ public Encoding ContentEncoding
+ {
+ get { return Encoding.UTF8; }
+ }
- public string DateFormat { get; set; }
- public string RootElement { get; set; }
- public string Namespace { get; set; }
+ #endregion
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.