Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#nullable enable

namespace Ideogram
{
public partial interface IManageClient
{
/// <summary>
/// Add credits to an API user's account.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::Ideogram.ApiException"></exception>
global::System.Threading.Tasks.Task<global::Ideogram.PostAddCreditsResponse> PostAddCreditsForApiAsync(
global::Ideogram.PostAddCreditsRequest request,
global::System.Threading.CancellationToken cancellationToken = default);

/// <summary>
/// Add credits to an API user's account.
/// </summary>
/// <param name="amount">
/// Represents a price.
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
global::System.Threading.Tasks.Task<global::Ideogram.PostAddCreditsResponse> PostAddCreditsForApiAsync(
global::Ideogram.Price amount,
global::System.Threading.CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@

#nullable enable

namespace Ideogram
{
public partial class ManageClient
{
partial void PreparePostAddCreditsForApiArguments(
global::System.Net.Http.HttpClient httpClient,
global::Ideogram.PostAddCreditsRequest request);
partial void PreparePostAddCreditsForApiRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
global::Ideogram.PostAddCreditsRequest request);
partial void ProcessPostAddCreditsForApiResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

partial void ProcessPostAddCreditsForApiResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);

/// <summary>
/// Add credits to an API user's account.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::Ideogram.ApiException"></exception>
public async global::System.Threading.Tasks.Task<global::Ideogram.PostAddCreditsResponse> PostAddCreditsForApiAsync(
global::Ideogram.PostAddCreditsRequest request,
global::System.Threading.CancellationToken cancellationToken = default)
{
request = request ?? throw new global::System.ArgumentNullException(nameof(request));

PrepareArguments(
client: HttpClient);
PreparePostAddCreditsForApiArguments(
httpClient: HttpClient,
request: request);

var __pathBuilder = new PathBuilder(
path: "/manage/api/add_credits",
baseUri: HttpClient.BaseAddress);
var __path = __pathBuilder.ToString();
using var __httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute));
#if NET6_0_OR_GREATER
__httpRequest.Version = global::System.Net.HttpVersion.Version11;
__httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher;
#endif

foreach (var __authorization in Authorizations)
{
if (__authorization.Type == "Http" ||
__authorization.Type == "OAuth2")
{
__httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue(
scheme: __authorization.Name,
parameter: __authorization.Value);
}
else if (__authorization.Type == "ApiKey" &&
__authorization.Location == "Header")
{
__httpRequest.Headers.Add(__authorization.Name, __authorization.Value);
}
}
var __httpRequestContentBody = request.ToJson(JsonSerializerContext);
var __httpRequestContent = new global::System.Net.Http.StringContent(
content: __httpRequestContentBody,
encoding: global::System.Text.Encoding.UTF8,
mediaType: "application/json");
__httpRequest.Content = __httpRequestContent;

PrepareRequest(
client: HttpClient,
request: __httpRequest);
PreparePostAddCreditsForApiRequest(
httpClient: HttpClient,
httpRequestMessage: __httpRequest,
request: request);

using var __response = await HttpClient.SendAsync(
request: __httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

ProcessResponse(
client: HttpClient,
response: __response);
ProcessPostAddCreditsForApiResponse(
httpClient: HttpClient,
httpResponseMessage: __response);
// Bad request
if ((int)__response.StatusCode == 400)
{
string? __content_400 = null;
global::Ideogram.PostAddCreditsError? __value_400 = null;
if (ReadResponseAsString)
{
__content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
__value_400 = global::Ideogram.PostAddCreditsError.FromJson(__content_400, JsonSerializerContext);
}
else
{
var __contentStream_400 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
__value_400 = await global::Ideogram.PostAddCreditsError.FromJsonStreamAsync(__contentStream_400, JsonSerializerContext).ConfigureAwait(false);
}

throw new global::Ideogram.ApiException<global::Ideogram.PostAddCreditsError>(
message: __content_400 ?? __response.ReasonPhrase ?? string.Empty,
statusCode: __response.StatusCode)
{
ResponseBody = __content_400,
ResponseObject = __value_400,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
//
if ((int)__response.StatusCode == 401)
{
string? __content_401 = null;
if (ReadResponseAsString)
{
__content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
else
{
var __contentStream_401 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
}

throw new global::Ideogram.ApiException(
message: __content_401 ?? __response.ReasonPhrase ?? string.Empty,
statusCode: __response.StatusCode)
{
ResponseBody = __content_401,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
//
if ((int)__response.StatusCode == 403)
{
string? __content_403 = null;
if (ReadResponseAsString)
{
__content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
}
else
{
var __contentStream_403 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
}

throw new global::Ideogram.ApiException(
message: __content_403 ?? __response.ReasonPhrase ?? string.Empty,
statusCode: __response.StatusCode)
{
ResponseBody = __content_403,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

if (ReadResponseAsString)
{
var __content = await __response.Content.ReadAsStringAsync(
#if NET5_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

ProcessResponseContent(
client: HttpClient,
response: __response,
content: ref __content);
ProcessPostAddCreditsForApiResponseContent(
httpClient: HttpClient,
httpResponseMessage: __response,
content: ref __content);

try
{
__response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException __ex)
{
throw new global::Ideogram.ApiException(
message: __content ?? __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseBody = __content,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

return
global::Ideogram.PostAddCreditsResponse.FromJson(__content, JsonSerializerContext) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
else
{
try
{
__response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException __ex)
{
throw new global::Ideogram.ApiException(
message: __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

return
await global::Ideogram.PostAddCreditsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ??
throw new global::System.InvalidOperationException("Response deserialization failed.");
}
}

/// <summary>
/// Add credits to an API user's account.
/// </summary>
/// <param name="amount">
/// Represents a price.
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::Ideogram.PostAddCreditsResponse> PostAddCreditsForApiAsync(
global::Ideogram.Price amount,
global::System.Threading.CancellationToken cancellationToken = default)
{
var __request = new global::Ideogram.PostAddCreditsRequest
{
Amount = amount,
};

return await PostAddCreditsForApiAsync(
request: __request,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#nullable enable

namespace Ideogram
{
public sealed partial class PostAddCreditsError
{
/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerContext.
/// </summary>
public string ToJson(
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return global::System.Text.Json.JsonSerializer.Serialize(
this,
this.GetType(),
jsonSerializerContext);
}

/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public string ToJson(
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.Serialize(
this,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerContext.
/// </summary>
public static global::Ideogram.PostAddCreditsError? FromJson(
string json,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return global::System.Text.Json.JsonSerializer.Deserialize(
json,
typeof(global::Ideogram.PostAddCreditsError),
jsonSerializerContext) as global::Ideogram.PostAddCreditsError;
}

/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::Ideogram.PostAddCreditsError? FromJson(
string json,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.Deserialize<global::Ideogram.PostAddCreditsError>(
json,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerContext.
/// </summary>
public static async global::System.Threading.Tasks.ValueTask<global::Ideogram.PostAddCreditsError?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return (await global::System.Text.Json.JsonSerializer.DeserializeAsync(
jsonStream,
typeof(global::Ideogram.PostAddCreditsError),
jsonSerializerContext).ConfigureAwait(false)) as global::Ideogram.PostAddCreditsError;
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::System.Threading.Tasks.ValueTask<global::Ideogram.PostAddCreditsError?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::Ideogram.PostAddCreditsError?>(
jsonStream,
jsonSerializerOptions);
}
}
}
Loading
Loading