diff --git a/client.go b/client.go index 89c56a8..50d5224 100644 --- a/client.go +++ b/client.go @@ -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 diff --git a/client_test.go b/client_test.go index 3f102a2..d01fba8 100644 --- a/client_test.go +++ b/client_test.go @@ -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() diff --git a/response.go b/response.go index 8933be1..5f326a6 100644 --- a/response.go +++ b/response.go @@ -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"`