Skip to content

Commit

Permalink
Add support for opt outs (#15)
Browse files Browse the repository at this point in the history
* SMS-25 Add support for getting and adding opt outs
  • Loading branch information
jackthorley committed May 10, 2016
1 parent 9b6ed4f commit 7a4489e
Show file tree
Hide file tree
Showing 37 changed files with 1,360 additions and 163 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* -text
4 changes: 2 additions & 2 deletions source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("2.3.0")]
[assembly: AssemblyFileVersion("2.3.0")]
[assembly: AssemblyVersion("2.4.0")]
[assembly: AssemblyFileVersion("2.4.0")]
18 changes: 12 additions & 6 deletions source/com.esendex.sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
Expand All @@ -76,7 +77,6 @@
<Compile Include="core\CharacterSet.cs" />
<Compile Include="core\MessageCollection.cs" />
<Compile Include="core\PagedCollection.cs" />
<Compile Include="exceptions\BadRequestException.cs" />
<Compile Include="extensions\HttpWebResponseExtensions.cs" />
<Compile Include="http\HttpClient.cs" />
<Compile Include="http\HttpRequest.cs" />
Expand All @@ -85,6 +85,7 @@
<Compile Include="adapters\HttpWebRequestAdapter.cs" />
<Compile Include="adapters\HttpWebResponseAdapter.cs" />
<Compile Include="http\HttpResponseHelper.cs" />
<Compile Include="http\HttpUriBuilder.cs" />
<Compile Include="http\IHttpClient.cs" />
<Compile Include="adapters\IHttpWebRequestAdapter.cs" />
<Compile Include="adapters\IHttpWebResponseAdapter.cs" />
Expand All @@ -108,6 +109,12 @@
<Compile Include="messaging\VoiceMessageLanguage.cs" />
<Compile Include="models\requests\SurveysAddRecipientRequest.cs" />
<Compile Include="models\requests\SurveysAddRecipientsRequest.cs" />
<Compile Include="optouts\models\response\FromAddress.cs" />
<Compile Include="optouts\models\response\OptOut.cs" />
<Compile Include="optouts\models\response\OptOutCollection.cs" />
<Compile Include="optouts\models\request\OptOutCreateRequest.cs" />
<Compile Include="optouts\models\response\OptOutCreateResult.cs" />
<Compile Include="optouts\OptOutsService.cs" />
<Compile Include="Properties\BuildInfo.cs" />
<Compile Include="Request.cs" />
<Compile Include="rest\resources\ContactsResource.cs" />
Expand All @@ -120,8 +127,8 @@
<Compile Include="rest\resources\ResourceLinkResource.cs" />
<Compile Include="rest\resources\SessionResource.cs" />
<Compile Include="sent\FailureReason.cs" />
<Compile Include="results\Error.cs" />
<Compile Include="results\SurveyResult.cs" />
<Compile Include="optouts\models\response\OptOutCreateError.cs" />
<Compile Include="surveys\models\SurveyResult.cs" />
<Compile Include="sent\SentMessage.cs" />
<Compile Include="messaging\SmsMessage.cs" />
<Compile Include="messaging\SmsMessageCollection.cs" />
Expand All @@ -135,6 +142,7 @@
<Compile Include="session\ISessionService.cs" />
<Compile Include="session\EsendexSession.cs" />
<Compile Include="session\SessionService.cs" />
<Compile Include="surveys\models\SurveysAddRecipientError.cs" />
<Compile Include="surveys\SurveysService.cs" />
<Compile Include="utilities\ISerialiser.cs" />
<Compile Include="rest\resources\MessageDispatcherResource.cs" />
Expand All @@ -152,9 +160,7 @@
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="builders\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
178 changes: 93 additions & 85 deletions source/core/PagedCollection.cs
Original file line number Diff line number Diff line change
@@ -1,86 +1,94 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

