Wizardry with unmarshal and xml

This commit is contained in:
Jacob Windle 2020-01-19 19:35:36 -05:00
parent d2861c2df2
commit b816717362
2 changed files with 31 additions and 17 deletions

View File

@ -79,26 +79,40 @@ func (c *AllyApi) AccountBalances() (balances []AccountBalance) {
return resp.AccountBalances
}
func (c *AllyApi) AccountDetail(accountId string) AccountDetailResponse {
var resp AccountDetailResponse
_ = xml.Unmarshal(c.getAndRead(fmt.Sprintf("accounts/%s", accountId)), &resp)
return resp
/**
Return an object representing account detail of a given string
*/
func (c *AllyApi) AccountDetail(accountId string) (resp AccountDetailResponse) {
c.marshalInterfaceResponse(fmt.Sprintf("accounts/%s", accountId), &resp)
return
}
func (c *AllyApi) AccountBalance(accountId string) AccountDetailBalanceResponse {
var resp AccountDetailBalanceResponse
_ = xml.Unmarshal(c.getAndRead(fmt.Sprintf("accounts/%s/balances", accountId)), &resp)
return resp
/**
Return an object representing account balances of a given string ID
*/
func (c *AllyApi) AccountBalance(accountId string) (resp AccountDetailBalanceResponse) {
c.marshalInterfaceResponse(fmt.Sprintf("accounts/%s/balances", accountId), &resp)
return
}
func (c *AllyApi) AccountHoldings(accountId string) AccountDetailHoldingsResponse {
var resp AccountDetailHoldingsResponse
_ = xml.Unmarshal(c.getAndRead(fmt.Sprintf("accounts/%s/holdings", accountId)), &resp)
return resp
/**
Return an object representing the account holdings of a given string.
*/
func (c *AllyApi) AccountHoldings(accountId string) (resp AccountDetailHoldingsResponse) {
c.marshalInterfaceResponse(fmt.Sprintf("accounts/%s/holdings", accountId), &resp)
return
}
func (c *AllyApi) MarketClock() MarketClockResponse {
var resp MarketClockResponse
_ = xml.Unmarshal(c.getAndRead("market/clock"), &resp)
return resp
/**
Return an object representing the market clock response.
*/
func (c *AllyApi) MarketClock() (resp MarketClockResponse) {
c.marshalInterfaceResponse("market/clock", &resp)
return
}
// Why does this work?? wtf??
func (c *AllyApi) marshalInterfaceResponse(p string, i interface{}) {
resp := c.getAndRead(p)
_ = xml.Unmarshal(resp, &i)
}

View File

@ -9,5 +9,5 @@ func main() {
var api AllyApi
api.Initialize()
fmt.Printf("Market Clock: %d\n", api.MarketClock().UnixTime)
fmt.Printf("Market Clock: %d\n", api.MarketClock().CurrentStatus)
}