Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,13 +17,13 @@ go mod init <project name>
```

```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
Expand All @@ -32,7 +32,7 @@ package main
import (
***

client "github.com/t4ke0/investecOpenAPI"
client "github.com/devinpearson/investec-open-api-sdk-go"

***
)
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions example/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/t4ke0/investecOpenAPI
module github.com/devinpearson/investec-open-api-sdk-go

go 1.18
7 changes: 5 additions & 2 deletions investecOpenAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -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")
Expand Down