-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/sdk 5045 forms support (#760)
- Loading branch information
Showing
26 changed files
with
581 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Auth0.ManagementApi.Models.Forms; | ||
using Auth0.ManagementApi.Paging; | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Clients | ||
{ | ||
public class FormsClient : BaseClient, IFormsClient | ||
{ | ||
private readonly JsonConverter[] formsConverters = { new PagedListConverter<FormBase>("forms") }; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="FormsClient"/>. | ||
/// </summary> | ||
/// <param name="connection"><see cref="IManagementConnection"/> used to make all API calls.</param> | ||
/// <param name="baseUri"><see cref="Uri"/> of the endpoint to use in making API calls.</param> | ||
/// <param name="defaultHeaders">Dictionary containing default headers included with every request this client makes.</param> | ||
public FormsClient(IManagementConnection connection, Uri baseUri, IDictionary<string, string> defaultHeaders) : base(connection, baseUri, defaultHeaders) | ||
{ | ||
|
||
} | ||
|
||
/// <inheritdoc /> | ||
public Task<IPagedList<FormBase>> GetAllAsync(FormsGetRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
if (request == null) | ||
throw new ArgumentNullException(nameof(request)); | ||
|
||
var queryStrings = new Dictionary<string, string>(); | ||
|
||
if (request.Hydrate != null && request.Hydrate.Any()) | ||
{ | ||
var hydrateValues = string.Join(",", request.Hydrate.Select( x => x.ToString().ToLower())); | ||
queryStrings["hydrate"] = hydrateValues; | ||
} | ||
|
||
if (request.PaginationInfo != null) | ||
{ | ||
queryStrings["page"] = request.PaginationInfo.PageNo.ToString(); | ||
queryStrings["per_page"] = request.PaginationInfo.PerPage.ToString(); | ||
queryStrings["include_totals"] = request.PaginationInfo.IncludeTotals.ToString().ToLower(); | ||
} | ||
|
||
return Connection.GetAsync<IPagedList<FormBase>>(BuildUri("forms", queryStrings), DefaultHeaders, formsConverters, cancellationToken); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Task<Form> GetAsync(FormsGetRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
if (request == null) | ||
throw new ArgumentNullException(nameof(request)); | ||
var queryStrings = new Dictionary<string, string>(); | ||
|
||
if (request.Hydrate != null && request.Hydrate.Any()) | ||
{ | ||
var hydrateValues = string.Join(",", request.Hydrate.Select( x => x.ToString().ToLower())); | ||
queryStrings["hydrate"] = hydrateValues; | ||
} | ||
|
||
return Connection.GetAsync<Form>(BuildUri($"forms/{EncodePath(request.Id)}", queryStrings), DefaultHeaders, null, cancellationToken); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Task<Form> CreateAsync(FormCreateRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
return Connection.SendAsync<Form>(HttpMethod.Post, BuildUri("forms"), request, DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Task<Form> UpdateAsync(string id, FormUpdateRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
if (string.IsNullOrEmpty(id)) | ||
{ | ||
throw new ArgumentNullException(nameof(id)); | ||
} | ||
return Connection.SendAsync<Form>(new HttpMethod("PATCH"), BuildUri($"forms/{EncodePath(id)}"), request, DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public Task DeleteAsync(string id, CancellationToken cancellationToken = default) | ||
{ | ||
if (string.IsNullOrEmpty(id)) | ||
{ | ||
throw new ArgumentNullException(nameof(id)); | ||
} | ||
return Connection.SendAsync<object>(HttpMethod.Delete, BuildUri($"forms/{EncodePath(id)}"), null, DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Auth0.ManagementApi.Models.Forms; | ||
using Auth0.ManagementApi.Paging; | ||
|
||
namespace Auth0.ManagementApi.Clients | ||
{ | ||
public interface IFormsClient | ||
{ | ||
/// <summary> | ||
/// Get all Forms | ||
/// </summary> | ||
/// <param name="request"><see cref="FormsGetRequest"/></param> | ||
/// <param name="cancellationToken"><see cref="CancellationToken"/></param> | ||
/// <returns>All available <see cref="Form" />s.</returns> | ||
Task<IPagedList<FormBase>> GetAllAsync(FormsGetRequest request, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Get A form. | ||
/// </summary> | ||
/// <param name="request"><see cref="FormsGetRequest"/></param> | ||
/// <param name="cancellationToken"><see cref="CancellationToken"/></param> | ||
/// <returns>All available <see cref="Form" />s.</returns> | ||
Task<Form> GetAsync(FormsGetRequest request, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Create a form. | ||
/// </summary> | ||
/// <param name="request"><see cref="FormCreateRequest"/></param> | ||
/// <param name="cancellationToken"><see cref="CancellationToken"/></param> | ||
/// <returns></returns> | ||
Task<Form> CreateAsync(FormCreateRequest request, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Update a form. | ||
/// </summary> | ||
/// <param name="id">ID of the form to be updated</param> | ||
/// <param name="request"><see cref="FormUpdateRequest"/></param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
Task<Form> UpdateAsync(string id, FormUpdateRequest request, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Delete a form. | ||
/// </summary> | ||
/// <param name="id">ID of the form to be deleted</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
Task DeleteAsync(string id, CancellationToken cancellationToken = default); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
public class AfterSubmit | ||
{ | ||
[JsonProperty("flow_id")] | ||
public string FlowId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
public class Coordinates | ||
{ | ||
[JsonProperty("x")] | ||
public int X { get; set; } | ||
|
||
[JsonProperty("y")] | ||
public int Y { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
public class Ending | ||
{ | ||
[JsonProperty("redirection")] | ||
public Redirection Redirection { get; set; } | ||
|
||
[JsonProperty("after_submit")] | ||
public AfterSubmit AfterSubmit { get; set; } | ||
|
||
[JsonProperty("coordinates")] | ||
public Coordinates Coordinates { get; set; } | ||
|
||
[JsonProperty("resume_flow")] | ||
public bool? ResumeFlow { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Auth0.ManagementApi.Models.Forms; | ||
|
||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
/// <summary> | ||
/// Represents a Form | ||
/// </summary> | ||
public class Form : FormBase | ||
{ | ||
[JsonProperty("messages")] | ||
public Messages Messages { get; set; } | ||
|
||
[JsonProperty("languages")] | ||
public Languages Languages { get; set; } | ||
|
||
[JsonProperty("translations")] | ||
public dynamic Translations { get; set; } | ||
|
||
[JsonProperty("nodes")] | ||
public Node[] Nodes { get; set; } | ||
|
||
[JsonProperty("start")] | ||
public Start Start { get; set; } | ||
|
||
[JsonProperty("ending")] | ||
public Ending Ending { get; set; } | ||
|
||
[JsonProperty("style")] | ||
public Style Style { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
public class FormBase | ||
{ | ||
[JsonProperty("id")] | ||
public string Id { get; set; } | ||
|
||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonProperty("created_at")] | ||
public DateTime CreatedAt { get; set; } | ||
|
||
[JsonProperty("updated_at")] | ||
public DateTime UpdatedAt { get; set; } | ||
|
||
[JsonProperty("embedded_at")] | ||
public DateTime EmbeddedAt { get; set; } | ||
|
||
[JsonProperty("submitted_at")] | ||
public DateTime SubmittedAt { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
/// <summary> | ||
/// Contains information required to create a new form. | ||
/// </summary> | ||
public class FormCreateRequest | ||
{ | ||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonProperty("messages")] | ||
public Messages Messages { get; set; } | ||
|
||
[JsonProperty("languages")] | ||
public Languages Languages { get; set; } | ||
|
||
[JsonProperty("translations")] | ||
public dynamic Translations { get; set; } | ||
|
||
[JsonProperty("nodes")] | ||
public Node[] Nodes { get; set; } | ||
|
||
[JsonProperty("start")] | ||
public Start Start { get; set; } | ||
|
||
[JsonProperty("ending")] | ||
public Ending Ending { get; set; } | ||
|
||
[JsonProperty("style")] | ||
public Style Style { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
public class FormUpdateRequest : FormCreateRequest | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Specialized; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
using Auth0.ManagementApi.Paging; | ||
|
||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
public class FormsGetRequest | ||
{ | ||
public PaginationInfo PaginationInfo { get; set; } | ||
|
||
/// <summary> | ||
/// Hydration parameter | ||
/// </summary> | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public Hydrate[] Hydrate { get; set; } | ||
|
||
/// <summary> | ||
/// Form Identifier | ||
/// </summary> | ||
public string Id { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
public class HiddenFields | ||
{ | ||
[JsonProperty("key")] | ||
public string Key { get; set; } | ||
|
||
[JsonProperty("value")] | ||
public string Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Auth0.ManagementApi.Models.Forms | ||
{ | ||
public enum Hydrate | ||
{ | ||
[EnumMember(Value = "flow_count")] | ||
FLOW_COUNT, | ||
|
||
[EnumMember(Value = "links")] | ||
LINKS | ||
} | ||
} |
Oops, something went wrong.