Skip to content

Commit

Permalink
Merge pull request #3 from KingdomFirst/SubscriberUpdatesToMatchCurre…
Browse files Browse the repository at this point in the history
…ntAPI

Add support for status filter in subscribers and listsubscribers get methods
  • Loading branch information
treyhendon authored Dec 23, 2020
2 parents c351341 + 5137fea commit 7540013
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
11 changes: 11 additions & 0 deletions ClearstreamDotNetFramework/Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,16 @@ public enum AutoresponseSetting
FIRST,
NEW
}

/// <summary>
/// Subscriber search status options.
/// </summary>
public enum SubscriberStatus
{
ACTIVE,
INACTIVE,
OPTOUT,
ANY
}
}
}
2 changes: 1 addition & 1 deletion ClearstreamDotNetFramework/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
[assembly: Guid( "6fb4d1a8-5f86-454d-94bb-fc1365523330" )]

// Auto increment assembly versions
[assembly: AssemblyVersion( "1.4.*" )]
[assembly: AssemblyVersion( "1.5.*" )]
19 changes: 18 additions & 1 deletion ClearstreamDotNetFramework/v1/Endpoints/Lists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ListResponse DeleteList( int id, bool forceDelete = false )
/// <param name="mobileNumber">The mobile number to search for in the list.</param>
/// <param name="searchOperator">The search operator to use if multiple search params are provided.</param>
/// <returns></returns>
public SubscribersResponse GetListSubscribers( int id, int? limit = null, int? page = null, string firstName = null, string lastName = null, string mobileNumber = null, SearchOperator searchOperator = SearchOperator.AND )
public SubscribersResponse GetListSubscribers( int id, int? limit = null, int? page = null, string firstName = null, string lastName = null, string mobileNumber = null, SearchOperator searchOperator = SearchOperator.AND, SubscriberStatus status = SubscriberStatus.ACTIVE )
{
var request = new RestRequest( $"lists/{id}/subscribers" );
request.Method = Method.GET;
Expand Down Expand Up @@ -186,12 +186,29 @@ public SubscribersResponse GetListSubscribers( int id, int? limit = null, int? p
searchParams = searchParams + 1;
}

request.AddParameter( "status", status.ToString(), ParameterType.GetOrPost );
searchParams = searchParams + 1;

if ( searchParams > 1 )
{
request.AddParameter( "operator", searchOperator.ToString(), ParameterType.GetOrPost );
}

return Execute<SubscribersResponse>( request );
}

/// <summary>
/// Removes a subscriber from a list. https://api-docs.clearstream.io/#delete-a-subscriber
/// </summary>
/// <param name="mobileNumber">The mobile number.</param>
/// <param name="listId">The list id.</param>
/// <returns></returns>
public ListResponse DeleteListSubscriber( string mobileNumber, int listId )
{
var request = new RestRequest( $"lists/{listId}/subscribers/{mobileNumber}" );
request.Method = Method.DELETE;

return Execute<ListResponse>( request );
}
}
}
12 changes: 10 additions & 2 deletions ClearstreamDotNetFramework/v1/Endpoints/Subscribers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public partial class Client
/// <param name="mobileNumber">The mobile number to search for.</param>
/// <param name="searchOperator">The search operator to use if multiple search params are provided.</param>
/// <returns></returns>
public SubscribersResponse GetSubscribers( int? limit = null, int? page = null, string firstName = null, string lastName = null, string mobileNumber = null, SearchOperator searchOperator = SearchOperator.AND )
public SubscribersResponse GetSubscribers( int? limit = null, int? page = null, string firstName = null, string lastName = null, string mobileNumber = null, SearchOperator searchOperator = SearchOperator.AND, SubscriberStatus status = SubscriberStatus.ACTIVE )
{
var request = new RestRequest( "subscribers" );
request.Method = Method.GET;
Expand Down Expand Up @@ -69,6 +69,9 @@ public SubscribersResponse GetSubscribers( int? limit = null, int? page = null,
searchParams = searchParams + 1;
}

request.AddParameter( "status", status.ToString(), ParameterType.GetOrPost );
searchParams = searchParams + 1;

if ( searchParams > 1 )
{
request.AddParameter( "operator", searchOperator.ToString(), ParameterType.GetOrPost );
Expand Down Expand Up @@ -176,7 +179,7 @@ public SubscriberResponse CreateSubscriber( string mobileNumber, List<int> lists
/// <param name="lastName">The last name.</param>
/// <param name="email">The email.</param>
/// <returns></returns>
public SubscriberResponse UpdateSubscriber( string mobileNumber, string firstName = null, string lastName = null, string email = null )
public SubscriberResponse UpdateSubscriber( string mobileNumber, string firstName = null, string lastName = null, string email = null, List<int> lists = null )
{
var request = new RestRequest( $"subscribers/{mobileNumber}" );
request.Method = Method.PATCH;
Expand All @@ -196,6 +199,11 @@ public SubscriberResponse UpdateSubscriber( string mobileNumber, string firstNam
request.AddParameter( "email", email, ParameterType.GetOrPost );
}

if ( lists != null )
{
request.AddParameter( "lists", string.Join( ",", lists.ToArray() ), ParameterType.GetOrPost );
}

return Execute<SubscriberResponse>( request );
}

Expand Down

0 comments on commit 7540013

Please sign in to comment.