APISystemInfo method (#60)

This commit is contained in:
Akolzin Dmitry 2022-02-03 18:09:33 +03:00 committed by GitHub
parent 1e51894cf4
commit 54810c21cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 0 deletions

View File

@ -277,6 +277,41 @@ func (c *Client) APICredentials() (CredentialResponse, int, error) {
return resp, status, nil
}
// APISystemInfo get info about system
//
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-system-info
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// data, status, err := client.APISystemInfo()
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// log.Printf("%v\n", data)
func (c *Client) APISystemInfo() (SystemInfoResponse, int, error) {
var resp SystemInfoResponse
data, status, err := c.GetRequest("/system-info", false)
if err != nil {
return resp, status, err
}
err = json.Unmarshal(data, &resp)
if err != nil {
return resp, status, err
}
return resp, status, nil
}
// Customers returns list of customers matched the specified filter
//
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers

View File

@ -15,6 +15,8 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/joho/godotenv"
gock "gopkg.in/h2non/gock.v1"
)
@ -180,6 +182,37 @@ func TestClient_ApiCredentialsCredentials(t *testing.T) {
}
}
func TestClient_APISystemInfo(t *testing.T) {
defer gock.Off()
r := SystemInfoResponse{
Success: true,
SystemVersion: "8.7.77",
PublicURL: crmURL,
TechnicalURL: fmt.Sprintf("https://%s.io", RandomString(30)),
}
data, err := json.Marshal(r)
if err != nil {
t.Errorf("%v", err)
}
gock.New(crmURL).
Get("/api/system-info").
Reply(200).
BodyString(string(data))
c := client()
res, s, e := c.APISystemInfo()
if e != nil {
t.Errorf("%v", e)
}
assert.Equal(t, s, 200)
assert.Equal(t, crmURL, res.PublicURL)
assert.Contains(t, res.TechnicalURL, ".io")
}
func TestClient_CustomersCustomers(t *testing.T) {
defer gock.Off()

View File

@ -39,6 +39,14 @@ type CredentialResponse struct {
SitesAvailable []string `json:"sitesAvailable,omitempty"`
}
// SystemInfoResponse return system info.
type SystemInfoResponse struct {
Success bool `json:"success,omitempty"`
SystemVersion string `json:"systemVersion,omitempty"`
PublicURL string `json:"publicUrl,omitempty"`
TechnicalURL string `json:"technicalUrl,omitempty"`
}
// CustomerResponse type.
type CustomerResponse struct {
Success bool `json:"success"`