diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..ddfc488 --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +# QuickBooks API Credentials +QB_CLIENT_ID=your_client_id_here +QB_CLIENT_SECRET=your_client_secret_here +QB_REALM_ID=your_realm_id_here + +# For Authorization Flow Test +QB_AUTH_CODE=your_auth_code_here + +# For Token Reuse Test +QB_REFRESH_TOKEN=your_refresh_token_here +QB_ACCESS_TOKEN=your_access_token_here diff --git a/.gitignore b/.gitignore index 6c56eff..1aa06a5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ # IntelliJ .idea +CLAUDE.md +.claude +.env diff --git a/examples/auth_flow_test.go b/examples/auth_flow_test.go index 5012300..04b0ccc 100644 --- a/examples/auth_flow_test.go +++ b/examples/auth_flow_test.go @@ -2,22 +2,30 @@ package examples import ( "fmt" + "os" "testing" + "github.com/joho/godotenv" "github.com/rwestlund/quickbooks-go" "github.com/stretchr/testify/require" ) func TestAuthorizationFlow(t *testing.T) { - clientId := "" - clientSecret := "" - realmId := "" + _ = godotenv.Load("../.env") // Load .env file if it exists + + clientId := os.Getenv("QB_CLIENT_ID") + clientSecret := os.Getenv("QB_CLIENT_SECRET") + realmId := os.Getenv("QB_REALM_ID") + authorizationCode := os.Getenv("QB_AUTH_CODE") + + if clientId == "" || clientSecret == "" || realmId == "" || authorizationCode == "" { + t.Skip("Skipping TestAuthorizationFlow; QB_CLIENT_ID, QB_CLIENT_SECRET, QB_REALM_ID, or QB_AUTH_CODE not set") + } qbClient, err := quickbooks.NewClient(clientId, clientSecret, realmId, false, "", nil) require.NoError(t, err) // To do first when you receive the authorization code from quickbooks callback - authorizationCode := "" redirectURI := "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl" bearerToken, err := qbClient.RetrieveBearerToken(authorizationCode, redirectURI) require.NoError(t, err) diff --git a/examples/reuse_token_test.go b/examples/reuse_token_test.go index 5691fe1..b984f6c 100644 --- a/examples/reuse_token_test.go +++ b/examples/reuse_token_test.go @@ -2,20 +2,30 @@ package examples import ( "fmt" + "os" "testing" + "github.com/joho/godotenv" "github.com/rwestlund/quickbooks-go" "github.com/stretchr/testify/require" ) func TestReuseToken(t *testing.T) { - clientId := "" - clientSecret := "" - realmId := "" + _ = godotenv.Load("../.env") // Load .env file if it exists + + clientId := os.Getenv("QB_CLIENT_ID") + clientSecret := os.Getenv("QB_CLIENT_SECRET") + realmId := os.Getenv("QB_REALM_ID") + refreshToken := os.Getenv("QB_REFRESH_TOKEN") + accessToken := os.Getenv("QB_ACCESS_TOKEN") + + if clientId == "" || clientSecret == "" || realmId == "" || refreshToken == "" || accessToken == "" { + t.Skip("Skipping TestReuseToken; required environment variables not set") + } token := quickbooks.BearerToken{ - RefreshToken: "", - AccessToken: "", + RefreshToken: refreshToken, + AccessToken: accessToken, } qbClient, err := quickbooks.NewClient(clientId, clientSecret, realmId, false, "", &token) diff --git a/go.mod b/go.mod index ec22901..ebe124a 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,11 @@ module github.com/rwestlund/quickbooks-go -go 1.20 +go 1.25 require ( - github.com/stretchr/testify v1.9.0 - golang.org/x/oauth2 v0.19.0 + github.com/joho/godotenv v1.5.1 + github.com/stretchr/testify v1.11.1 + golang.org/x/oauth2 v0.35.0 gopkg.in/guregu/null.v4 v4.0.0 ) diff --git a/go.sum b/go.sum index a260b36..c2626c0 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,15 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg= -golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ= +golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/guregu/null.v4 v4.0.0 h1:1Wm3S1WEA2I26Kq+6vcW+w0gcDo44YKYD7YIEJNHDjg=