Skip to content
Open
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
3 changes: 3 additions & 0 deletions GatherContent.Net/GatherContent.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PageContentElements.cs" />
<Compile Include="PageContent.cs" />
<Compile Include="PageItem.cs" />
<Compile Include="GatherContentClient.cs" />
<Compile Include="Field.cs" />
<Compile Include="File.cs" />
Expand Down
23 changes: 20 additions & 3 deletions GatherContent.Net/GatherContentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GatherContentClient
private readonly string _apiKey;
private readonly string _version;

public GatherContentClient(string accountName, string apiKey, string version = "0.2.1")
public GatherContentClient(string accountName, string apiKey, string version = "0.4")
{
_accountName = accountName;
_apiKey = apiKey;
Expand All @@ -32,14 +32,32 @@ public async Task<ProjectData> GetProjectsAsync()
return await PostAsync<ProjectData>("get_projects");
}

public PageItem GetPage(string pageID) {
return GetPageAsync(pageID).Result;
}

public async Task<PageItem> GetPageAsync(string pageID) {
var result = await PostAsync<PageItem>("get_page", new[] { new KeyValuePair<string, string>("id", pageID) });
if (result.page != null) {
result.page.SetContents();
}
return result;
}

public PageData GetPagesByProject(string projectId)
{
return GetPagesByProjectAsync(projectId).Result;
}

public async Task<PageData> GetPagesByProjectAsync(string projectId)
{
return await PostAsync<PageData>("get_pages_by_project", new[] { new KeyValuePair<string, string>("id", projectId) });
var result = await PostAsync<PageData>("get_pages_by_project", new[] { new KeyValuePair<string, string>("id", projectId) });
if (result.pages != null) {
foreach (var page in result.pages) {
page.SetContents();
}
}
return result;
}

public FileData GetFilesByProject(string projectId)
Expand Down Expand Up @@ -91,6 +109,5 @@ private async Task<T> PostAsync<T>(string requestUri, IEnumerable<KeyValuePair<s
}
}


}
}
37 changes: 36 additions & 1 deletion GatherContent.Net/Page.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
namespace GatherContent.Net
using System;
using System.Text;
using Newtonsoft.Json;

namespace GatherContent.Net
{
public class Page
{
public string id { get; set; }
public string project_id { get; set; }
public string name { get; set; }
public string parent_id { get; set; }
public string type { get; set; }
public string due_date { get; set; }
public string template_id { get; set; }
public string repeatable { get; set; }
public string repeatable_page_id { get; set; }
public string position { get; set; }
Expand All @@ -15,5 +22,33 @@ public class Page
public object custom_field_values { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
/// <summary>
/// Base64 page contents
/// </summary>
public string config { get; set; }
/// <summary>
/// Page content
/// </summary>
public PageContent[] contents { get; set; }
/// <summary>
/// Exception when calling <see cref="SetContents()"/>
/// </summary>
public Exception contentsException { get; set; }

/// <summary>
/// Populates <see cref="contents"/> by converted the <see cref="config"/> Base64 content.
/// </summary>
public void SetContents() {
if (string.IsNullOrWhiteSpace(this.config)) {
this.contents = new PageContent[0];
}
try {
var configData = Convert.FromBase64String(this.config);
var configJson = Encoding.UTF8.GetString(configData);
this.contents = JsonConvert.DeserializeObject<PageContent[]>(configJson);
} catch (Exception ex) {
this.contentsException = ex;
}
}
}
}
23 changes: 23 additions & 0 deletions GatherContent.Net/PageContent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace GatherContent.Net {
/// <summary>
/// Content tab.
/// </summary>
public class PageContent {
/// <summary>
/// Label for the content tab. Defaults to "Content".
/// </summary>
public string label { get; set; }
/// <summary>
/// Internal tab identifier.
/// </summary>
public string name { get; set; }
/// <summary>
///
/// </summary>
public bool hidden { get; set; }
/// <summary>
/// Elements containing HTML or text that makeup this tab.
/// </summary>
public PageContentElement[] elements { get; set; }
}
}
43 changes: 43 additions & 0 deletions GatherContent.Net/PageContentElements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace GatherContent.Net {
/// <summary>
/// Text elements within a content tab.
/// </summary>
public class PageContentElement {
/// <summary>
/// Element type, such as "text".
/// </summary>
public string type { get; set; }
/// <summary>
/// Internal element identifier.
/// </summary>
public string name { get; set; }
/// <summary>
///
/// </summary>
public bool required { get; set; }
/// <summary>
/// User declared content label.
/// </summary>
public string label { get; set; }
/// <summary>
/// Content HTML or text.
/// </summary>
public string value { get; set; }
/// <summary>
///
/// </summary>
public string microcopy { get; set; }
/// <summary>
/// How the content is limited, such as "words".
/// </summary>
public string limit_type { get; set; }
/// <summary>
/// Numeric limit of the content. Defaults to "0".
/// </summary>
public string limit { get; set; }
/// <summary>
/// True if <see cref="value"/> does not contain HTML.
/// </summary>
public bool plain_text { get; set; }
}
}
6 changes: 6 additions & 0 deletions GatherContent.Net/PageItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace GatherContent.Net {
public class PageItem {
public bool success { get; set; }
public Page page { get; set; }
}
}
5 changes: 2 additions & 3 deletions GatherContent.Net/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -32,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.3.0.0")]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Currently you can:
<dd>Get a list of projects for your API Key</dd>
<dt>Pages</dt>
<dd>Get the pages for a given project</dd>
<dt>Page</dt>
<dd>Get a single page</dd>
<dt>Files</dt>
<dd>Get the files for a given project and download them</dd>
</dl>
Expand Down