From 874fd2bafe2a4fc88ebd5e62e20ef9593a3aa9f5 Mon Sep 17 00:00:00 2001 From: TheWanderingCrow Date: Tue, 11 Nov 2025 23:10:33 -0500 Subject: [PATCH] refactor!: change the way api calls are made --- src/main.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.go b/src/main.go index e3dabba..2a61777 100644 --- a/src/main.go +++ b/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() {