Skip to content

Commit

Permalink
Added Automation endpoint and multiple fixes. See notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kylegregory committed Jun 5, 2018
1 parent 4c89964 commit 1a4cfd4
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 33 deletions.
6 changes: 3 additions & 3 deletions EmmaSharp/EmmaSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<Compile Include="Extensions\JsonSerializer.cs" />
<Compile Include="Extensions\PlainJsonStringConverter.cs" />
<Compile Include="Extensions\QueryFactory.cs" />
<Compile Include="Methods\Automation.cs" />
<Compile Include="Models\Automation\Workflow.cs" />
<Compile Include="Models\Mailings\ForwardMailing.cs" />
<Compile Include="Models\Mailings\MailingHeadsUp.cs" />
<Compile Include="Models\Mailings\MailingIdentifier.cs" />
Expand Down Expand Up @@ -89,7 +91,6 @@
<Compile Include="Models\Members\ImportStatus.cs" />
<Compile Include="Models\Members\MemberBulk.cs" />
<Compile Include="Models\Members\MembersAdd.cs" />
<Compile Include="Models\Members\MemberGroups.cs" />
<Compile Include="Models\Members\RemoveMemberGroups.cs" />
<Compile Include="Models\Members\UpdateMember.cs" />
<Compile Include="Models\Members\SignupMember.cs" />
Expand Down Expand Up @@ -140,5 +141,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
52 changes: 52 additions & 0 deletions EmmaSharp/Methods/Automation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using EmmaSharp.Models.Automation;
using RestSharp;
using RestSharp.Serializers;
using System.Collections.Generic;

namespace EmmaSharp
{
public partial class EmmaApi
{
#region Automation

/// <summary>
/// Gets a list of this account’s automation workflows.
/// </summary>
/// <returns>A list of automation workflows in the given account.</returns>
public List<Workflow> GetWorkflows()
{
var request = new RestRequest();
request.Resource = "/{accountId}/automation/workflows";

return Execute<List<Workflow>>(request);
}

/// <summary>
/// Gets detailed information about a single workflow.
/// </summary>
/// <param name="workflowId">The ID of the Workflow to return.</param>
/// <returns>A single workflow if one exists</returns>
public Workflow GetWorkflowById(string workflowId)
{
var request = new RestRequest();
request.Resource = "/{accountId}/automation/workflows/{workflowId}";
request.AddUrlSegment("workflowId", workflowId);

return Execute<Workflow>(request);
}

/// <summary>
/// Gets the counts of workflows for this account by workflow state.
/// </summary>
/// <returns>Returns counts for the workflow by state ("active", "inactive" and "draft").</returns>
public WorkflowCount GetWorkflowCounts()
{
var request = new RestRequest();
request.Resource = "/{accountId}/automation/counts";

return Execute<WorkflowCount>(request);
}

#endregion
}
}
12 changes: 6 additions & 6 deletions EmmaSharp/Methods/Members.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,18 @@ public List<Group> GetMemberGroups(string memberId)
/// Add a single member to one or more groups.
/// </summary>
/// <param name="memberId">Member identifier.</param>
/// <param name="members">Group ids to which to add this member.</param>
/// <param name="groupIds">Group ids to which to add this member.</param>
/// <returns>An array of ids of the affected groups.</returns>
/// <remarks>Http404 if no member is found.</remarks>
public List<int> AddMemberToGroups(string memberId, MemberGroups members)
public List<int> AddMemberToGroups(string memberId, List<int> groupIds)
{
var request = new RestRequest(Method.PUT);
request.Resource = "/{accountId}/members/{memberId}/groups";
request.AddUrlSegment("memberId", memberId);

request.RequestFormat = DataFormat.Json;
request.JsonSerializer = new EmmaJsonSerializer();
request.AddBody(members);
request.AddBody(new { group_ids = groupIds });

return Execute<List<int>>(request);
}
Expand All @@ -287,18 +287,18 @@ public List<int> AddMemberToGroups(string memberId, MemberGroups members)
/// Remove a single member from one or more groups.
/// </summary>
/// <param name="memberId">Member identifier.</param>
/// <param name="members">Group ids from which to remove this member</param>
/// <param name="groupIds">Group ids from which to remove this member</param>
/// <returns>An array of references to the affected groups.</returns>
/// <remarks>Http404 if no member is found.</remarks>
public List<int> RemoveMemberFromGroups(string memberId, MemberGroups members)
public List<int> RemoveMemberFromGroups(string memberId, List<int> groupIds)
{
var request = new RestRequest(Method.PUT);
request.Resource = "/{accountId}/members/{memberId}/groups/remove";
request.AddUrlSegment("memberId", memberId);

request.RequestFormat = DataFormat.Json;
request.JsonSerializer = new EmmaJsonSerializer();
request.AddBody(members);
request.AddBody(new { group_ids = groupIds });

return Execute<List<int>>(request);
}
Expand Down
53 changes: 53 additions & 0 deletions EmmaSharp/Models/Automation/Workflow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using EmmaSharp.Extensions;
using Newtonsoft.Json;
using System;
using System.Runtime.Serialization;

namespace EmmaSharp.Models.Automation
{
public class Workflow
{
[JsonProperty("workflow_id")]
public string WorkflowId { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("status")]
public WorkflowStatus Status { get; set; }

[JsonConverter(typeof(EmmaDateConverter))]
[JsonProperty("updated_at")]
public DateTime UpdatedAt { get; set; }

[JsonConverter(typeof(EmmaDateConverter))]
[JsonProperty("created_at")]
public DateTime CreatedAt { get; set; }
}

public enum WorkflowStatus
{
[EnumMember(Value = "active")]
Active,
[EnumMember(Value = "inactive")]
Inactive,
[EnumMember(Value = "draft")]
Draft
}

public class WorkflowCount
{
[JsonProperty("account_id")]
public int? AccountId { get; set; }

[JsonProperty("draft")]
public int Draft { get; set; }

[JsonProperty("active")]
public int Active { get; set; }

[JsonProperty("inactive")]
public int Inactive { get; set; }
}
}

21 changes: 0 additions & 21 deletions EmmaSharp/Models/Members/MemberGroups.cs

This file was deleted.

4 changes: 1 addition & 3 deletions EmmaSharp/Models/Members/MembersAdd.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace EmmaSharp.Models.Members
{
public class MembersAdd
{
[JsonProperty("import_id")]
public int ImportId { get; set; }
public long ImportId { get; set; }
}
}
6 changes: 6 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ EmmaSharp Release Notes
=========

## HEAD (Unreleased)


## New in 1.2.0 (Released 2018/06/05)
* Added Automation Workflow endpoints.
* Reduced parameter complexity in AddMemberToGroups and RemoveMemberFromGroups.
* Set ImportId to long in MembersAdd. [#35](https://github.com/kylegregory/EmmaSharp/pull/35) via @tjdavis1111
* Update return type for GetSearchesCount. [#33](https://github.com/kylegregory/EmmaSharp/pull/33) via @MilSix
* Fixes UpdateStatusOfGroupMembersBasedOnCurrentStatus method to put groupId in the request body. [#32](https://github.com/kylegregory/EmmaSharp/issues/32) via @MiaWang7777
* Fixes AddMemberToGroups by adding JSON Serializer. [#34](https://github.com/kylegregory/EmmaSharp/issues/34) via @pbhandari1s
Expand Down

0 comments on commit 1a4cfd4

Please sign in to comment.