Skip to content

Commit

Permalink
Closes #95 - Added optional flag defaulted to true to say if a member…
Browse files Browse the repository at this point in the history
… is not subscribed then they "don't exist"
  • Loading branch information
brandonseydel committed Sep 22, 2016
1 parent 56c737d commit 0f0c1fa
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 63 deletions.
88 changes: 44 additions & 44 deletions MailChimp.Net/Interfaces/IMemberLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,26 @@ public interface IMemberLogic
Task DeleteAsync(string listId, string emailAddress);


/// <summary>
/// Gets the activities for a specific list
/// </summary>
/// <param name="listId"></param>
/// <param name="emailAddress"></param>
/// <param name="request"></param>
/// <returns></returns>
Task<IEnumerable<Activity>> GetActivitiesAsync(string listId, string emailAddress, BaseRequest request = null);
/// <summary>
/// Gets the activities for a specific list
/// </summary>
/// <param name="listId"></param>
/// <param name="emailAddress"></param>
/// <param name="request"></param>
/// <returns></returns>
Task<IEnumerable<Activity>> GetActivitiesAsync(string listId, string emailAddress, BaseRequest request = null);

/// <summary>
/// The get all async.
/// </summary>
/// <param name="listId">
/// The list id.
/// </param>
/// <param name="memberRequest"></param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
Task<IEnumerable<Member>> GetAllAsync(string listId, MemberRequest memberRequest = null);
/// <summary>
/// The get all async.
/// </summary>
/// <param name="listId">
/// The list id.
/// </param>
/// <param name="memberRequest"></param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
Task<IEnumerable<Member>> GetAllAsync(string listId, MemberRequest memberRequest = null);

/// <summary>
/// Get the total number of members in the list
Expand All @@ -91,34 +91,34 @@ public interface IMemberLogic
/// </returns>
Task<Member> GetAsync(string listId, string emailAddress, BaseRequest request = null);

/// <summary>
/// The check if exists async.
/// </summary>
/// <param name="listId">
/// The list id.
/// </param>
/// <param name="emailAddress">
/// <summary>
/// The check if exists async.
/// </summary>
/// <param name="listId">
/// The list id.
/// </param>
/// <param name="emailAddress">
/// </param>
/// <param name="request"></param>
/// The email address.
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
Task<bool> ExistsAsync(string listId, string emailAddress, BaseRequest request = null);
/// The email address.
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
Task<bool> ExistsAsync(string listId, string emailAddress, BaseRequest request = null, bool falseIfUnsubscribed = true);

/// <exception cref="ArgumentNullException"><paramref>
/// <name>uriString</name>
/// </paramref>
/// is null. </exception>
/// <exception cref="UriFormatException">In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, <see cref="T:System.FormatException" />, instead.<paramref name="uriString" /> is empty.-or- The scheme specified in <paramref name="uriString" /> is not correctly formed. See <see cref="M:System.Uri.CheckSchemeName(System.String)" />.-or- <paramref name="uriString" /> contains too many slashes.-or- The password specified in <paramref name="uriString" /> is not valid.-or- The host name specified in <paramref name="uriString" /> is not valid.-or- The file name specified in <paramref name="uriString" /> is not valid. -or- The user name specified in <paramref name="uriString" /> is not valid.-or- The host or authority name specified in <paramref name="uriString" /> cannot be terminated by backslashes.-or- The port number specified in <paramref name="uriString" /> is not valid or cannot be parsed.-or- The length of <paramref name="uriString" /> exceeds 65519 characters.-or- The length of the scheme specified in <paramref name="uriString" /> exceeds 1023 characters.-or- There is an invalid character sequence in <paramref name="uriString" />.-or- The MS-DOS path specified in <paramref name="uriString" /> must start with c:\\.</exception>
/// <exception cref="InvalidOperationException">This member belongs to a type that is loaded into the reflection-only context. See How to: Load Assemblies into the Reflection-Only Context.</exception>
/// <exception cref="MailChimpException">
/// Custom Mail Chimp Exception
/// </exception>
/// <exception cref="NotSupportedException"><paramref name="element" /> is not a constructor, method, property, event, type, or field. </exception>
/// <exception cref="TypeLoadException">A custom attribute type cannot be loaded. </exception>
/// <exception cref="ArgumentOutOfRangeException">Enlarging the value of this instance would exceed <see cref="P:System.Text.StringBuilder.MaxCapacity" />. </exception>
Task<MemberResponse> GetResponseAsync(string listId, MemberRequest memberRequest = null);
/// <exception cref="ArgumentNullException"><paramref>
/// <name>uriString</name>
/// </paramref>
/// is null. </exception>
/// <exception cref="UriFormatException">In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, <see cref="T:System.FormatException" />, instead.<paramref name="uriString" /> is empty.-or- The scheme specified in <paramref name="uriString" /> is not correctly formed. See <see cref="M:System.Uri.CheckSchemeName(System.String)" />.-or- <paramref name="uriString" /> contains too many slashes.-or- The password specified in <paramref name="uriString" /> is not valid.-or- The host name specified in <paramref name="uriString" /> is not valid.-or- The file name specified in <paramref name="uriString" /> is not valid. -or- The user name specified in <paramref name="uriString" /> is not valid.-or- The host or authority name specified in <paramref name="uriString" /> cannot be terminated by backslashes.-or- The port number specified in <paramref name="uriString" /> is not valid or cannot be parsed.-or- The length of <paramref name="uriString" /> exceeds 65519 characters.-or- The length of the scheme specified in <paramref name="uriString" /> exceeds 1023 characters.-or- There is an invalid character sequence in <paramref name="uriString" />.-or- The MS-DOS path specified in <paramref name="uriString" /> must start with c:\\.</exception>
/// <exception cref="InvalidOperationException">This member belongs to a type that is loaded into the reflection-only context. See How to: Load Assemblies into the Reflection-Only Context.</exception>
/// <exception cref="MailChimpException">
/// Custom Mail Chimp Exception
/// </exception>
/// <exception cref="NotSupportedException"><paramref name="element" /> is not a constructor, method, property, event, type, or field. </exception>
/// <exception cref="TypeLoadException">A custom attribute type cannot be loaded. </exception>
/// <exception cref="ArgumentOutOfRangeException">Enlarging the value of this instance would exceed <see cref="P:System.Text.StringBuilder.MaxCapacity" />. </exception>
Task<MemberResponse> GetResponseAsync(string listId, MemberRequest memberRequest = null);

