feat!: add header insertion into callApi, make callApi "private", reimplement BankSync
This commit is contained in:
parent
d6fd8f51a1
commit
6b243f38df
2 changed files with 12 additions and 4 deletions
|
|
@ -2,7 +2,7 @@ Learning golang, writing a simple app to interface with an HTTP API and generate
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [ ] Fetch the desired budget file
|
- [ ] 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)
|
- [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
|
- [ ] Fetch the category information for each category as well as the overall groups
|
||||||
- [ ] Compile a email-friendly report of the information
|
- [ ] Compile a email-friendly report of the information
|
||||||
|
|
|
||||||
14
src/main.go
14
src/main.go
|
|
@ -23,14 +23,18 @@ func CreateBudgetClient(baseUrl string, apiKey string, syncId string) *BudgetCli
|
||||||
// Make a call to the actualbudget API
|
// Make a call to the actualbudget API
|
||||||
//
|
//
|
||||||
// method is POST, GET, ect
|
// method is POST, GET, ect
|
||||||
// path is the endpoint to call ex. /accounts/banksync
|
// route is the route to call with a leading / ex. /accounts/banksync
|
||||||
func (b BudgetClient) CallApi(method string, path string) bool {
|
// 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
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
req.Header.Add("x-api-key", b.apiKey)
|
req.Header.Add("x-api-key", b.apiKey)
|
||||||
|
for header, value := range headers {
|
||||||
|
req.Header.Add(header, value)
|
||||||
|
}
|
||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
@ -39,6 +43,10 @@ func (b BudgetClient) CallApi(method string, path string) bool {
|
||||||
return resp.StatusCode == http.StatusOK
|
return resp.StatusCode == http.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b BudgetClient) BankSync() bool {
|
||||||
|
return b.callApi("POST", "/accounts/banksync", nil)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if os.Getenv("ENVIRONMENT") == "dev" {
|
if os.Getenv("ENVIRONMENT") == "dev" {
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue