Skip to content
Merged
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
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
lint:
golangci-lint -v run ./...


generate:
go generate -v ./...
go generate -v ./...

demo_run:
cd ./example && go run main.go
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ func main() {
client := cli.NewClient(conf)
client.Debug(true, os.Stdout)

acc, err := client.Account()
mte, err := client.AccountMTEngines()
_, _ = client.GetAccount()
_, _ = client.GetAccountMTEngines()
_, _ = client.SetCallback(cli.Callback{
URL: "https://demo.example/callback",
AdditionalHeaders: []cli.AdditionalHeader{
{Name: "x-header", Value: "demo"},
},
})
_, _ = client.GetCallback()
_ = client.DelCallback()
_, _ = client.GetCallbackLastErrors(10)
}
```
12 changes: 6 additions & 6 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ type (
AccountMTEngines []AccountMTEngine
)

//Account Receiving the account details
func (v *Client) Account() (o Account, err error) {
err, _ = v.call(http.MethodGet, uriAccount, nil, &o)
//GetAccount Receiving the account details
func (v *Client) GetAccount() (out Account, err error) {
err, _ = v.call(http.MethodGet, uriAccount, nil, &out)
return
}

//AccountMtengines Receiving MT engines available for the account
func (v *Client) AccountMTEngines() (o AccountMTEngines, err error) {
err, _ = v.call(http.MethodGet, uriAccountMTEngines, nil, &o)
//GetAccountMTEngines Receiving MT engines available for the account
func (v *Client) GetAccountMTEngines() (out AccountMTEngines, err error) {
err, _ = v.call(http.MethodGet, uriAccountMTEngines, nil, &out)
return
}
58 changes: 58 additions & 0 deletions callback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package smartcatclient

import (
"fmt"
"net/http"
)

//go:generate easyjson

const (
uriCallback = "/api/integration/v1/callback"
uriCallbackLastErrors = "/api/integration/v1/callback/lastErrors"
)

//easyjson:json
type (
AdditionalHeader struct {
Name string `json:"name"`
Value string `json:"value"`
}
Callback struct {
URL string `json:"url"`
AdditionalHeaders []AdditionalHeader `json:"additionalHeaders"`
}
LastError struct {
Created string `json:"created"`
URL string `json:"url"`
Reason string `json:"reason"`
Code int `json:"code"`
Content string `json:"content"`
SourceIds []string `json:"sourceIds"`
}
LastErrors []LastError
)

//DelCallback Resetting the configuration of notifications reception
func (v *Client) DelCallback() (err error) {
err, _ = v.call(http.MethodDelete, uriCallback, nil, nil)
return
}

//GetCallback Reading configurations of notifications reception of the account
func (v *Client) GetCallback() (out Callback, err error) {
err, _ = v.call(http.MethodGet, uriCallback, nil, &out)
return
}

//SetCallback Setting configurations of notifications reception of the account
func (v *Client) SetCallback(in Callback) (out Callback, err error) {
err, _ = v.call(http.MethodPost, uriCallback, &in, &out)
return
}

//GetCallbackLastErrors Reading the recent sending errors
func (v *Client) GetCallbackLastErrors(limit int) (out LastErrors, err error) {
err, _ = v.call(http.MethodGet, fmt.Sprintf("%s?limit=%d", uriCallbackLastErrors, limit), nil, &out)
return
}
Loading