string Hash(string emailAddress);
}
Expand Down
36 changes: 18 additions & 18 deletions MailChimp.Net/Logic/CampaignLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,32 +323,32 @@ public async Task<Campaign> GetAsync(string id)
{
using (var client = this.CreateMailClient("campaigns/"))
{
string dashboardLink = string.Empty;
string dashboardLink = string.Empty;
var response = await client.GetAsync($"{id}").ConfigureAwait(false);
await response.EnsureSuccessMailChimpAsync().ConfigureAwait(false);

IEnumerable<string> linkValues;
if (response.Headers.TryGetValues("Link", out linkValues))
{
var linkValue = linkValues?.FirstOrDefault();
var dashboardLinkSection = linkValue?.Split(';')?.FirstOrDefault(x => x.Contains("show"));
IEnumerable<string> linkValues;
if (response.Headers.TryGetValues("Link", out linkValues))
{
var linkValue = linkValues?.FirstOrDefault();
var dashboardLinkSection = linkValue?.Split(';')?.FirstOrDefault(x => x.Contains("show"));

if (!string.IsNullOrWhiteSpace(dashboardLinkSection))
{
var indexOfFirstCarrot = dashboardLinkSection.IndexOf("<") + 1;
var indexOfSecondCarrot = dashboardLinkSection.IndexOf(">");
if (!string.IsNullOrWhiteSpace(dashboardLinkSection))
{
var indexOfFirstCarrot = dashboardLinkSection.IndexOf("<") + 1;
var indexOfSecondCarrot = dashboardLinkSection.IndexOf(">");

if (indexOfFirstCarrot > -1 && indexOfSecondCarrot > indexOfFirstCarrot)
{
dashboardLink = dashboardLinkSection?.Substring(indexOfFirstCarrot, indexOfSecondCarrot - indexOfFirstCarrot);
}
}
}
if (indexOfFirstCarrot > -1 && indexOfSecondCarrot > indexOfFirstCarrot)
{
dashboardLink = dashboardLinkSection?.Substring(indexOfFirstCarrot, indexOfSecondCarrot - indexOfFirstCarrot);
}
}
}

var campaign = await response.Content.ReadAsAsync<Campaign>().ConfigureAwait(false);

campaign.DashboardLink = dashboardLink;
return campaign;
campaign.DashboardLink = dashboardLink;
return campaign;
}
}

Expand Down
8 changes: 7 additions & 1 deletion MailChimp.Net/Logic/MemberLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,19 @@ public async Task<Member> GetAsync(string listId, string emailAddress, BaseReque
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
public async Task<bool> ExistsAsync(string listId, string emailAddress, BaseRequest request = null)
public async Task<bool> ExistsAsync(string listId, string emailAddress, BaseRequest request = null, bool falseIfUnsubscribed = true)
{
using (var client = this.CreateMailClient($"{BaseUrl}/"))
{
var response = await client.GetAsync($"{listId}/members/{this.Hash(emailAddress.ToLower())}{request?.ToQueryString()}").ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
if (falseIfUnsubscribed)
{
var member = await response.Content.ReadAsAsync<Member>().ConfigureAwait(false);
return member.Status != Status.Unsubscribed;
}

return true;
}

Expand Down

0 comments on commit 0f0c1fa

Please sign in to comment.