namespace com.esendex.sdk.core
{
/// <summary>
/// Represents a paged collection of objects which all paged collection are derived.
/// </summary>
/// <typeparam name="T">The type of objects.</typeparam>
public abstract class PagedCollection<T> : IPagedCollection<T>
where T : class
{
/// <summary>
/// <![CDATA[Initialises a new instance of the com.esendex.sdk.core.PagedCollection<T>]]>
/// </summary>
public PagedCollection()
{
Items = new List<T>();
}

protected List<T> Items { get; set; }

private int startIndex;

/// <summary>
/// Gets or sets the page number.
/// </summary>
[XmlAttribute("startindex")]
public int PageNumber
{
get
{
// Convert the zero based collection index to a real page number.
return (startIndex/PageSize) + 1;
}
set { startIndex = value; }
}

/// <summary>
/// Gets or sets the page size.
/// </summary>
[XmlAttribute("count")]
public int PageSize { get; set; }

/// <summary>
/// Gets or sets the total number of items in the paged resource.
/// </summary>
[XmlAttribute("totalcount")]
public int TotalItems { get; set; }

/// <summary>
/// Determines whether the specified System.Object are considered equal.
/// </summary>
/// <param name="obj">The System.Object to compare with the current System.Object</param>
/// <returns>true if the specified System.Object is equal to the current System.Object; otherwise, false.</returns>
public override bool Equals(object obj)
{
var other = obj as PagedCollection<T>;

if (other == null) return false;

if (PageNumber != other.PageNumber) return false;
if (PageSize != other.PageSize) return false;
if (TotalItems != other.TotalItems) return false;

if (Items.Count != other.Items.Count) return false;

for (var i = 0; i < Items.Count; i++)
{
if (Items.ElementAt(i) != other.Items.ElementAt(i)) return false;
}

return true;
}

/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>A hash code for the current System.Object</returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using Newtonsoft.Json;

namespace com.esendex.sdk.core
{
/// <summary>
/// Represents a paged collection of objects which all paged collection are derived.
/// </summary>
/// <typeparam name="T">The type of objects.</typeparam>
public abstract class PagedCollection<T> : IPagedCollection<T>
where T : class
{
/// <summary>
/// <![CDATA[Initialises a new instance of the com.esendex.sdk.core.PagedCollection<T>]]>
/// </summary>
public PagedCollection()
{
Items = new List<T>();
}

protected List<T> Items { get; set; }

private int startIndex;

/// <summary>
/// Gets or sets the page number.
/// </summary>
[XmlAttribute("startindex")]
[JsonProperty("startindex")]
public int PageNumber
{
get
{
// Convert the zero based collection index to a real page number.
if (PageSize == 0 && TotalItems == 0)
{
return 1;
}
return (startIndex/PageSize) + 1;
}
set { startIndex = value; }
}

/// <summary>
/// Gets or sets the page size.
/// </summary>
[XmlAttribute("count")]
[JsonProperty("count")]
public int PageSize { get; set; }

/// <summary>
/// Gets or sets the total number of items in the paged resource.
/// </summary>
[XmlAttribute("totalcount")]
[JsonProperty("totalcount")]
public int TotalItems { get; set; }

/// <summary>
/// Determines whether the specified System.Object are considered equal.
/// </summary>
/// <param name="obj">The System.Object to compare with the current System.Object</param>
/// <returns>true if the specified System.Object is equal to the current System.Object; otherwise, false.</returns>
public override bool Equals(object obj)
{
var other = obj as PagedCollection<T>;

if (other == null) return false;

if (PageNumber != other.PageNumber) return false;
if (PageSize != other.PageSize) return false;
if (TotalItems != other.TotalItems) return false;

if (Items.Count != other.Items.Count) return false;

for (var i = 0; i < Items.Count; i++)
{
if (Items.ElementAt(i) != other.Items.ElementAt(i)) return false;
}

return true;
}

/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>A hash code for the current System.Object</returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
16 changes: 0 additions & 16 deletions source/exceptions/BadRequestException.cs

This file was deleted.

1 change: 1 addition & 0 deletions source/extensions/HttpWebResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal static class HttpWebResponseExtensions
public static T DeserialiseJson<T>(this HttpWebResponse response)
{
var serializer = new JsonSerializer();

using (var sr = new StreamReader(response.GetResponseStream()))
using (var jsonTextReader = new JsonTextReader(sr))
{
Expand Down
35 changes: 35 additions & 0 deletions source/http/HttpUriBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Specialized;
using System.Web;

namespace com.esendex.sdk.http
{
public class HttpUriBuilder
{
private readonly UriBuilder _uriBuilder;
private readonly NameValueCollection _query;

private HttpUriBuilder(string url)
{
_uriBuilder = new UriBuilder(url);
_query = HttpUtility.ParseQueryString(string.Empty);
}

public static HttpUriBuilder Create(string url)
{
return new HttpUriBuilder(url);
}

public HttpUriBuilder WithParameter(string name, string value)
{
_query[name] = value;
return this;
}

public Uri Build()
{
_uriBuilder.Query = _query.ToString();
return _uriBuilder.Uri;
}
}
}
Loading

0 comments on commit 7a4489e

Please sign in to comment.