Skip to content

Commit 1b0cc44

Browse files
authored
Merge pull request #2 from markus621/callback
add callback requests
2 parents b68d59e + 84d0f87 commit 1b0cc44

File tree

7 files changed

+511
-51
lines changed

7 files changed

+511
-51
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
lint:
22
golangci-lint -v run ./...
33

4-
54
generate:
6-
go generate -v ./...
5+
go generate -v ./...
6+
7+
demo_run:
8+
cd ./example && go run main.go

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ func main() {
2929
client := cli.NewClient(conf)
3030
client.Debug(true, os.Stdout)
3131

32-
acc, err := client.Account()
33-
mte, err := client.AccountMTEngines()
32+
_, _ = client.GetAccount()
33+
_, _ = client.GetAccountMTEngines()
34+
_, _ = client.SetCallback(cli.Callback{
35+
URL: "https://demo.example/callback",
36+
AdditionalHeaders: []cli.AdditionalHeader{
37+
{Name: "x-header", Value: "demo"},
38+
},
39+
})
40+
_, _ = client.GetCallback()
41+
_ = client.DelCallback()
42+
_, _ = client.GetCallbackLastErrors(10)
3443
}
3544
```

account.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ type (
2626
AccountMTEngines []AccountMTEngine
2727
)
2828

29-
//Account Receiving the account details
30-
func (v *Client) Account() (o Account, err error) {
31-
err, _ = v.call(http.MethodGet, uriAccount, nil, &o)
29+
//GetAccount Receiving the account details
30+
func (v *Client) GetAccount() (out Account, err error) {
31+
err, _ = v.call(http.MethodGet, uriAccount, nil, &out)
3232
return
3333
}
3434

35-
//AccountMtengines Receiving MT engines available for the account
36-
func (v *Client) AccountMTEngines() (o AccountMTEngines, err error) {
37-
err, _ = v.call(http.MethodGet, uriAccountMTEngines, nil, &o)
35+
//GetAccountMTEngines Receiving MT engines available for the account
36+
func (v *Client) GetAccountMTEngines() (out AccountMTEngines, err error) {
37+
err, _ = v.call(http.MethodGet, uriAccountMTEngines, nil, &out)
3838
return
3939
}

callback.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package smartcatclient
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
//go:generate easyjson
9+
10+
const (
11+
uriCallback = "/api/integration/v1/callback"
12+
uriCallbackLastErrors = "/api/integration/v1/callback/lastErrors"
13+
)
14+
15+
//easyjson:json
16+
type (
17+
AdditionalHeader struct {
18+
Name string `json:"name"`
19+
Value string `json:"value"`
20+
}
21+
Callback struct {
22+
URL string `json:"url"`
23+
AdditionalHeaders []AdditionalHeader `json:"additionalHeaders"`
24+
}
25+
LastError struct {
26+
Created string `json:"created"`
27+
URL string `json:"url"`
28+
Reason string `json:"reason"`
29+
Code int `json:"code"`
30+
Content string `json:"content"`
31+
SourceIds []string `json:"sourceIds"`
32+
}
33+
LastErrors []LastError
34+
)
35+
36+
//DelCallback Resetting the configuration of notifications reception
37+
func (v *Client) DelCallback() (err error) {
38+
err, _ = v.call(http.MethodDelete, uriCallback, nil, nil)
39+
return
40+
}
41+
42+
//GetCallback Reading configurations of notifications reception of the account
43+
func (v *Client) GetCallback() (out Callback, err error) {
44+
err, _ = v.call(http.MethodGet, uriCallback, nil, &out)
45+
return
46+
}
47+
48+
//SetCallback Setting configurations of notifications reception of the account
49+
func (v *Client) SetCallback(in Callback) (out Callback, err error) {
50+
err, _ = v.call(http.MethodPost, uriCallback, &in, &out)
51+
return
52+
}
53+
54+
//GetCallbackLastErrors Reading the recent sending errors
55+
func (v *Client) GetCallbackLastErrors(limit int) (out LastErrors, err error) {
56+
err, _ = v.call(http.MethodGet, fmt.Sprintf("%s?limit=%d", uriCallbackLastErrors, limit), nil, &out)
57+
return
58+
}

0 commit comments

Comments
 (0)