summaryrefslogtreecommitdiff
path: root/src/cardmarket/account.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cardmarket/account.go')
-rw-r--r--src/cardmarket/account.go88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/cardmarket/account.go b/src/cardmarket/account.go
new file mode 100644
index 0000000..3baa747
--- /dev/null
+++ b/src/cardmarket/account.go
@@ -0,0 +1,88 @@
+package cardmarket
+
+import (
+ "context"
+ "encoding/json"
+ "io"
+ "log/slog"
+)
+
+type Account struct{}
+
+func (c *ApiClient) GetAccountInformation(ctx context.Context) (Account, error) {
+ slog.DebugContext(ctx, "requesting account info...")
+ resp, err := c.httpClient.GetWithContext(ctx, c.baseURL+"/account")
+ if err != nil {
+ slog.DebugContext(ctx, "failed to get account info from API")
+ return Account{}, err
+ }
+ slog.DebugContext(ctx, "received account info")
+
+ slog.DebugContext(ctx, "reading body...")
+ respBodyBuf, err := io.ReadAll(resp.Body)
+ if err != nil {
+ slog.DebugContext(ctx, "failed to read body")
+ return Account{}, err
+ }
+ defer resp.Body.Close()
+ slog.DebugContext(ctx, "read body")
+
+ slog.DebugContext(ctx, "parsing body...", "respBodyBuf", string(respBodyBuf))
+ type responseBody struct {
+ UserID uint32 `json:"idUser"`
+ Username []byte `json:"username"`
+ Country []byte `json:"country"`
+ Type uint8 `json:"isCommercial"`
+ SellerStatus uint8 `json:"sellerActivation"`
+ RiskGroup uint8 `json:"riskGroup"`
+ Reputation uint8 `json:"reputation"`
+ ShipsFast uint8 `json:"shipsFast"`
+ SalesCount uint32 `json:"sellCount"`
+ SoldItemCount uint32 `json:"soldItems"`
+ AvgShippingTime uint8 `json:"avgShippingTime"`
+ OnVacation bool `json:"onVacation"`
+ DisplayLanguageID uint8 `json:"idDisplayLanguage"`
+ Name struct {
+ First []byte `json:"firstName"`
+ Last []byte `json:"lastName"`
+ } `json:"name"`
+ HomeAddress struct {
+ ReceiverName []byte `json:"name"`
+ Extra []byte `json:"extra"`
+ Street []byte `json:"street"`
+ PostCode []byte `json:"zip"`
+ City []byte `json:"city"`
+ Country []byte `json:"country"`
+ } `json:"homeAddress"`
+ Email []byte `json:"email"`
+ PhoneNumber []byte `json:"phoneNumber"`
+ VAT []byte `json:"vat"`
+ RegistrationDate []byte `json:"registerDate"`
+ IsActivated bool `json:"isActivated"`
+ Wallet struct {
+ TotalBalance float32 `json:"totalBalance"`
+ MoneyBalance float32 `json:"moneyBalance"`
+ BonusBalance float32 `json:"bonusBalance"`
+ UnpaidAmount float32 `json:"unpaidAmount"`
+ ProviderRechargeAmount float32 `json:"providerRechargeAmount"`
+ } `json:"moneyDetails"`
+ BankAccount struct {
+ AccountOwner []byte `json:"accountOwner"`
+ IBAN []byte `json:"iban"`
+ BIC []byte `json:"bic"`
+ BankName []byte `json:"bankName"`
+ } `json:"bankAccount"`
+ ArticlesInShoppingCart uint16 `json:"articlesInShoppingCart"`
+ UnreadMessages uint16 `json:"unreadMessages"`
+ MaySell bool `json:"maySell"`
+ Links map[string]string `json:"links"`
+ }
+ respBody := new(responseBody)
+ if err = json.Unmarshal(respBodyBuf, respBody); err != nil {
+ slog.DebugContext(ctx, "failed to unmarshal body: "+string(respBodyBuf))
+ return Account{}, err
+ }
+ slog.DebugContext(ctx, "parsed body")
+
+ return Account{}, nil
+}