add getting gold in bank

This commit is contained in:
Rokas Puzonas 2024-08-09 21:11:43 +03:00
parent 56915df9ac
commit 409c6c9014

View File

@ -461,7 +461,6 @@ pub const GoldTransactionResult = struct {
pub fn parseDepositError(status: std.http.Status) ?BankDepositGoldError { pub fn parseDepositError(status: std.http.Status) ?BankDepositGoldError {
return switch (@intFromEnum(status)) { return switch (@intFromEnum(status)) {
461 => BankDepositGoldError.BankIsBusy, 461 => BankDepositGoldError.BankIsBusy,
478 => BankDepositGoldError.NotEnoughGold, // TODO: This should maybe be removed
486 => BankDepositGoldError.CharacterIsBusy, 486 => BankDepositGoldError.CharacterIsBusy,
492 => BankDepositGoldError.NotEnoughGold, 492 => BankDepositGoldError.NotEnoughGold,
498 => BankDepositGoldError.CharacterNotFound, 498 => BankDepositGoldError.CharacterNotFound,
@ -482,10 +481,6 @@ pub const GoldTransactionResult = struct {
else => null else => null
}; };
} }
pub fn deinit(self: GoldTransactionResult) void {
_ = self;
}
}; };
pub const ItemTransactionResult = struct { pub const ItemTransactionResult = struct {
@ -1071,6 +1066,22 @@ pub fn actionEquip(
); );
} }
pub fn getBankGold(self: *ArtifactsAPI) APIError!u64 {
const result = try self.fetch(.{ .method = .GET, .path = "/my/bank/gold" });
defer result.deinit();
if (result.status != .ok) {
return APIError.RequestFailed;
}
if (result.body == null) {
return APIError.ParseFailed;
}
const data = json_utils.asObject(result.body.?) orelse return APIError.RequestFailed;
const quantity = json_utils.getInteger(data, "quantity") orelse return APIError.ParseFailed;
return @intCast(quantity);
}
test "parse date time" { test "parse date time" {
try std.testing.expectEqual(1723069394.105, parseDateTime("2024-08-07T22:23:14.105Z").?); try std.testing.expectEqual(1723069394.105, parseDateTime("2024-08-07T22:23:14.105Z").?);
} }