Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Help Center API support #107

Merged
merged 10 commits into from
Oct 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Tests/HelpCenter/ArticleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using NUnit.Framework;
using ZendeskApi_v2;
using ZendeskApi_v2.Models.Articles;

namespace Tests.HelpCenter
{
[TestFixture]
public class ArticleTests
{
private ZendeskApi api = new ZendeskApi(Settings.Site, Settings.Email, Settings.Password);

[Test]
public void CanGetArticles()
{
var res = api.HelpCenter.Articles.GetArticles();
Assert.Greater(res.Count, 0);

var resSections = api.HelpCenter.Sections.GetSections();
var res1 = api.HelpCenter.Articles.GetArticlesBySectionId(resSections.Sections[0].Id.Value);
Assert.AreEqual(res1.Articles[0].SectionId, resSections.Sections[0].Id);
}

[Test]
public void CanCreateUpdateAndDeleteArticles()
{
var resSections = api.HelpCenter.Sections.GetSections();
var res = api.HelpCenter.Articles.CreateArticle(resSections.Sections[0].Id.Value, new Article()
{
Title = "My Test article",
Body = "The body of my article",
Locale = "en-us"
});
Assert.Greater(res.Arcticle.Id, 0);

res.Arcticle.Body = "updated body";
var update = api.HelpCenter.Articles.UpdateArticle(res.Arcticle);
Assert.AreEqual(update.Arcticle.Body, res.Arcticle.Body);

Assert.True(api.HelpCenter.Articles.DeleteArticle(res.Arcticle.Id.Value));
}

[Test]
public void CanGetArticlesAsync()
{
var res = api.HelpCenter.Articles.GetArticlesAsync().Result;
Assert.Greater(res.Count, 0);

var resSections = api.HelpCenter.Sections.GetSectionsAsync().Result;
var res1 = api.HelpCenter.Articles.GetArticlesBySectionIdAsync(resSections.Sections[0].Id.Value);
Assert.AreEqual(res1.Result.Articles[0].SectionId, resSections.Sections[0].Id);
}

[Test]
public void CanCreateUpdateAndDeleteArticlesAsync()
{
var resSections = api.HelpCenter.Sections.GetSectionsAsync().Result;
var res = api.HelpCenter.Articles.CreateArticleAsync(resSections.Sections[0].Id.Value, new Article()
{
Title = "My Test article",
Body = "The body of my article",
Locale = "en-us"
}).Result;
Assert.Greater(res.Arcticle.Id, 0);

res.Arcticle.Body = "updated body";
var update = api.HelpCenter.Articles.UpdateArticleAsync(res.Arcticle).Result;
Assert.AreEqual(update.Arcticle.Body, res.Arcticle.Body);

Assert.True(api.HelpCenter.Articles.DeleteArticleAsync(res.Arcticle.Id.Value).Result);
}
}
}
38 changes: 38 additions & 0 deletions Tests/HelpCenter/CategoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using NUnit.Framework;
using ZendeskApi_v2;
using ZendeskApi_v2.Models.HelpCenter.Categories;

namespace Tests.HelpCenter
{
[TestFixture]
public class CategoryTests
{
private ZendeskApi api = new ZendeskApi(Settings.Site, Settings.Email, Settings.Password);

[Test]
public void CanGetCategories()
{
var res = api.HelpCenter.Categories.GetCategories();
Assert.Greater(res.Count, 0);

var res1 = api.HelpCenter.Categories.GetCategoryById(res.Categories[0].Id.Value);
Assert.AreEqual(res1.Category.Id, res.Categories[0].Id);
}

[Test]
public void CanCreateUpdateAndDeleteCategories()
{
var res = api.HelpCenter.Categories.CreateCategory(new Category()
{
Name = "My Test category"
});
Assert.Greater(res.Category.Id, 0);

res.Category.Description = "updated description";
var update = api.HelpCenter.Categories.UpdateCategory(res.Category);
Assert.AreEqual(update.Category.Description, res.Category.Description);

Assert.True(api.HelpCenter.Categories.DeleteCategory(res.Category.Id.Value));
}
}
}
2 changes: 2 additions & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="HelpCenter\ArticleTests.cs" />
<Compile Include="AttachmentTests.cs" />
<Compile Include="CategoryTests.cs" />
<Compile Include="CoreTests.cs" />
<Compile Include="CustomRolesTests.cs" />
<Compile Include="ForumTests.cs" />
<Compile Include="GroupTests.cs" />
<Compile Include="HelpCenter\CategoryTests.cs" />
<Compile Include="JobStatusTests.cs" />
<Compile Include="LocaleTests.cs" />
<Compile Include="MacroTests.cs" />
Expand Down
4 changes: 2 additions & 2 deletions ZendeskApi_v2/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected T GenericGet<T>(string resource)
protected bool GenericDelete(string resource)
{
var res = RunRequest(resource, "DELETE");
return res.HttpStatusCode == HttpStatusCode.OK;
return res.HttpStatusCode == HttpStatusCode.OK || res.HttpStatusCode == HttpStatusCode.NoContent;
}

protected T GenericPost<T>(string resource, object body=null)
Expand Down Expand Up @@ -267,7 +267,7 @@ protected async Task<T> GenericGetAsync<T>(string resource)
protected async Task<bool> GenericDeleteAsync(string resource)
{
var res = RunRequestAsync(resource, "DELETE");
return await res.ContinueWith(x => x.Result.HttpStatusCode == HttpStatusCode.OK);
return await res.ContinueWith(x => x.Result.HttpStatusCode == HttpStatusCode.OK || x.Result.HttpStatusCode == HttpStatusCode.NoContent);
}

