Skip to content

Commit 5052bcb

Browse files
first commit
1 parent 00d3b04 commit 5052bcb

File tree

6 files changed

+237
-18
lines changed

6 files changed

+237
-18
lines changed

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ ___
5151
- [Video](#Video)
5252
- [Other Features of Version 1](#Other-Features-of-Version-1)
5353
- [Model list](#Model-list)
54+
- [User account](#User account)
55+
- [User balance](#User-balance)
5456
- [Contributing](#contributing)
5557
- [License](#license)
5658

@@ -1174,10 +1176,12 @@ Detailed settings on the [official documentation](https://platform.stability.ai/
11741176

11751177
## Model list
11761178

1179+
List the engines compatible with `Version 1` REST API endpoints.
1180+
11771181
```Pascal
11781182
//uses
11791183
// StabilityAI, StabilityAI.Types, StabilityAI.Common, FMX.Stability.Tutorial,
1180-
// SStabilityAI.Version1.Engines;
1184+
// StabilityAI.Version1.Engines;
11811185
11821186
Stability.Version1.Engines.List(
11831187
function : TAsynEngines
@@ -1193,6 +1197,48 @@ Detailed settings on the [official documentation](https://platform.stability.ai/
11931197

11941198
<br/>
11951199

1200+
## User account
1201+
1202+
Retrieve details about the account linked to the specified API key
1203+
1204+
```Pascal
1205+
//uses
1206+
// StabilityAI, StabilityAI.Types, StabilityAI.Common, FMX.Stability.Tutorial,
1207+
// StabilityAI.Version1.User;
1208+
1209+
Stability.Version1.User.AccountDetails(
1210+
function : TAsynAccountDetails
1211+
begin
1212+
Result.Sender := StabilityResult;
1213+
Result.OnStart := Start;
1214+
Result.OnSuccess := Display;
1215+
Result.OnError := Display;
1216+
end);
1217+
```
1218+
1219+
Detailed settings on the [official documentation](https://platform.stability.ai/docs/api-reference#tag/User/operation/userAccount)
1220+
1221+
<br/>
1222+
1223+
## User balance
1224+
1225+
```Pascal
1226+
//uses
1227+
// StabilityAI, StabilityAI.Types, StabilityAI.Common, FMX.Stability.Tutorial,
1228+
// StabilityAI.Version1.User;
1229+
1230+
var Balance := Stability.Version1.User.AccountBalance;
1231+
try
1232+
Memo1.Lines.Text := Memo1.Text + Balance.Credits.ToString + sLineBreak;
1233+
finally
1234+
Balance.Free;
1235+
end;
1236+
```
1237+
1238+
Detailed settings on the [official documentation](https://platform.stability.ai/docs/api-reference#tag/User/operation/userBalance)
1239+
1240+
<br/>
1241+
11961242
# Contributing
11971243

11981244
Pull requests are welcome. If you're planning to make a major change, please open an issue first to discuss your proposed changes.

source/FMX.Stability.Tutorial.pas

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface
1515
uses
1616
System.SysUtils, System.Classes, System.Types, FMX.Memo, FMX.Objects, FMX.Forms,
1717
StabilityAI.Common, StabilityAI.Version1.SDXL1AndSD1_6, StabilityAI.VideoAnd3D.Stable3D,
18-
StabilityAI.VideoAnd3D.Video, StabilityAI.Version1.Engines;
18+
StabilityAI.VideoAnd3D.Video, StabilityAI.Version1.Engines, StabilityAI.Version1.User;
1919

2020
type
2121
TFMXStabilitySender = class
@@ -40,6 +40,7 @@ TFMXStabilitySender = class
4040
procedure Display(Sender: TObject; Value: TModel3D); overload;
4141
procedure Display(Sender: TObject; Value: TJobVideo); overload;
4242
procedure Display(Sender: TObject; Value: TEngines); overload;
43+
procedure Display(Sender: TObject; Value: TAccountDetails); overload;
4344

4445
var
4546
StabilityResult: TFMXStabilitySender = nil;
@@ -48,7 +49,7 @@ implementation
4849

4950
procedure Start(Sender: TObject);
5051
begin
51-
Display(Sender, 'Request dended. Please wait....');
52+
Display(Sender, 'Request sended. Please wait....');
5253
end;
5354

5455
procedure Display(Sender: TObject; Value: string);
@@ -126,6 +127,20 @@ procedure Display(Sender: TObject; Value: TEngines);
126127
Display(Sender, Item.Name);
127128
end;
128129

130+
procedure Display(Sender: TObject; Value: TAccountDetails);
131+
begin
132+
Display(Sender, Value.Id);
133+
Display(Sender, Value.Email);
134+
Display(Sender, Value.ProfilePicture);
135+
for var Item in Value.Organizations do
136+
begin
137+
Display(Sender, Item.Id);
138+
Display(Sender, Item.Name);
139+
Display(Sender, Item.Role);
140+
Display(Sender, BoolToStr(Item.IsDefault, True));
141+
end;
142+
end;
143+
129144
{ TFMXStabilitySender }
130145

131146
constructor TFMXStabilitySender.Create(const AMemo: TMemo;

source/StabilityAI.Version1.Engines.pas

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ TEngines = class
126126
/// Each object in the array represents an individual engine with its respective metadata.
127127
/// </remarks>
128128
property Result: TArray<TEngine> read FResult write FResult;
129+
destructor Destroy; override;
129130
end;
130131

131132
/// <summary>
@@ -166,7 +167,7 @@ TEnginesRoute = class(TStabilityAIAPIRoute)
166167
/// var Stability := TStabilityAIFactory.CreateInstance(BaererKey);
167168
/// var Data := Stability.Version1.Engines.List;
168169
/// try
169-
/// for var Itel in Data.Result do
170+
/// for var Item in Data.Result do
170171
/// showMesage(Item.Name);
171172
/// finally
172173
/// Data.Free;
@@ -180,9 +181,6 @@ TEnginesRoute = class(TStabilityAIAPIRoute)
180181
/// NOTE: This method is <c>asynchronous</c>
181182
/// </para>
182183
/// </summary>
183-
/// <param name="ParamProc">
184-
/// A procedure used to configure the parameters for the image creation, such as image, the the format of the output image etc.
185-
/// </param>
186184
/// <param name="CallBacks">
187185
/// A function that returns a record containing event handlers for asynchronous image creation, such as <c>onSuccess</c> and <c>onError</c>.
188186
/// </param>
@@ -288,4 +286,13 @@ function TEnginesRoute.List: TEngines;
288286
Result := API.GetArray<TEngines>('v1/engines/list');
289287
end;
290288

289+
{ TEngines }
290+
291+
destructor TEngines.Destroy;
292+
begin
293+
for var Item in FResult do
294+
Item.Free;
295+
inherited;
296+
end;
297+
291298
end.

source/StabilityAI.Version1.User.pas

Lines changed: 144 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,147 @@ TAccountBalance = class
117117
/// </remarks>
118118
TAsynAccountBalance = TAsynCallBack<TAccountBalance>;
119119

120+
/// <summary>
121+
/// Provides methods to interact with user-related endpoints of the StabilityAI API.
122+
/// </summary>
123+
/// <remarks>
124+
/// This class offers synchronous and asynchronous methods for retrieving account details
125+
/// and account balance information associated with the provided API key. It is designed
126+
/// for both blocking and non-blocking workflows, making it suitable for various application requirements.
127+
/// </remarks>
120128
TUserRoute = class(TStabilityAIAPIRoute)
129+
/// <summary>
130+
/// Get information about the account associated with the provided API key
131+
/// <para>
132+
/// NOTE: This method is <c>synchronous</c>
133+
/// </para>
134+
/// </summary>
135+
/// <returns>
136+
/// Returns a <c>TAccountDetails</c> object that contains account informations.
137+
/// </returns>
138+
/// <exception cref="StabilityAIException">
139+
/// Thrown when there is an error in the communication with the API or other underlying issues in the API call.
140+
/// </exception>
141+
/// <exception cref="StabilityAIExceptionBadRequestError">
142+
/// Thrown when the request is invalid, such as when required parameters are missing or values exceed allowed limits.
143+
/// </exception>
144+
/// <remarks>
145+
/// <code>
146+
/// var Stability := TStabilityAIFactory.CreateInstance(BaererKey);
147+
/// var Data := Stability.Version1.User.AccountDetails;
148+
/// try
149+
/// for var Itel in Data.Result do
150+
/// //display details account informations
151+
/// finally
152+
/// Data.Free;
153+
/// end;
154+
/// </code>
155+
/// </remarks>
121156
function AccountDetails: TAccountDetails; overload;
157+
/// <summary>
158+
/// Get information about the account associated with the provided API key
159+
/// <para>
160+
/// NOTE: This method is <c>asynchronous</c>
161+
/// </para>
162+
/// </summary>
163+
/// <param name="CallBacks">
164+
/// A function that returns a record containing event handlers for asynchronous image creation, such as <c>onSuccess</c> and <c>onError</c>.
165+
/// </param>
166+
/// <exception cref="StabilityAIException">
167+
/// Thrown when there is an error in the communication with the API or other underlying issues in the API call.
168+
/// </exception>
169+
/// <exception cref="StabilityAIExceptionBadRequestError">
170+
/// Thrown when the request is invalid, such as when required parameters are missing or values exceed allowed limits.
171+
/// </exception>
172+
/// <remarks>
173+
/// <code>
174+
/// // WARNING - Move the following line to the main OnCreate method for maximum scope.
175+
/// // var Stability := TStabilityAIFactory.CreateInstance(BaererKey);
176+
/// Stability.Version1.User.AccountDetails(
177+
/// function : TAsynAccountDetails
178+
/// begin
179+
/// Result.Sender := my_obj; // Instance passed to callback parameter
180+
///
181+
/// Result.OnStart := nil; // If nil then; Can be omitted
182+
///
183+
/// Result.OnSuccess := procedure (Sender: TObject; Data: TAccountDetails)
184+
/// begin
185+
/// // Handle success operation
186+
/// end;
187+
///
188+
/// Result.OnError := procedure (Sender: TObject; Error: string)
189+
/// begin
190+
/// // Handle error message
191+
/// end;
192+
/// end);
193+
/// </code>
194+
/// </remarks>
122195
procedure AccountDetails(CallBacks: TFunc<TAsynAccountDetails>); overload;
123-
196+
/// <summary>
197+
/// Get the credit balance of the account/organization associated with the API key
198+
/// <para>
199+
/// NOTE: This method is <c>synchronous</c>
200+
/// </para>
201+
/// </summary>
202+
/// <returns>
203+
/// Returns a <c>TAccountBalance</c> object that contains balance information.
204+
/// </returns>
205+
/// <exception cref="StabilityAIException">
206+
/// Thrown when there is an error in the communication with the API or other underlying issues in the API call.
207+
/// </exception>
208+
/// <exception cref="StabilityAIExceptionBadRequestError">
209+
/// Thrown when the request is invalid, such as when required parameters are missing or values exceed allowed limits.
210+
/// </exception>
211+
/// <remarks>
212+
/// <code>
213+
/// var Stability := TStabilityAIFactory.CreateInstance(BaererKey);
214+
/// var Data := Stability.Version1.User.AccountBalance;
215+
/// try
216+
/// //display balanceinformation
217+
/// finally
218+
/// Data.Free;
219+
/// end;
220+
/// </code>
221+
/// </remarks>
124222
function AccountBalance: TAccountBalance; overload;
223+
/// <summary>
224+
/// Get the credit balance of the account/organization associated with the API key
225+
/// <para>
226+
/// NOTE: This method is <c>asynchronous</c>
227+
/// </para>
228+
/// </summary>
229+
/// <param name="CallBacks">
230+
/// A function that returns a record containing event handlers for asynchronous image creation, such as <c>onSuccess</c> and <c>onError</c>.
231+
/// </param>
232+
/// <exception cref="StabilityAIException">
233+
/// Thrown when there is an error in the communication with the API or other underlying issues in the API call.
234+
/// </exception>
235+
/// <exception cref="StabilityAIExceptionBadRequestError">
236+
/// Thrown when the request is invalid, such as when required parameters are missing or values exceed allowed limits.
237+
/// </exception>
238+
/// <remarks>
239+
/// <code>
240+
/// // WARNING - Move the following line to the main OnCreate method for maximum scope.
241+
/// // var Stability := TStabilityAIFactory.CreateInstance(BaererKey);
242+
/// Stability.Version1.User.AccountBalance(
243+
/// function : TAsynAccountBalance
244+
/// begin
245+
/// Result.Sender := my_obj; // Instance passed to callback parameter
246+
///
247+
/// Result.OnStart := nil; // If nil then; Can be omitted
248+
///
249+
/// Result.OnSuccess := procedure (Sender: TObject; Data: TAccountBalance)
250+
/// begin
251+
/// // Handle success operation
252+
/// end;
253+
///
254+
/// Result.OnError := procedure (Sender: TObject; Error: string)
255+
/// begin
256+
/// // Handle error message
257+
/// end;
258+
/// end);
259+
/// </code>
260+
/// </remarks>
125261
procedure AccountBalance(CallBacks: TFunc<TAsynAccountBalance>); overload;
126262
end;
127263

@@ -141,6 +277,11 @@ destructor TAccountDetails.Destroy;
141277

142278
{ TUserRoute }
143279

280+
function TUserRoute.AccountBalance: TAccountBalance;
281+
begin
282+
Result := API.Get<TAccountBalance>('v1/user/balance');
283+
end;
284+
144285
procedure TUserRoute.AccountBalance(CallBacks: TFunc<TAsynAccountBalance>);
145286
begin
146287
with TAsynCallBackExec<TAsynAccountBalance, TAccountBalance>.Create(CallBacks) do
@@ -159,9 +300,9 @@ procedure TUserRoute.AccountBalance(CallBacks: TFunc<TAsynAccountBalance>);
159300
end;
160301
end;
161302

162-
function TUserRoute.AccountBalance: TAccountBalance;
303+
function TUserRoute.AccountDetails: TAccountDetails;
163304
begin
164-
Result := API.Get<TAccountBalance>('v1/user/balance');
305+
Result := API.Get<TAccountDetails>('v1/user/account');
165306
end;
166307

167308
procedure TUserRoute.AccountDetails(CallBacks: TFunc<TAsynAccountDetails>);
@@ -182,9 +323,4 @@ procedure TUserRoute.AccountDetails(CallBacks: TFunc<TAsynAccountDetails>);
182323
end;
183324
end;
184325

185-
function TUserRoute.AccountDetails: TAccountDetails;
186-
begin
187-
Result := API.Get<TAccountDetails>('v1/user/account');
188-
end;
189-
190326
end.

source/StabilityAI.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ destructor TVersion1.Destroy;
612612
begin
613613
FVersion1Route.Free;
614614
FEnginesRoute.Free;
615-
FUSerRoute.Free;
615+
FUserRoute.Free;
616616
inherited;
617617
end;
618618

source/VCL.Stability.Tutorial.pas

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface
1515
uses
1616
System.SysUtils, System.Classes, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Controls, Vcl.Forms,
1717
StabilityAI.Common, StabilityAI.Version1.SDXL1AndSD1_6, StabilityAI.VideoAnd3D.Stable3D,
18-
StabilityAI.VideoAnd3D.Video, StabilityAI.Version1.Engines;
18+
StabilityAI.VideoAnd3D.Video, StabilityAI.Version1.Engines, StabilityAI.Version1.User;
1919

2020
type
2121
TVCLStabilitySender = class
@@ -40,6 +40,7 @@ TVCLStabilitySender = class
4040
procedure Display(Sender: TObject; Value: TModel3D); overload;
4141
procedure Display(Sender: TObject; Value: TJobVideo); overload;
4242
procedure Display(Sender: TObject; Value: TEngines); overload;
43+
procedure Display(Sender: TObject; Value: TAccountDetails); overload;
4344

4445
var
4546
StabilityResult: TVCLStabilitySender = nil;
@@ -48,7 +49,7 @@ implementation
4849

4950
procedure Start(Sender: TObject);
5051
begin
51-
Display(Sender, 'Request dended. Please wait...');
52+
Display(Sender, 'Request sended. Please wait...');
5253
end;
5354

5455
procedure Display(Sender: TObject; Value: string);
@@ -126,6 +127,20 @@ procedure Display(Sender: TObject; Value: TEngines);
126127
Display(Sender, Item.Name);
127128
end;
128129

130+
procedure Display(Sender: TObject; Value: TAccountDetails);
131+
begin
132+
Display(Sender, Value.Id);
133+
Display(Sender, Value.Email);
134+
Display(Sender, Value.ProfilePicture);
135+
for var Item in Value.Organizations do
136+
begin
137+
Display(Sender, Item.Id);
138+
Display(Sender, Item.Name);
139+
Display(Sender, Item.Role);
140+
Display(Sender, BoolToStr(Item.IsDefault, True));
141+
end;
142+
end;
143+
129144
{ TVCLStabilitySender }
130145

131146
constructor TVCLStabilitySender.Create(const AMemo: TMemo;

0 commit comments

Comments
 (0)