예제 #1
0
 /// <summary>
 /// Retrieve all templates.
 /// </summary>
 /// <param name="type">The type of template.</param>
 /// <param name="onBehalfOf">The user to impersonate.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>
 /// An array of <see cref="Template" />.
 /// </returns>
 public Task <Template[]> GetAllAsync(TemplateType type, string onBehalfOf = null, CancellationToken cancellationToken = default)
 {
     return(_client
            .GetAsync(_endpoint)
            .WithArgument("generations", type.ToEnumString())
            .OnBehalfOf(onBehalfOf)
            .WithCancellationToken(cancellationToken)
            .AsObject <Template[]>("templates"));
 }
예제 #2
0
        /// <summary>
        /// Create a template.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="type">The type of template.</param>
        /// <param name="onBehalfOf">The user to impersonate.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The <see cref="Template" />.
        /// </returns>
        public Task <Template> CreateAsync(string name, TemplateType type, string onBehalfOf = null, CancellationToken cancellationToken = default)
        {
            var data = new StrongGridJsonObject();

            data.AddProperty("name", name);
            data.AddProperty("generation", type.ToEnumString());

            return(_client
                   .PostAsync(_endpoint)
                   .OnBehalfOf(onBehalfOf)
                   .WithJsonBody(data)
                   .WithCancellationToken(cancellationToken)
                   .AsObject <Template>());
        }