mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-11-24 13:56:04 +03:00
APISystemInfo method (#60)
This commit is contained in:
parent
1e51894cf4
commit
54810c21cd
35
client.go
35
client.go
@ -277,6 +277,41 @@ func (c *Client) APICredentials() (CredentialResponse, int, error) {
|
|||||||
return resp, status, nil
|
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
|
// Customers returns list of customers matched the specified filter
|
||||||
//
|
//
|
||||||
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers
|
||||||
|
@ -15,6 +15,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
gock "gopkg.in/h2non/gock.v1"
|
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) {
|
func TestClient_CustomersCustomers(t *testing.T) {
|
||||||
defer gock.Off()
|
defer gock.Off()
|
||||||
|
|
||||||
|
@ -39,6 +39,14 @@ type CredentialResponse struct {
|
|||||||
SitesAvailable []string `json:"sitesAvailable,omitempty"`
|
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.
|
// CustomerResponse type.
|
||||||
type CustomerResponse struct {
|
type CustomerResponse struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
|
Loading…
Reference in New Issue
Block a user