Skip to content

Commit

Permalink
Merge pull request #92 from irq/interfaces
Browse files Browse the repository at this point in the history
Interfaces for unit testing
  • Loading branch information
eneifert committed Aug 8, 2014
2 parents b9dcf37 + 5f5cac0 commit 536d368
Show file tree
Hide file tree
Showing 23 changed files with 936 additions and 84 deletions.
19 changes: 17 additions & 2 deletions ZendeskApi_v2/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@

namespace ZendeskApi_v2
{
public class Core
{
public interface ICore
{
#if SYNC
T GetByPageUrl<T>(string pageUrl, int perPage=100);
T RunRequest<T>(string resource, string requestMethod, object body = null);
RequestResult RunRequest(string resource, string requestMethod, object body = null);
#endif

#if ASYNC
Task<T> GetByPageUrlAsync<T>(string pageUrl, int perPage = 100);
Task<T> RunRequestAsync<T>(string resource, string requestMethod, object body = null);
Task<RequestResult> RunRequestAsync(string resource, string requestMethod, object body = null);
#endif
}

public class Core : ICore
{
private const string XOnBehalfOfEmail = "X-On-Behalf-Of";
protected string User;
protected string Password;
Expand Down
19 changes: 17 additions & 2 deletions ZendeskApi_v2/Requests/AccountsAndActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,23 @@

namespace ZendeskApi_v2.Requests
{
public class AccountsAndActivity : Core
{
public interface IAccountsAndActivity : ICore
{
#if SYNC
SettingsResponse GetSettings();
GroupActivityResponse GetActivities();
IndividualActivityResponse GetActivityById(long activityId);
#endif

#if ASYNC
Task<SettingsResponse> GetSettingsAsync();
Task<GroupActivityResponse> GetActivitiesAync();
Task<IndividualActivityResponse> GetActivityByIdAync(long activityId);
#endif
}

public class AccountsAndActivity : Core, IAccountsAndActivity
{

public AccountsAndActivity(string yourZendeskUrl, string user, string password, string apiToken)
: base(yourZendeskUrl, user, password, apiToken)
Expand Down
26 changes: 24 additions & 2 deletions ZendeskApi_v2/Requests/Attachments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,30 @@

namespace ZendeskApi_v2.Requests
{
public class Attachments : Core
{
public interface IAttachments : ICore
{
#if SYNC
Upload UploadAttachment(ZenFile file);
Upload UploadAttachments(IEnumerable<ZenFile> files);
#endif

#if ASYNC
Task<Upload> UploadAttachmentAsync(ZenFile file);
Task<Upload> UploadAttachmentsAsync(IEnumerable<ZenFile> files);

/// <summary>
/// Uploads a file to zendesk and returns the corresponding token id.
/// To upload another file to an existing token just pass in the existing token.
/// </summary>
/// <param name="file"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<Upload> UploadAttachmentAsync(ZenFile file, string token = "");
#endif
}

public class Attachments : Core, IAttachments
{
public Attachments(string yourZendeskUrl, string user, string password, string apiToken)
: base(yourZendeskUrl, user, password, apiToken)
{ }
Expand Down
23 changes: 21 additions & 2 deletions ZendeskApi_v2/Requests/Categories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,27 @@

namespace ZendeskApi_v2.Requests
{
public class Categories : Core
{
public interface ICategories : ICore
{
#if SYNC
GroupCategoryResponse GetCategories();
IndividualCategoryResponse GetCategoryById(long id);
IndividualCategoryResponse CreateCategory(Category category);
IndividualCategoryResponse UpdateCategory(Category category);
bool DeleteCategory(long id);
#endif

#if ASYNC
Task<GroupCategoryResponse> GetCategoriesAsync();
Task<IndividualCategoryResponse> GetCategoryByIdAsync(long id);
Task<IndividualCategoryResponse> CreateCategoryAsync(Category category);
Task<IndividualCategoryResponse> UpdateCategoryAsync(Category category);
Task<bool> DeleteCategoryAsync(long id);
#endif
}

public class Categories : Core, ICategories
{
public Categories(string yourZendeskUrl, string user, string password, string apiToken)
: base(yourZendeskUrl, user, password, apiToken)
{
Expand Down
15 changes: 13 additions & 2 deletions ZendeskApi_v2/Requests/CustomAgentRoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@

namespace ZendeskApi_v2.Requests
{
public class CustomAgentRoles : Core
{
public interface ICustomAgentRoles : ICore
{
#if SYNC
CustomRoles GetCustomRoles();
#endif

#if ASYNC
Task<CustomRoles> GetCustomRolesAsync();
#endif
}

public class CustomAgentRoles : Core, ICustomAgentRoles
{
public CustomAgentRoles(string yourZendeskUrl, string user, string password, string apiToken)
: base(yourZendeskUrl, user, password, apiToken)
{
Expand Down
35 changes: 33 additions & 2 deletions ZendeskApi_v2/Requests/Forums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,39 @@

namespace ZendeskApi_v2.Requests
{
public class Forums : Core
{
public interface IForums : ICore
{
#if SYNC
GroupForumResponse GetForums();
IndividualForumResponse GetForumById(long forumId);
GroupForumResponse GetForumsByCategory(long categoryId);
IndividualForumResponse CreateForum(Forum forum);
IndividualForumResponse UpdateForum(Forum forum);
bool DeleteForum(long id);
GroupForumSubcriptionResponse GetForumSubscriptions();
GroupForumSubcriptionResponse GetForumSubscriptionsByForumId(long forumId);
IndividualForumSubcriptionResponse GetForumSubscriptionsById(long subscriptionId);
IndividualForumSubcriptionResponse CreateForumSubscription(ForumSubscription forumSubscription);
bool DeleteForumSubscription(long subscriptionId);
#endif

#if ASYNC
Task<GroupForumResponse> GetForumsAsync();
Task<IndividualForumResponse> GetForumByIdAsync(long forumId);
Task<GroupForumResponse> GetForumsByCategoryAsync(long categoryId);
Task<IndividualForumResponse> CreateForumAsync(Forum forum);
Task<IndividualForumResponse> UpdateForumAsync(Forum forum);
Task<bool> DeleteForumAsync(long id);
Task<GroupForumSubcriptionResponse> GetForumSubscriptionsAsync();
Task<GroupForumSubcriptionResponse> GetForumSubscriptionsByForumIdAsync(long forumId);
Task<IndividualForumSubcriptionResponse> GetForumSubscriptionsByIdAsync(long subscriptionId);
Task<IndividualForumSubcriptionResponse> CreateForumSubscriptionAsync(ForumSubscription forumSubscription);
Task<bool> DeleteForumSubscriptionAsync(long subscriptionId);
#endif
}

public class Forums : Core, IForums
{
public Forums(string yourZendeskUrl, string user, string password, string apiToken)
: base(yourZendeskUrl, user, password, apiToken)
{
Expand Down
61 changes: 59 additions & 2 deletions ZendeskApi_v2/Requests/Groups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,65 @@

namespace ZendeskApi_v2.Requests
{
public class Groups : Core
{
public interface IGroups : ICore
{
#if SYNC
MultipleGroupResponse GetGroups();
MultipleGroupResponse GetAssignableGroups();
IndividualGroupResponse GetGroupById(long id);
IndividualGroupResponse CreateGroup(string groupName);
IndividualGroupResponse UpdateGroup(Group group);
bool DeleteGroup(long id);
MultipleGroupMembershipResponse GetGroupMemberships();
MultipleGroupMembershipResponse GetGroupMembershipsByUser(long userId);
MultipleGroupMembershipResponse GetGroupMembershipsByGroup(long groupId);
MultipleGroupMembershipResponse GetAssignableGroupMemberships();
MultipleGroupMembershipResponse GetAssignableGroupMembershipsByGroup(long groupId);
IndividualGroupMembershipResponse GetGroupMembershipsByMembershipId(long groupMembershipId);
IndividualGroupMembershipResponse GetGroupMembershipsByUserAndMembershipId(long userId, long groupMembershipId);

/// <summary>
/// Creating a membership means assigning an agent to a given group
/// </summary>
/// <param name="groupMembership"></param>
/// <returns></returns>
IndividualGroupMembershipResponse CreateGroupMembership(GroupMembership groupMembership);

MultipleGroupMembershipResponse SetGroupMembershipAsDefault(long userId, long groupMembershipId);
bool DeleteGroupMembership(long groupMembershipId);
bool DeleteUserGroupMembership(long userId, long groupMembershipId);
#endif

#if ASYNC
Task<MultipleGroupResponse> GetGroupsAsync();
Task<MultipleGroupResponse> GetAssignableGroupsAsync();
Task<IndividualGroupResponse> GetGroupByIdAsync(long id);
Task<IndividualGroupResponse> CreateGroupAsync(string groupName);
Task<IndividualGroupResponse> UpdateGroupAsync(Group group);
Task<bool> DeleteGroupAsync(long id);
Task<MultipleGroupMembershipResponse> GetGroupMembershipsAsync();
Task<MultipleGroupMembershipResponse> GetGroupMembershipsByUserAsync(long userId);
Task<MultipleGroupMembershipResponse> GetGroupMembershipsByGroupAsync(long groupId);
Task<MultipleGroupMembershipResponse> GetAssignableGroupMembershipsAsync();
Task<MultipleGroupMembershipResponse> GetAssignableGroupMembershipsByGroupAsync(long groupId);
Task<IndividualGroupMembershipResponse> GetGroupMembershipsByMembershipIdAsync(long groupMembershipId);
Task<IndividualGroupMembershipResponse> GetGroupMembershipsByUserAndMembershipIdAsync(long userId, long groupMembershipId);

/// <summary>
/// Creating a membership means assigning an agent to a given group
/// </summary>
/// <param name="groupMembership"></param>
/// <returns></returns>
Task<IndividualGroupMembershipResponse> CreateGroupMembershipAsync(GroupMembership groupMembership);

Task<MultipleGroupMembershipResponse> SetGroupMembershipAsDefaultAsync(long userId, long groupMembershipId);
Task<bool> DeleteGroupMembershipAsync(long groupMembershipId);
Task<bool> DeleteUserGroupMembershipAsync(long userId, long groupMembershipId);
#endif
}

public class Groups : Core, IGroups
{
public Groups(string yourZendeskUrl, string user, string password, string apiToken)
: base(yourZendeskUrl, user, password, apiToken)
{
Expand Down
15 changes: 13 additions & 2 deletions ZendeskApi_v2/Requests/JobStatuses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@

namespace ZendeskApi_v2.Requests
{
public class JobStatuses : Core
{
public interface IJobStatuses : ICore
{
#if SYNC
JobStatusResponse GetJobStatus(string id);
#endif

#if ASYNC
Task<JobStatusResponse> GetJobStatusAsync(string id);
#endif
}

public class JobStatuses : Core, IJobStatuses
{

public JobStatuses(string yourZendeskUrl, string user, string password, string apiToken)
: base(yourZendeskUrl, user, password, apiToken)
Expand Down
59 changes: 57 additions & 2 deletions ZendeskApi_v2/Requests/Locales.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,63 @@

namespace ZendeskApi_v2.Requests
{
public class Locales : Core
{
public interface ILocales : ICore
{
#if SYNC
/// <summary>
/// This lists the translation locales that are available for the account.
/// </summary>
/// <returns></returns>
GroupLocaleResponse GetAllLocales();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
GroupLocaleResponse GetLocalesForAgents();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
IndividualLocaleResponse GetLocaleById(long id);

/// <summary>
/// This works exactly like show, but instead of taking an id as argument, it renders the locale of the user performing the request.
/// </summary>
/// <returns></returns>
IndividualLocaleResponse GetCurrentLocale();
#endif

#if ASYNC
/// <summary>
/// This lists the translation locales that are available for the account.
/// </summary>
/// <returns></returns>
Task<GroupLocaleResponse> GetAllLocalesAsync();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
Task<GroupLocaleResponse> GetLocalesForAgentsAsync();

/// <summary>
/// This lists the translation locales that have been localized for agents.
/// </summary>
/// <returns></returns>
Task<IndividualLocaleResponse> GetLocaleByIdAsync(long id);

/// <summary>
/// This works exactly like show, but instead of taking an id as argument, it renders the locale of the user performing the request.
/// </summary>
/// <returns></returns>
Task<IndividualLocaleResponse> GetCurrentLocaleAsync();
#endif
}

public class Locales : Core, ILocales
{

public Locales(string yourZendeskUrl, string user, string password, string apiToken)
: base(yourZendeskUrl, user, password, apiToken)
Expand Down
Loading

0 comments on commit 536d368

Please sign in to comment.