Commit 0e30e227 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel

Fixups after making MergeStructs more strict

parent bc9c412d
......@@ -35,7 +35,7 @@ type wrappedDeviceServerResponse struct {
Response []deviceServerResponse `json:"Response"`
}
type deviceServerResponse struct {
ID BunqID `json:"Id"`
ID *BunqID `json:"Id"`
}
// CheckDeviceServer registers this device with bunq if we don't have a device ID yet.
......@@ -64,6 +64,6 @@ func (c *Client) PostDeviceServer(description string, permittedIPs []string) {
MergeStructs(wrappedResponse.Response, &response)
c.creds.DeviceID = &response.ID.ID
log.WithField("id", c.creds.DeviceID).Info("registered device device ID")
log.WithField("id", *c.creds.DeviceID).Info("registered device device ID")
c.creds.Save()
}
......@@ -76,7 +76,8 @@ func MergeStructs(responses interface{}, mergedResp interface{}) {
useValue = fieldVal.Int() != 0
// fmt.Printf("is int : %v", useValue)
default:
panic(fmt.Sprintf("field %s is of unmergeable kind %v", respType.Field(fieldnum).Name, fieldVal.Kind()))
panic(fmt.Sprintf("field %s.%s is of unmergeable kind %v",
respType.Name(), respType.Field(fieldnum).Name, fieldVal.Kind()))
}
// fmt.Println()
......
......@@ -36,13 +36,6 @@ type monetaryAccountBankResponse struct {
MonetaryAccountBank MonetaryAccountBank `json:"MonetaryAccountBank"`
}
type wrappedMonetaryAccountBankCreateResponse struct {
Response []monetaryAccountBankCreateResponse `json:"Response"`
}
type monetaryAccountBankCreateResponse struct {
ID BunqID `json:"Id"`
}
// MonetaryAccountBank is defined by the bunq API.
type MonetaryAccountBank struct {
ID int `json:"id,omitempty"`
......@@ -133,14 +126,14 @@ func (c *Client) GetMonetaryAccountBank(accountID int) (MonetaryAccountBank, err
// CreateMonetaryAccountBank creates a new bank account for the current user.
func (c *Client) CreateMonetaryAccountBank(account MonetaryAccountBank) {
wrappedResponse := wrappedMonetaryAccountBankCreateResponse{}
wrappedResponse := wrappedIDResponse{}
url := fmt.Sprintf("user/%d/monetary-account-bank", c.session.UserPerson.ID)
errResp := c.DoRequest("POST", url, &account, &wrappedResponse)
if errResp != nil {
log.WithFields(errResp.LogFields()).Fatal("error performing session creation request")
}
response := monetaryAccountBankCreateResponse{}
response := idResponse{}
MergeStructs(wrappedResponse.Response, &response)
log.WithField("bankAccountID", response.ID.ID).Info("bank account created")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment