refactor!: change the way api calls are made
This commit is contained in:
parent
79a6c7a2c1
commit
874fd2bafe
1 changed files with 10 additions and 9 deletions
19
src/main.go
19
src/main.go
|
|
@ -11,31 +11,32 @@ type BudgetClient struct {
|
|||
baseUrl string
|
||||
apiKey string
|
||||
syncId string
|
||||
fullUrl string
|
||||
}
|
||||
|
||||
func CreateBudgetClient(baseUrl string, apiKey string, syncId string) *BudgetClient {
|
||||
client := BudgetClient{baseUrl, apiKey, syncId}
|
||||
fullUrl := baseUrl + "/v1/budgets/" + syncId
|
||||
client := BudgetClient{baseUrl, apiKey, syncId, fullUrl}
|
||||
return &client
|
||||
}
|
||||
|
||||
func (b BudgetClient) BankSync() bool {
|
||||
// Make a call to the actualbudget API
|
||||
//
|
||||
// method is POST, GET, ect
|
||||
// path is the endpoint to call ex. /accounts/banksync
|
||||
func (b BudgetClient) CallApi(method string, path string) bool {
|
||||
var httpClient http.Client
|
||||
req, err := http.NewRequest("POST", b.baseUrl+"/v1/budgets/"+b.syncId+"/accounts/banksync", http.NoBody)
|
||||
req, err := http.NewRequest(method, b.fullUrl+path, http.NoBody)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
req.Header.Add("x-api-key", b.apiKey)
|
||||
log.Println("Sent off request")
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println(resp)
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
return resp.StatusCode == http.StatusOK
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue