SDKs
Go SDK
Management Client
8min
Go
import(
"gitlab.com/l3178/sdk-go/management_client"
management_request "gitlab.com/l3178/sdk-go/management_client/models/request"
)
Go
config := management_client.NewManagementClientConfiguration("managementKey")
c := management_client.NewManagementClient(config)
Go
ctx := context.Background()
t.Run("Create", func(t *testing.T) {
resp := c.CustomerApi().CreateCustomer(ctx, management_request.CreateCustomerRequest{
Email: "[email protected]",
FirstName: "Test",
})
require.NoError(t, resp.Error)
id = resp.Value.Id
})
t.Run("List", func(t *testing.T) {
resp := c.CustomerApi().ListCustomers(ctx, management_request.SearchCustomersRequest{
Email: "[email protected]",
})
assert.NoError(t, resp.Error)
assert.Equal(t, 1, resp.Count)
})
t.Run("Edit", func(t *testing.T) {
resp := c.CustomerApi().EditCustomer(ctx, id, management_request.CreateCustomerRequest{
LastName: "abcd",
})
assert.NoError(t, resp.Error)
})
t.Run("Get", func(t *testing.T) {
resp := c.CustomerApi().ShowCustomer(ctx, id)
assert.NoError(t, resp.Error)
assert.Equal(t, "abcd", resp.Value.LastName)
})
t.Run("Delete", func(t *testing.T) {
err := c.CustomerApi().DeleteCustomer(ctx, id)
assert.NoError(t, err)
})
t.Run("Create", func(t *testing.T) {
resp := c.CustomerApi().CreateCustomerLabel(ctx, management_request.CreateCustomerLabelRequest{
Label: "abcd",
Color: "efgh",
})
require.NoError(t, resp.Error)
id = resp.Value.Id
})
t.Run("List", func(t *testing.T) {
resp := c.CustomerApi().ListCustomerLabels(ctx, management_request.SearchRequest{})
assert.NoError(t, resp.Error)
assert.Equal(t, 1, resp.Count)
})
t.Run("Edit", func(t *testing.T) {
resp := c.CustomerApi().EditCustomerLabel(ctx, id, management_request.CreateCustomerLabelRequest{
Color: "1234",
})
assert.NoError(t, resp.Error)
})
t.Run("Get", func(t *testing.T) {
resp := c.CustomerApi().ShowCustomerLabel(ctx, id)
assert.NoError(t, resp.Error)
assert.Equal(t, "1234", resp.Value.Color)
})
t.Run("Delete", func(t *testing.T) {
err := c.CustomerApi().DeleteCustomerLabel(ctx, id)
assert.NoError(t, err)
})
t.Run("Create", func(t *testing.T) {
resp := c.CustomerApi().CreateCustomerAccount(ctx, management_request.CreateCustomerAccountRequest{
Code: "abcd",
Name: "efgh",
})
require.NoError(t, resp.Error)
id = resp.Value.Id
})
t.Run("List", func(t *testing.T) {
resp := c.CustomerApi().ListCustomerAccounts(ctx, management_request.SearchRequest{})
assert.NoError(t, resp.Error)
assert.Equal(t, 1, resp.Count)
})
t.Run("Edit", func(t *testing.T) {
resp := c.CustomerApi().EditCustomerAccount(ctx, id, management_request.CreateCustomerAccountRequest{
Description: "test",
})
assert.NoError(t, resp.Error)
})
t.Run("Get", func(t *testing.T) {
resp := c.CustomerApi().ShowCustomerAccount(ctx, id)
assert.NoError(t, resp.Error)
assert.Equal(t, "test", resp.Value.Description)
})
t.Run("Delete", func(t *testing.T) {
err := c.CustomerApi().DeleteCustomerAccount(ctx, id)
assert.NoError(t, err)
})
Go
ctx := context.Background()
t.Run("SearchDevices", func(t *testing.T) {
resp := c.DeviceApi().ListDevices(ctx, management_request.SearchDevicesRequest{
License: testLicenseID,
})
assert.NoError(t, resp.Error)
})
t.Run("ShowDevice", func(t *testing.T) {
c.DeviceApi().ShowDevice(ctx, deviceID)
})
t.Run("ResetDevice", func(t *testing.T) {
c.DeviceApi().ResetDevice(ctx, deviceID)
})
t.Run("BlacklistDevice", func(t *testing.T) {
c.DeviceApi().BlacklistDevice(ctx, deviceID)
})
t.Run("CreateDeviceVariable", func(t *testing.T) {
resp := c.DeviceApi().CreateDeviceVariable(ctx, management_request.CreateDeviceVariableRequest{
Variable: "test",
Value: "value",
Device: deviceID,
})
assert.NoError(t, resp.Error)
})
t.Run("UpdateDeviceVariable", func(t *testing.T) {
resp := c.DeviceApi().UpdateDeviceVariable(ctx, deviceID, management_request.UpdateDeviceVariableRequest{
Variable: "test",
Value: "value",
})
assert.NoError(t, resp.Error)
})
t.Run("DeleteDeviceVariable", func(t *testing.T) {
err := c.DeviceApi().DeleteDeviceVariable(ctx, deviceID)
assert.NoError(t, err)
})
t.Run("SearchDeviceVariable", func(t *testing.T) {
resp := c.DeviceApi().ListDeviceVariables(ctx, management_request.SearchDeviceVariablesRequest{
Device: deviceID,
})
assert.NoError(t, resp.Error)
})
t.Run("ShowDeviceVariable", func(t *testing.T) {
resp := c.DeviceApi().ShowDeviceVariable(ctx, deviceID)
assert.NoError(t, resp.Error)
})
Go
ctx := context.Background()
t.Run("Disable", func(t *testing.T) {
resp := c.LicenseApi().DisableLicense(ctx, testLicenseID)
assert.NoError(t, resp.Error)
})
t.Run("Get", func(t *testing.T) {
resp := c.LicenseApi().GetLicense(ctx, testLicenseID)
assert.NoError(t, resp.Error)
assert.False(t, resp.Value.Enabled)
})
t.Run("Enable", func(t *testing.T) {
resp := c.LicenseApi().EnableLicense(ctx, testLicenseID)
assert.NoError(t, resp.Error)
})
t.Run("Update", func(t *testing.T) {
resp := c.LicenseApi().UpdateLicense(ctx, testLicenseID, management_request.UpdateLicenseRequest{
MaxActivations: 5,
})
assert.NoError(t, resp.Error)
})
t.Run("List", func(t *testing.T) {
resp := c.LicenseApi().SearchLicenses(ctx, management_request.SearchLicensesRequest{})
assert.NoError(t, resp.Error)
assert.Equal(t, 3, resp.Count)
})
t.Run("Assign", func(t *testing.T) {
resp := c.LicenseApi().AssignUser(ctx, testUserLicenseID, management_request.AssignUserToLicenseRequest{
Email: "[email protected]",
Password: "abcdefgh",
})
assert.NoError(t, resp.Error)
})
t.Run("List", func(t *testing.T) {
resp := c.LicenseApi().ListLicenseUsers(ctx, management_request.SearchUsersRequest{
EmailContains: "[email protected]",
})
assert.NoError(t, resp.Error)
require.Equal(t, 1, resp.Count)
userID = resp.Results[0].Id
})
t.Run("Password", func(t *testing.T) {
resp := c.LicenseApi().SetUserPassword(ctx, userID, management_request.SetPasswordRequest{
Password: "test",
})
assert.NoError(t, resp.Error)
})
t.Run("Unassign", func(t *testing.T) {
resp := c.LicenseApi().UnassignUser(ctx, testUserLicenseID, management_request.UnassignRequest{
LicenseUserId: userID,
})
assert.NoError(t, resp.Error)
})
t.Run("List", func(t *testing.T) {
resp := c.LicenseApi().SearchLicenseCustomFields(ctx, management_request.SearchLicenseCustomFieldsRequest{
License: testLicenseID,
})
require.NoError(t, resp.Error)
require.Equal(t, 1, resp.Count)
id = resp.Results[0].Id
})
t.Run("Get", func(t *testing.T) {
resp := c.LicenseApi().GetLicenseCustomField(ctx, id)
assert.NoError(t, resp.Error)
})
t.Run("Update", func(t *testing.T) {
resp := c.LicenseApi().UpdateLicenseCustomField(ctx, id, management_request.UpdateCustomLicenseFieldRequest{
Value: "test",
})
assert.NoError(t, resp.Error)
})
Go
ctx := context.Background()
t.Run("SearchOrders", func(t *testing.T) {
resp := c.OrderApi().SearchOrders(ctx, management_request.SearchOrdersRequest{})
assert.NoError(t, resp.Error)
})
t.Run("GetOrder", func(t *testing.T) {
resp := c.OrderApi().GetOrder(ctx, orderID)
assert.NoError(t, resp.Error)
})
t.Run("CreateOrder", func(t *testing.T) {
resp := c.OrderApi().CreateOrder(ctx, management_models.WebhookOrder{
Items: []management_models.OrderItem{
{
ProductCode: "code",
Licenses: []management_models.OrderLicense{
{
Key: "key",
},
},
},
},
})
assert.NoError(t, resp.Error)
})
t.Run("ExportToCSV", func(t *testing.T) {
timeStart := time.Now().Add(-5 * time.Hour)
timeEnd := time.Now()
resp := c.OrderApi().ExportToCsv(ctx, timeStart, timeEnd)
assert.NoError(t, resp.Error)
})
t.Run("ExportToCSVRange", func(t *testing.T) {
var r management_models.Range
r = r.Last30()
resp := c.OrderApi().ExportToCsvRange(ctx, r)
assert.NoError(t, resp.Error)
})
t.Run("GenerateLicenseKeys", func(t *testing.T) {
resp := c.OrderApi().GenerateLicenseKeys(ctx, management_request.GenerateLicenseRequest{
Product: "product",
Quantity: 1,
})
assert.NoError(t, resp.Error)
})
t.Run("AddManagerToOrder", func(t *testing.T) {
resp := c.OrderApi().AddManagerToOrder(ctx, orderID, management_request.AddManagerToOrderRequest{
Email: "email",
Password: "password",
})
assert.NoError(t, resp.Error)
})
Go
ctx := context.Background()
t.Run("List", func(t *testing.T) {
resp := c.ProductApi().ListProducts(ctx, management_request.SearchProductsRequest{})
assert.NoError(t, resp.Error)
assert.Equal(t, 2, resp.Count)
})
t.Run("Show", func(t *testing.T) {
resp := c.ProductApi().ShowProduct(ctx, testProductID)
assert.NoError(t, resp.Error)
})
t.Run("Create", func(t *testing.T) {
resp := c.ProductApi().CreateInstallationFile(ctx, management_request.CreateInstallationFileRequest{
FullLink: "link",
Product: testProductID,
Version: "v1",
})
assert.NoError(t, resp.Error)
id = resp.Value.Id
})
t.Run("List", func(t *testing.T) {
resp2 := c.ProductApi().ListInstallationFiles(ctx, management_request.SearchInstallationFilesRequest{
Product: testProductID,
})
assert.NoError(t, resp2.Error)
})
t.Run("Show", func(t *testing.T) {
resp3 := c.ProductApi().ShowInstallationFile(ctx, id)
assert.NoError(t, resp3.Error)
})
t.Run("Create", func(t *testing.T) {
resp := c.ProductApi().CreateProductCustomField(ctx, management_request.CreateProductCustomFieldRequest{
Name: "field",
DefaultValue: "test",
Product: testProductID,
})
assert.NoError(t, resp.Error)
id = resp.Value.Id
})
t.Run("Show1", func(t *testing.T) {
respShow := c.ProductApi().ShowProductCustomField(ctx, id)
assert.NoError(t, respShow.Error)
assert.Equal(t, "test", respShow.Value.DefaultValue)
})
t.Run("Update", func(t *testing.T) {
respUpdate := c.ProductApi().UpdateProductCustomField(ctx, id, management_request.UpdateProductCustomFieldRequest{
Name: "field",
DefaultValue: "abcd",
})
assert.NoError(t, respUpdate.Error)
})
t.Run("Show2", func(t *testing.T) {
respShow := c.ProductApi().ShowProductCustomField(ctx, id)
assert.NoError(t, respShow.Error)
assert.Equal(t, "abcd", respShow.Value.DefaultValue)
})
t.Run("Delete", func(t *testing.T) {
err := c.ProductApi().DeleteProductCustomField(ctx, id)
assert.NoError(t, err)
})
t.Run("List", func(t *testing.T) {
respList := c.ProductApi().ListProductCustomFields(ctx, management_request.SearchProductCustomFieldsRequest{
Product: testProductID,
})
assert.NoError(t, respList.Error)
assert.Equal(t, 1, respList.Count)
})
Updated 05 Sep 2023
Did this page help you?