protected async Task<T> GenericPostAsync<T>(string resource, object body = null)
Expand Down
30 changes: 30 additions & 0 deletions ZendeskApi_v2/HelpCenterApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using ZendeskApi_v2.Requests.HelpCenter;
namespace ZendeskApi_v2.HelpCenter
{
public interface IHelpCenterApi
{
ICategories Categories { get; }
ISections Sections { get; }
IArticles Articles { get; }

string Locale { get; }
}

public class HelpCenterApi : IHelpCenterApi
{
public ICategories Categories { get; set; }
public ISections Sections { get; set; }
public IArticles Articles { get; set; }

public string Locale { get; set; }

public HelpCenterApi(string yourZendeskUrl, string user, string password, string apiToken, string locale)
{
Categories = new Categories(yourZendeskUrl, user, password, apiToken, locale);
Sections = new Sections(yourZendeskUrl, user, password, apiToken);
Articles = new Articles(yourZendeskUrl, user, password, apiToken);

Locale = locale;
}
}
}
47 changes: 47 additions & 0 deletions ZendeskApi_v2/Models/Articles/Article.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Newtonsoft.Json;

namespace ZendeskApi_v2.Models.Articles
{

public class Article
{
[JsonProperty("id")]
public long? Id { get; set; }

[JsonProperty("title")]
public string Title { get; set; }

[JsonProperty("body")]
public string Body { get; set; }

[JsonProperty("locale")]
public string Locale { get; set; }

[JsonProperty("author_id")]
public long? AuthorId { get; set; }

[JsonProperty("comments_disabled")]
public bool CommentsDisabled { get; set; }

[JsonProperty("promoted")]
public bool Promoted { get; set; }

[JsonProperty("position")]
public int Position { get; set; }

[JsonProperty("vote_sum")]
public int VoteSum { get; set; }

[JsonProperty("vote_count")]
public int VoteCount { get; set; }

[JsonProperty("section_id")]
public long? SectionId { get; set; }

[JsonProperty("created_at")]
public string CreatedAt { get; set; }

[JsonProperty("updated_at")]
public string UpdatedAt { get; set; }
}
}
13 changes: 13 additions & 0 deletions ZendeskApi_v2/Models/Articles/GroupArticleResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace ZendeskApi_v2.Models.Articles
{

public class GroupArticleResponse : GroupResponseBase
{

[JsonProperty("articles")]
public IList<Article> Articles { get; set; }
}
}
11 changes: 11 additions & 0 deletions ZendeskApi_v2/Models/Articles/IndividualArticleResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Newtonsoft.Json;

namespace ZendeskApi_v2.Models.Articles
{
public class IndividualArticleResponse
{

[JsonProperty("article")]
public Article Arcticle { get; set; }
}
}
9 changes: 9 additions & 0 deletions ZendeskApi_v2/Models/Constants/Visibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ZendeskApi_v2.Models.Constants
{
public static class Visibility
{
public const string Public = "public";
public const string Restricted = "restricted";
public const string Internet = "internal";
}
}
49 changes: 49 additions & 0 deletions ZendeskApi_v2/Models/HelpCenter/Categories/Category.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Generated by Xamasoft JSON Class Generator
// http://www.xamasoft.com/json-class-generator

using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ZendeskApi_v2.Models.HelpCenter.Categories
{

public class Category
{

[JsonProperty("id")]
public long? Id { get; set; }

[JsonProperty("url")]
public string Url { get; set; }

[JsonProperty("html_url")]
public string HtmlUrl { get; set; }

[JsonProperty("position")]
public int? Position { get; set; }

[JsonProperty("created_at")]
public string CreatedAt { get; set; }

[JsonProperty("updated_at")]
public string UpdatedAt { get; set; }

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

[JsonProperty("description")]
public string Description { get; set; }

[JsonProperty("locale")]
public string Locale { get; set; }

[JsonProperty("source_locale")]
public string SourceLocale { get; set; }

[JsonProperty("outdated")]
public bool Outdated { get; set; }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// JSON C# Class Generator
// http://at-my-window.blogspot.com/?page=json-class-generator

using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ZendeskApi_v2.Models.HelpCenter.Categories
{

public class GroupCategoryResponse : GroupResponseBase
{

[JsonProperty("categories")]
public IList<Category> Categories { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Newtonsoft.Json;

namespace ZendeskApi_v2.Models.HelpCenter.Categories
{
public class IndividualCategoryResponse
{

[JsonProperty("category")]
public Category Category { get; set; }
}
}
15 changes: 15 additions & 0 deletions ZendeskApi_v2/Models/Sections/GroupSectionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ZendeskApi_v2.Models.Sections
{

public class GroupSectionResponse : GroupResponseBase
{

[JsonProperty("sections")]
public IList<Section> Sections { get; set; }
}
}
12 changes: 12 additions & 0 deletions ZendeskApi_v2/Models/Sections/IndividualSectionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;
using ZendeskApi_v2.Models.Categories;

namespace ZendeskApi_v2.Models.Sections
{
public class IndividualSectionResponse
{

[JsonProperty("section")]
public Section Section { get; set; }
}
}
Loading