From 409c6c90148a33386fcbe31cd67b0e2585a1ef41 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Fri, 9 Aug 2024 21:11:43 +0300 Subject: [PATCH] add getting gold in bank --- src/artifacts.zig | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/artifacts.zig b/src/artifacts.zig index ff0e194..266c550 100644 --- a/src/artifacts.zig +++ b/src/artifacts.zig @@ -461,7 +461,6 @@ pub const GoldTransactionResult = struct { pub fn parseDepositError(status: std.http.Status) ?BankDepositGoldError { return switch (@intFromEnum(status)) { 461 => BankDepositGoldError.BankIsBusy, - 478 => BankDepositGoldError.NotEnoughGold, // TODO: This should maybe be removed 486 => BankDepositGoldError.CharacterIsBusy, 492 => BankDepositGoldError.NotEnoughGold, 498 => BankDepositGoldError.CharacterNotFound, @@ -482,10 +481,6 @@ pub const GoldTransactionResult = struct { else => null }; } - - pub fn deinit(self: GoldTransactionResult) void { - _ = self; - } }; 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" { try std.testing.expectEqual(1723069394.105, parseDateTime("2024-08-07T22:23:14.105Z").?); }