settings method

This commit is contained in:
Pavel 2020-07-14 10:22:36 +03:00
parent 38acbef244
commit 12ae59c7b1
4 changed files with 113 additions and 0 deletions

View File

@ -4000,6 +4000,43 @@ func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, *e
return resp, status, nil return resp, status, nil
} }
// Settings returns system settings
//
// For more information see https://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-settings
//
// Example:
//
// var client = v5.New("https://demo.url", "09jIJ")
//
// data, status, err := client.Settings()
//
// if err.Error() != "" {
// fmt.Printf("%v", err.RuntimeErr)
// }
//
// if status >= http.StatusBadRequest {
// fmt.Printf("%v", err.ApiErr())
// }
//
// fmt.Printf("%#v\n", data)
func (c *Client) Settings() (SettingsResponse, int, *errs.Failure) {
var resp SettingsResponse
data, status, err := c.GetRequest("/settings")
if err.Error() != "" {
return resp, status, err
}
json.Unmarshal(data, &resp)
if resp.Success == false {
buildErr(data, err)
return resp, status, err
}
return resp, status, nil
}
// Inventories returns leftover stocks and purchasing prices // Inventories returns leftover stocks and purchasing prices
// //
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-inventories // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-inventories

View File

@ -4978,6 +4978,59 @@ func TestClient_Segments(t *testing.T) {
} }
} }
func TestClient_Settings(t *testing.T) {
c := client()
defer gock.Off()
gock.New(crmURL).
Get("/settings").
Reply(200).
BodyString(`{
"success": true,
"settings": {
"default_currency": {
"value": "RUB",
"updated_at": "2019-02-13 13:57:20"
},
"system_language": {
"value": "RU",
"updated_at": "2019-02-13 14:02:23"
},
"timezone": {
"value": "Europe/Moscow",
"updated_at": "2019-02-13 13:57:20"
}
}
}
`)
data, status, err := c.Settings()
if err.Error() != "" {
t.Errorf("%v", err.Error())
}
if status >= http.StatusBadRequest {
t.Errorf("%v", err.ApiError())
}
if data.Success != true {
t.Errorf("%v", err.ApiError())
}
if data.Settings.DefaultCurrency.Value != "RUB" {
t.Errorf("Invalid default_currency value: %v", data.Settings.DefaultCurrency.Value)
}
if data.Settings.SystemLanguage.Value != "RU" {
t.Errorf("Invalid system_language value: %v", data.Settings.SystemLanguage.Value)
}
if data.Settings.Timezone.Value != "Europe/Moscow" {
t.Errorf("Invalid timezone value: %v", data.Settings.Timezone.Value)
}
}
func TestClient_Segments_Fail(t *testing.T) { func TestClient_Segments_Fail(t *testing.T) {
c := client() c := client()

View File

@ -218,6 +218,12 @@ type SegmentsResponse struct {
Segments []Segment `json:"segments,omitempty,brackets"` Segments []Segment `json:"segments,omitempty,brackets"`
} }
// SettingsResponse type
type SettingsResponse struct {
Success bool `json:"success"`
Settings Settings `json:"settings,omitempty,brackets"`
}
// CountriesResponse type // CountriesResponse type
type CountriesResponse struct { type CountriesResponse struct {
Success bool `json:"success"` Success bool `json:"success"`

View File

@ -622,6 +622,23 @@ type Segment struct {
Active bool `json:"active,omitempty"` Active bool `json:"active,omitempty"`
} }
/*
* Settings related types
*/
// SettingsNode represents an item in settings. All settings nodes contains only string value and update time for now.
type SettingsNode struct {
Value string `json:"value"`
UpdatedAt string `json:"updated_at"`
}
// Settings type. Contains retailCRM configuration.
type Settings struct {
DefaultCurrency SettingsNode `json:"default_currency"`
SystemLanguage SettingsNode `json:"system_language"`
Timezone SettingsNode `json:"timezone"`
}
/** /**
Reference related types Reference related types
*/ */