Skip to content

Adding Support for External Content API #598

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
36 changes: 36 additions & 0 deletions src/ZendeskApi_v2/FederatedSearchApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using ZendeskApi_v2.Requests.FederatedSearch;

namespace ZendeskApi_v2.FederatedSearch
{
public interface IFederatedSearchApi
{
IExternalContentRecords ExternalContentRecords { get; }
IExternalContentSources ExternalContentSources { get; }
IExternalContentTypes ExternalContentTypes { get; }
string Locale { get; }
}

public class FederatedSearchApi : IFederatedSearchApi
{
public FederatedSearchApi(
string yourZendeskUrl,
string user,
string password,
string apiToken,
string locale,
string p_OAuthToken,
Dictionary<string, string> customHeaders)
{
ExternalContentRecords = new ExternalContentRecords(yourZendeskUrl, user, password, apiToken, locale, p_OAuthToken, customHeaders);
ExternalContentSources = new ExternalContentSources(yourZendeskUrl, user, password, apiToken, locale, p_OAuthToken, customHeaders);
ExternalContentTypes = new ExternalContentTypes(yourZendeskUrl, user, password, apiToken, locale, p_OAuthToken, customHeaders);
Locale = locale;
}

public IExternalContentRecords ExternalContentRecords { get; }
public IExternalContentSources ExternalContentSources { get; }
public IExternalContentTypes ExternalContentTypes { get; }
public string Locale { get; }
}
}
31 changes: 31 additions & 0 deletions src/ZendeskApi_v2/Models/FederatedSearch/ExternalContentBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using ZendeskApi_v2.Extensions;
using ZendeskApi_v2.Models.FederatedSearch;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public interface IExternalContentBase
{
string Id { get; set; }
DateTimeOffset? CreatedAt { get; set; }

DateTimeOffset? UpdatedAt { get; set; }
}

public class ExternalContentBase : IExternalContentBase
{
[JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)]
public string Id { get; set; }

[JsonProperty("created_at", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTimeOffset? CreatedAt { get; set; }

[JsonProperty("updated_at", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTimeOffset? UpdatedAt { get; set; }
}
}
80 changes: 80 additions & 0 deletions src/ZendeskApi_v2/Models/FederatedSearch/ExternalContentRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using ZendeskApi_v2.Models.HelpCenter.Translations;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public class ExternalContentRecord
{
[JsonProperty("id")]
public string Id { get; set; }

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

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

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

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

[JsonProperty("external_id")]
public string ExternalId { get; set; }

[JsonProperty("user_segment_id", NullValueHandling = NullValueHandling.Include,
DefaultValueHandling = DefaultValueHandling.Include )]
public string UserSegmentId { get; set; }

[JsonProperty("source")]
public ExternalContentSource Source { get; set; }

[JsonProperty("type")]
public ExternalContentType Type { get; set; }

[JsonProperty("created_at", NullValueHandling = NullValueHandling.Include)]
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTimeOffset CreatedAt { get; set; }

[JsonProperty("updated_at", NullValueHandling = NullValueHandling.Include)]
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTimeOffset UpdatedAt { get; set; }
}
//New class for create/update operations since the Source/Type structures are only required for GET operations
public class CreateUpdateExternalContentRecord
{
[JsonProperty("title")]
public string Title { get; set; }

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

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

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

[JsonProperty("external_id")]
public string ExternalId { get; set; }

[JsonProperty("user_segment_id", NullValueHandling = NullValueHandling.Include,
DefaultValueHandling = DefaultValueHandling.Include )]
public string UserSegmentId { get; set; }

[JsonProperty("source_id")]
public string SourceId { get; set; }

[JsonProperty("type_id")]
public string TypeId { get; set; }
}

public class ExternalContentRecordRequest {
[JsonProperty("record")]
public CreateUpdateExternalContentRecord Record { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/ZendeskApi_v2/Models/FederatedSearch/ExternalContentSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Newtonsoft.Json;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public class ExternalContentSource : ExternalContentBase
{
[JsonProperty("name")]
public string Name { get; set; }
}

public class ExternalContentSourceRequest {
[JsonProperty("source")]
public ExternalContentSource Source { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/ZendeskApi_v2/Models/FederatedSearch/ExternalContentType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Newtonsoft.Json;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public class ExternalContentType : ExternalContentBase
{
[JsonProperty("name")]
public string Name { get; set; }
}

public class ExternalContentTypeRequest {
[JsonProperty("type")]
public ExternalContentType Type { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using ZendeskApi_v2.Models.FederatedSearch;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public class GroupExternalContentRecordsResponse : GroupExternalContentResponseBase
{
[JsonProperty("records")]
public IList<ExternalContentRecord> Records { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using ZendeskApi_v2.Extensions;
using ZendeskApi_v2.Models.FederatedSearch;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public interface IGroupExternalContentResponseBase
{
GroupExternalContentResponseMeta Meta {get;set;}
}

public interface IExternalContentMetaResponseBase
{
[JsonProperty("has_more")]
bool HasMore {get;set;}
[JsonProperty("after_cursor")]
string AfterCursor{ get; set;}
[JsonProperty("before_cursor")]
string BeforeCursor {get; set;}
}

public class GroupExternalContentResponseBase : IGroupExternalContentResponseBase
{
[JsonProperty("meta")]
public GroupExternalContentResponseMeta Meta {get;set;}
}

public class GroupExternalContentResponseMeta : IExternalContentMetaResponseBase
{
[JsonProperty("has_more")]
public bool HasMore { get ; set ; }
[JsonProperty("after_cursor")]
public string AfterCursor { get; set; }
[JsonProperty("before_cursor")]
public string BeforeCursor { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using ZendeskApi_v2.Models.FederatedSearch;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public class GroupExternalContentSourcesResponse : GroupExternalContentResponseBase
{
[JsonProperty("Sources")]
public IList<ExternalContentSource> Sources { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using ZendeskApi_v2.Models.FederatedSearch;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public class GroupExternalContentTypesResponse : GroupExternalContentResponseBase
{
[JsonProperty("types")]
public IList<ExternalContentType> Types { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using ZendeskApi_v2.Models.FederatedSearch;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public class IndividualExternalContentRecordResponse
{
[JsonProperty("record")]
public ExternalContentRecord Record { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using ZendeskApi_v2.Models.FederatedSearch;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public class IndividualExternalContentSourceResponse
{
[JsonProperty("source")]
public ExternalContentSource Source { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using ZendeskApi_v2.Models.FederatedSearch;

namespace ZendeskApi_v2.Models.FederatedSearch
{
public class IndividualExternalContentTypeResponse
{
[JsonProperty("type")]
public ExternalContentType Type { get; set; }
}
}
Loading
Loading