feat: Implement BudgetClient, add method for syncing bank
This commit is contained in:
parent
5f7ea4ccca
commit
79a6c7a2c1
7 changed files with 66 additions and 1 deletions
3
.env.example
Normal file
3
.env.example
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
BASE_URL=
|
||||||
|
API_KEY=
|
||||||
|
SYNC_ID=
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
.direnv/
|
.direnv/
|
||||||
result
|
result
|
||||||
|
.env
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
- [ ] Trigger a bank sync and see if we can wait for it to finish (might need to trigger the sync and then just wait, could also just do daily bank syncs at a certain hour)
|
- [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
|
||||||
- [ ] Send the email to the desired parties via SMTP
|
- [ ] Send the email to the desired parties via SMTP
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
# FIXME(TODO): Build the package
|
# FIXME(TODO): Build the package
|
||||||
# packages.default =
|
# packages.default =
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
|
ENVIRONMENT = "dev";
|
||||||
nativeBuildInputs = with pkgs; [ go ];
|
nativeBuildInputs = with pkgs; [ go ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
5
go.mod
Normal file
5
go.mod
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
module git.wanderingcrow.net/actualbudget-report
|
||||||
|
|
||||||
|
go 1.25.2
|
||||||
|
|
||||||
|
require github.com/joho/godotenv v1.5.1
|
||||||
2
go.sum
Normal file
2
go.sum
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
53
src/main.go
Normal file
53
src/main.go
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BudgetClient struct {
|
||||||
|
baseUrl string
|
||||||
|
apiKey string
|
||||||
|
syncId string
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateBudgetClient(baseUrl string, apiKey string, syncId string) *BudgetClient {
|
||||||
|
client := BudgetClient{baseUrl, apiKey, syncId}
|
||||||
|
return &client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b BudgetClient) BankSync() bool {
|
||||||
|
var httpClient http.Client
|
||||||
|
req, err := http.NewRequest("POST", b.baseUrl+"/v1/budgets/"+b.syncId+"/accounts/banksync", 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if os.Getenv("ENVIRONMENT") == "dev" {
|
||||||
|
err := godotenv.Load()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error loading .env file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var baseUrl = os.Getenv("BASE_URL")
|
||||||
|
var apiKey = os.Getenv("API_KEY")
|
||||||
|
var syncId = os.Getenv("SYNC_ID")
|
||||||
|
client := CreateBudgetClient(baseUrl, apiKey, syncId)
|
||||||
|
client.BankSync()
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue