Skip to content

Commit 830c3ff

Browse files
committed
Implement depot resource functions
1 parent 4398072 commit 830c3ff

File tree

9 files changed

+353
-90
lines changed

9 files changed

+353
-90
lines changed

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,32 @@ the [comdirect REST API](https://www.comdirect.de/cms/kontakt-zugaenge-api.html)
1010
1111
Documentation
1212
---
13-
You can find more detailed documentation
14-
* on the [website](https://jsattler.github.io/comdirect-golang/#/)
13+
You can find detailed documentation
14+
* on this [website](https://jsattler.github.io/comdirect-golang/#/)
1515
* in the [`docs/`](docs/getting-started.md) folder
16-
* or in the [`examples/`](examples) older
16+
* in the [`examples/`](examples) folder
17+
* or in the tests [`pkg/comdirect`](pkg/comdirect)
1718

1819
Roadmap / To-Do
1920
---
20-
> Bold items have priority
2121

22-
**Functional**
23-
* [x] **Auth**
24-
* [x] P_TAN_PUSH
25-
* [ ] P_TAN_PHOTO (currently out of scope, since the package is not intended for use in front end apps)
26-
* [ ] P_TAN_APP (currently out of scope, since I have no chance to test this)
27-
* [x] Refresh Token Flow
28-
* [x] Revoke Token
29-
* [x] **Account**
30-
* [x] All Balances
31-
* [x] Balance by Account ID
32-
* [x] Transactions
33-
* [ ] **Depot**
34-
* [ ] All Depots
35-
* [ ] Positions by Depot ID
36-
* [ ] Position by Depot ID and Position ID
37-
* [ ] Transactions by Depot ID
38-
* [ ] **Instrument**
39-
* [ ] **Order**
22+
* [x] Auth
23+
* [x] P_TAN_PUSH
24+
* [ ] P_TAN_PHOTO (currently out of scope, since the package is not intended for use in front end apps)
25+
* [ ] P_TAN_APP (currently out of scope, since I have no chance to test this)
26+
* [x] Refresh Token
27+
* [x] Revoke Token
28+
* [x] Account
29+
* [x] All Balances
30+
* [x] Balance by Account ID
31+
* [x] Transactions
32+
* [x] Depot
33+
* [x] All Depots
34+
* [x] Positions by Depot ID
35+
* [x] Position by Depot ID and Position ID
36+
* [x] Transactions by Depot ID
37+
* [ ] Instrument
38+
* [ ] Order
4039
* [ ] Quote
41-
* [ ] **Documents**
40+
* [ ] Documents
4241
* [ ] Reports

pkg/comdirect/account.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type Creditor struct {
7272
}
7373

7474
func (c *Client) Balances() ([]AccountBalance, error) {
75-
if c.authentication.accessToken == nil || c.authentication.IsExpired() {
75+
if c.authentication.accessToken.AccessToken == "" || c.authentication.IsExpired() {
7676
return nil, errors.New("authentication is expired or not initialized")
7777
}
7878
info, err := requestInfoJSON(c.authentication.sessionID)
@@ -97,7 +97,7 @@ func (c *Client) Balances() ([]AccountBalance, error) {
9797
}
9898

9999
func (c *Client) Balance(accountId string) (*AccountBalance, error) {
100-
if c.authentication.accessToken == nil || c.authentication.IsExpired() {
100+
if c.authentication.accessToken.AccessToken == "" || c.authentication.IsExpired() {
101101
return nil, errors.New("authentication is expired or not initialized")
102102
}
103103

@@ -123,7 +123,7 @@ func (c *Client) Balance(accountId string) (*AccountBalance, error) {
123123
}
124124

125125
func (c *Client) Transactions(accountId string) ([]Transaction, error) {
126-
if c.authentication.accessToken == nil || c.authentication.IsExpired() {
126+
if c.authentication.accessToken.AccessToken == "" || c.authentication.IsExpired() {
127127
return nil, errors.New("authentication is expired or not initialized")
128128
}
129129
info, err := requestInfoJSON(c.authentication.sessionID)

pkg/comdirect/account_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package comdirect
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
)
8+
9+
func TestClient_Balances(t *testing.T) {
10+
client := clientFromEnv()
11+
auth, err := client.Authenticate()
12+
if err != nil {
13+
t.Errorf("failed to authenticate: %s", err)
14+
}
15+
fmt.Printf("%+v\n", auth)
16+
balances, err := client.Balances()
17+
if err != nil {
18+
t.Errorf("failed to exchange account balances %s", err)
19+
}
20+
21+
fmt.Printf("%+v\n", balances)
22+
23+
auth, err = client.Refresh()
24+
if err != nil {
25+
return
26+
}
27+
fmt.Printf("%+v\n", auth)
28+
29+
err = client.Revoke()
30+
if err != nil {
31+
return
32+
}
33+
fmt.Println("successfully revoked access token")
34+
}
35+
36+
func TestClient_Balance(t *testing.T) {
37+
client := clientFromEnv()
38+
_, err := client.Balance(os.Getenv("COMDIRECT_ACCOUNT_ID"))
39+
40+
if err != nil {
41+
t.Errorf("failed to exchange account balance %s", err)
42+
return
43+
}
44+
}
45+
46+
func TestClient_Transactions(t *testing.T) {
47+
client := clientFromEnv()
48+
transactions, err := client.Transactions(os.Getenv("COMDIRECT_ACCOUNT_ID"))
49+
50+
if err != nil {
51+
t.Errorf("failed to exchange account balance %s", err)
52+
return
53+
}
54+
55+
for _, t := range transactions {
56+
fmt.Printf("%v\n", t)
57+
}
58+
}
59+
60+
func clientFromEnv() *Client {
61+
options := &AuthOptions{
62+
Username: os.Getenv("COMDIRECT_USERNAME"),
63+
Password: os.Getenv("COMDIRECT_PASSWORD"),
64+
ClientId: os.Getenv("COMDIRECT_CLIENT_ID"),
65+
ClientSecret: os.Getenv("COMDIRECT_CLIENT_SECRET"),
66+
}
67+
return NewWithAuthOptions(options)
68+
}

pkg/comdirect/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type authState struct {
3535

3636
// Authentication represents an authentication object for the comdirect REST API.
3737
type Authentication struct {
38-
accessToken *AccessToken
38+
accessToken AccessToken
3939
sessionID string
4040
time time.Time
4141
}
@@ -144,7 +144,7 @@ func (a *Authenticator) Authenticate() (*Authentication, error) {
144144
}
145145

146146
return &Authentication{
147-
accessToken: &state.accessToken,
147+
accessToken: state.accessToken,
148148
sessionID: state.requestInfo.ClientRequestID.SessionID,
149149
time: time.Now(),
150150
}, err
@@ -172,7 +172,7 @@ func (a *Authenticator) Refresh(auth Authentication) (Authentication, error) {
172172
var accessToken AccessToken
173173
_, err := a.http.exchange(req, &accessToken)
174174

175-
auth.accessToken = &accessToken
175+
auth.accessToken = accessToken
176176
auth.time = time.Now()
177177
return auth, err
178178
}

pkg/comdirect/client_test.go

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,23 @@
11
package comdirect
22

3-
import (
4-
"fmt"
5-
"os"
6-
"testing"
7-
)
3+
import "testing"
84

9-
func TestClient_AccountBalances(t *testing.T) {
10-
client := getClientFromEnv()
11-
auth, err := client.Authenticate()
12-
if err != nil {
13-
t.Errorf("failed to authenticate: %s", err)
14-
}
15-
fmt.Printf("%+v\n", auth)
16-
balances, err := client.Balances()
17-
if err != nil {
18-
t.Errorf("failed to exchange account balances %s", err)
19-
}
20-
21-
fmt.Printf("%+v\n", balances)
22-
23-
auth, err = client.Refresh()
24-
if err != nil {
25-
return
26-
}
27-
fmt.Printf("%+v\n", auth)
28-
29-
err = client.Revoke()
30-
if err != nil {
31-
return
32-
}
33-
fmt.Println("successfully revoked access token")
5+
func TestNewWithAuthenticator(t *testing.T) {
6+
// TODO
347
}
358

36-
func TestClient_Balance(t *testing.T) {
37-
client := getClientFromEnv()
38-
accountId := os.Getenv("COMDIRECT_ACCOUNT_ID")
39-
_, err := client.Balance(accountId)
40-
41-
if err != nil {
42-
t.Errorf("failed to exchange account balance %s", err)
43-
return
44-
}
9+
func TestNewWithAuthOptions(t *testing.T) {
10+
// TODO
4511
}
4612

47-
func TestClient_Transactions(t *testing.T) {
48-
client := getClientFromEnv()
49-
accountId := os.Getenv("COMDIRECT_ACCOUNT_ID")
50-
transactions, err := client.Transactions(accountId)
51-
52-
if err != nil {
53-
t.Errorf("failed to exchange account balance %s", err)
54-
return
55-
}
56-
57-
for _, t := range transactions {
58-
fmt.Printf("%v\n", t)
59-
}
13+
func TestClient_Authenticate(t *testing.T) {
14+
// TODO
6015
}
6116

62-
func getClientFromEnv() *Client {
63-
64-
options := &AuthOptions{
65-
Username: os.Getenv("COMDIRECT_USERNAME"),
66-
Password: os.Getenv("COMDIRECT_PASSWORD"),
67-
ClientId: os.Getenv("COMDIRECT_CLIENT_ID"),
68-
ClientSecret: os.Getenv("COMDIRECT_CLIENT_SECRET"),
69-
}
17+
func TestClient_Refresh(t *testing.T) {
18+
// TODO
19+
}
7020

71-
return NewWithAuthOptions(options)
21+
func TestClient_Revoke(t *testing.T) {
22+
// TODO
7223
}

0 commit comments

Comments
 (0)