From 45fcf0fd3d1096b85dc6fef4fd705524004c5aee Mon Sep 17 00:00:00 2001 From: Devin Date: Sun, 4 Feb 2024 11:15:37 +0200 Subject: [PATCH 1/3] feat: added required api-key --- README.md | 3 ++- example/cmd/main.go | 5 +++-- go.mod | 2 +- investecOpenAPI.go | 7 +++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 06878af..fd56f59 100644 --- a/README.md +++ b/README.md @@ -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..8e375a0 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/api" ) // 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") From 734b524ef2163f7e83d3ca108aad1b4aafa4672b Mon Sep 17 00:00:00 2001 From: Devin Date: Sun, 4 Feb 2024 11:19:32 +0200 Subject: [PATCH 2/3] fix: corrected client url and added generated main to gitignore --- .gitignore | 1 + example/cmd/main.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .gitignore 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/example/cmd/main.go b/example/cmd/main.go index 8e375a0..93e783a 100644 --- a/example/cmd/main.go +++ b/example/cmd/main.go @@ -3,7 +3,7 @@ package main import ( "log" - client "github.com/devinpearson/investec-open-api-sdk-go/api" + client "github.com/devinpearson/investec-open-api-sdk-go" ) // fill in the following vars From 5d1a26cff7600d71e43d4222560b86091b6d6631 Mon Sep 17 00:00:00 2001 From: Devin Date: Sun, 4 Feb 2024 11:22:15 +0200 Subject: [PATCH 3/3] docs: updated readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fd56f59..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" *** )