diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88d050b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +main \ No newline at end of file diff --git a/README.md b/README.md index 06878af..e35e60a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This repository is crafted with ❤️ by our talented community members. It's a space for everyone to use, contribute to, and share. While it aligns with the spirit of our community, please note that this repo is not directly endorsed or supported by Investec. Always exercise caution and discretion when using or contributing to community-driven projects. -# investecOpenAPI +# Investec Open API SDK for Go ## installation @@ -17,13 +17,13 @@ go mod init ``` ```bash -go get -v github.com/t4ke0/investecOpenAPI +go get -v github.com/devinpearson/investec-open-api-sdk-go ``` ## Usage -before you start you might need to have the `clientID` and `secret` from the API provider. +before you start you will need to have the `clientID`, `secret` and `apiKey` from Investec. then you are good to proceed. ```golang @@ -32,7 +32,7 @@ package main import ( *** - client "github.com/t4ke0/investecOpenAPI" + client "github.com/devinpearson/investec-open-api-sdk-go" *** ) @@ -42,8 +42,9 @@ func main() { // need to have secret and clientID then fill in these vars. secret := "" clientID := "" + apiKey := "" - clt := client.NewBankingClient(secret, clientID) + clt := client.NewBankingClient(secret, clientID, apiKey) // OAuth to the API if err := clt.GetAccessToken(); err != nil { diff --git a/example/cmd/main.go b/example/cmd/main.go index 9feec64..93e783a 100644 --- a/example/cmd/main.go +++ b/example/cmd/main.go @@ -3,18 +3,19 @@ package main import ( "log" - client "github.com/t4ke0/investecOpenAPI" + client "github.com/devinpearson/investec-open-api-sdk-go" ) // fill in the following vars var ( clientID string = "" secret string = "" + apiKey string = "" ) func main() { - clt := client.NewBankingClient(secret, clientID) + clt := client.NewBankingClient(secret, clientID, apiKey) if err := clt.GetAccessToken(); err != nil { log.Fatal(err) diff --git a/go.mod b/go.mod index 5e02166..150b988 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/t4ke0/investecOpenAPI +module github.com/devinpearson/investec-open-api-sdk-go go 1.18 diff --git a/investecOpenAPI.go b/investecOpenAPI.go index 4ae33cb..f48a7c5 100644 --- a/investecOpenAPI.go +++ b/investecOpenAPI.go @@ -8,22 +8,24 @@ import ( "net/http" "strings" - "github.com/t4ke0/investecOpenAPI/api" + "github.com/devinpearson/investec-open-api-sdk-go/api" ) const APIurl string = "https://openapi.investec.com" type BankingClient struct { UserCreds string + ApiKey string AccessToken string httpClient *http.Client } -func NewBankingClient(secret, clientID string) BankingClient { +func NewBankingClient(secret, clientID, apiKey string) BankingClient { userCreds := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", clientID, secret))) return BankingClient{ UserCreds: userCreds, + ApiKey: apiKey, httpClient: new(http.Client), } } @@ -54,6 +56,7 @@ func (b BankingClient) requestAPI(url, method string, mode authMode) (*http.Resp case basic: req.Header.Set("Authorization", fmt.Sprintf("Basic %s", b.UserCreds)) req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("x-api-key", b.ApiKey) case bearer: req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", b.AccessToken)) req.Header.Set("Accept", "application/json")