diff --git a/README.md b/README.md index 27c1b81..229b519 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Learning golang, writing a simple app to interface with an HTTP API and generate # TODO - [ ] Fetch the desired budget file -- [ ] Change path to route in API caller +- [x] Change path to route in API caller - [x] Trigger a bank sync and see if we can wait for it to finish (looks like it's a blocking call so we can safely sync before reports) - [ ] Fetch the category information for each category as well as the overall groups - [ ] Compile a email-friendly report of the information diff --git a/src/main.go b/src/main.go index 2a61777..ce6b430 100644 --- a/src/main.go +++ b/src/main.go @@ -23,14 +23,18 @@ func CreateBudgetClient(baseUrl string, apiKey string, syncId string) *BudgetCli // 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 { +// route is the route to call with a leading / ex. /accounts/banksync +// headers is a map of strings expecting "header" "value" +func (b BudgetClient) callApi(method string, route string, headers map[string]string) bool { var httpClient http.Client - req, err := http.NewRequest(method, b.fullUrl+path, http.NoBody) + req, err := http.NewRequest(method, b.fullUrl+route, http.NoBody) if err != nil { log.Fatal(err) } req.Header.Add("x-api-key", b.apiKey) + for header, value := range headers { + req.Header.Add(header, value) + } resp, err := httpClient.Do(req) if err != nil { log.Fatal(err) @@ -39,6 +43,10 @@ func (b BudgetClient) CallApi(method string, path string) bool { return resp.StatusCode == http.StatusOK } +func (b BudgetClient) BankSync() bool { + return b.callApi("POST", "/accounts/banksync", nil) +} + func main() { if os.Getenv("ENVIRONMENT") == "dev" { err := godotenv.Load()