SDKs
Go SDK
Management Client
8min
Go
1import(
2 "gitlab.com/l3178/sdk-go/management_client"
3 management_request "gitlab.com/l3178/sdk-go/management_client/models/request"
4)
Go
1config := management_client.NewManagementClientConfiguration("managementKey")
2c := management_client.NewManagementClient(config)
Go
1ctx := context.Background()
2
3t.Run("Create", func(t *testing.T) {
4 resp := c.CustomerApi().CreateCustomer(ctx, management_request.CreateCustomerRequest{
5 Email: "[email protected]",
6 FirstName: "Test",
7 })
8 require.NoError(t, resp.Error)
9 id = resp.Value.Id
10})
11
12t.Run("List", func(t *testing.T) {
13 resp := c.CustomerApi().ListCustomers(ctx, management_request.SearchCustomersRequest{
14 Email: "[email protected]",
15 })
16 assert.NoError(t, resp.Error)
17 assert.Equal(t, 1, resp.Count)
18})
19
20t.Run("Edit", func(t *testing.T) {
21 resp := c.CustomerApi().EditCustomer(ctx, id, management_request.CreateCustomerRequest{
22 LastName: "abcd",
23 })
24 assert.NoError(t, resp.Error)
25})
26
27t.Run("Get", func(t *testing.T) {
28 resp := c.CustomerApi().ShowCustomer(ctx, id)
29 assert.NoError(t, resp.Error)
30 assert.Equal(t, "abcd", resp.Value.LastName)
31})
32
33t.Run("Delete", func(t *testing.T) {
34 err := c.CustomerApi().DeleteCustomer(ctx, id)
35 assert.NoError(t, err)
36})
37
38t.Run("Create", func(t *testing.T) {
39 resp := c.CustomerApi().CreateCustomerLabel(ctx, management_request.CreateCustomerLabelRequest{
40 Label: "abcd",
41 Color: "efgh",
42 })
43 require.NoError(t, resp.Error)
44 id = resp.Value.Id
45})
46
47t.Run("List", func(t *testing.T) {
48 resp := c.CustomerApi().ListCustomerLabels(ctx, management_request.SearchRequest{})
49 assert.NoError(t, resp.Error)
50 assert.Equal(t, 1, resp.Count)
51})
52
53t.Run("Edit", func(t *testing.T) {
54 resp := c.CustomerApi().EditCustomerLabel(ctx, id, management_request.CreateCustomerLabelRequest{
55 Color: "1234",
56 })
57 assert.NoError(t, resp.Error)
58})
59
60t.Run("Get", func(t *testing.T) {
61 resp := c.CustomerApi().ShowCustomerLabel(ctx, id)
62 assert.NoError(t, resp.Error)
63 assert.Equal(t, "1234", resp.Value.Color)
64})
65
66t.Run("Delete", func(t *testing.T) {
67 err := c.CustomerApi().DeleteCustomerLabel(ctx, id)
68 assert.NoError(t, err)
69})
70
71t.Run("Create", func(t *testing.T) {
72 resp := c.CustomerApi().CreateCustomerAccount(ctx, management_request.CreateCustomerAccountRequest{
73 Code: "abcd",
74 Name: "efgh",
75 })
76 require.NoError(t, resp.Error)
77 id = resp.Value.Id
78})
79
80t.Run("List", func(t *testing.T) {
81 resp := c.CustomerApi().ListCustomerAccounts(ctx, management_request.SearchRequest{})
82 assert.NoError(t, resp.Error)
83 assert.Equal(t, 1, resp.Count)
84})
85
86t.Run("Edit", func(t *testing.T) {
87 resp := c.CustomerApi().EditCustomerAccount(ctx, id, management_request.CreateCustomerAccountRequest{
88 Description: "test",
89 })
90 assert.NoError(t, resp.Error)
91})
92
93t.Run("Get", func(t *testing.T) {
94 resp := c.CustomerApi().ShowCustomerAccount(ctx, id)
95 assert.NoError(t, resp.Error)
96 assert.Equal(t, "test", resp.Value.Description)
97})
98
99t.Run("Delete", func(t *testing.T) {
100 err := c.CustomerApi().DeleteCustomerAccount(ctx, id)
101 assert.NoError(t, err)
102})
Go
1ctx := context.Background()
2
3t.Run("SearchDevices", func(t *testing.T) {
4 resp := c.DeviceApi().ListDevices(ctx, management_request.SearchDevicesRequest{
5 License: testLicenseID,
6 })
7 assert.NoError(t, resp.Error)
8})
9
10t.Run("ShowDevice", func(t *testing.T) {
11 c.DeviceApi().ShowDevice(ctx, deviceID)
12})
13
14t.Run("ResetDevice", func(t *testing.T) {
15 c.DeviceApi().ResetDevice(ctx, deviceID)
16})
17
18t.Run("BlacklistDevice", func(t *testing.T) {
19 c.DeviceApi().BlacklistDevice(ctx, deviceID)
20})
21
22t.Run("CreateDeviceVariable", func(t *testing.T) {
23 resp := c.DeviceApi().CreateDeviceVariable(ctx, management_request.CreateDeviceVariableRequest{
24 Variable: "test",
25 Value: "value",
26 Device: deviceID,
27 })
28 assert.NoError(t, resp.Error)
29})
30
31t.Run("UpdateDeviceVariable", func(t *testing.T) {
32 resp := c.DeviceApi().UpdateDeviceVariable(ctx, deviceID, management_request.UpdateDeviceVariableRequest{
33 Variable: "test",
34 Value: "value",
35 })
36 assert.NoError(t, resp.Error)
37})
38
39t.Run("DeleteDeviceVariable", func(t *testing.T) {
40 err := c.DeviceApi().DeleteDeviceVariable(ctx, deviceID)
41 assert.NoError(t, err)
42})
43
44t.Run("SearchDeviceVariable", func(t *testing.T) {
45 resp := c.DeviceApi().ListDeviceVariables(ctx, management_request.SearchDeviceVariablesRequest{
46 Device: deviceID,
47 })
48 assert.NoError(t, resp.Error)
49})
50
51t.Run("ShowDeviceVariable", func(t *testing.T) {
52 resp := c.DeviceApi().ShowDeviceVariable(ctx, deviceID)
53 assert.NoError(t, resp.Error)
54})
Go
1ctx := context.Background()
2
3t.Run("Disable", func(t *testing.T) {
4 resp := c.LicenseApi().DisableLicense(ctx, testLicenseID)
5 assert.NoError(t, resp.Error)
6})
7
8t.Run("Get", func(t *testing.T) {
9 resp := c.LicenseApi().GetLicense(ctx, testLicenseID)
10 assert.NoError(t, resp.Error)
11 assert.False(t, resp.Value.Enabled)
12})
13
14t.Run("Enable", func(t *testing.T) {
15 resp := c.LicenseApi().EnableLicense(ctx, testLicenseID)
16 assert.NoError(t, resp.Error)
17})
18
19t.Run("Update", func(t *testing.T) {
20 resp := c.LicenseApi().UpdateLicense(ctx, testLicenseID, management_request.UpdateLicenseRequest{
21 MaxActivations: 5,
22 })
23 assert.NoError(t, resp.Error)
24})
25
26t.Run("List", func(t *testing.T) {
27 resp := c.LicenseApi().SearchLicenses(ctx, management_request.SearchLicensesRequest{})
28 assert.NoError(t, resp.Error)
29 assert.Equal(t, 3, resp.Count)
30})
31
32t.Run("Assign", func(t *testing.T) {
33 resp := c.LicenseApi().AssignUser(ctx, testUserLicenseID, management_request.AssignUserToLicenseRequest{
34 Email: "[email protected]",
35 Password: "abcdefgh",
36 })
37 assert.NoError(t, resp.Error)
38})
39
40t.Run("List", func(t *testing.T) {
41 resp := c.LicenseApi().ListLicenseUsers(ctx, management_request.SearchUsersRequest{
42 EmailContains: "[email protected]",
43 })
44 assert.NoError(t, resp.Error)
45 require.Equal(t, 1, resp.Count)
46 userID = resp.Results[0].Id
47})
48
49t.Run("Password", func(t *testing.T) {
50 resp := c.LicenseApi().SetUserPassword(ctx, userID, management_request.SetPasswordRequest{
51 Password: "test",
52 })
53 assert.NoError(t, resp.Error)
54})
55
56t.Run("Unassign", func(t *testing.T) {
57 resp := c.LicenseApi().UnassignUser(ctx, testUserLicenseID, management_request.UnassignRequest{
58 LicenseUserId: userID,
59 })
60 assert.NoError(t, resp.Error)
61})
62
63t.Run("List", func(t *testing.T) {
64 resp := c.LicenseApi().SearchLicenseCustomFields(ctx, management_request.SearchLicenseCustomFieldsRequest{
65 License: testLicenseID,
66 })
67 require.NoError(t, resp.Error)
68 require.Equal(t, 1, resp.Count)
69 id = resp.Results[0].Id
70})
71
72t.Run("Get", func(t *testing.T) {
73 resp := c.LicenseApi().GetLicenseCustomField(ctx, id)
74 assert.NoError(t, resp.Error)
75})
76
77t.Run("Update", func(t *testing.T) {
78 resp := c.LicenseApi().UpdateLicenseCustomField(ctx, id, management_request.UpdateCustomLicenseFieldRequest{
79 Value: "test",
80 })
81 assert.NoError(t, resp.Error)
82})
Go
1ctx := context.Background()
2
3t.Run("SearchOrders", func(t *testing.T) {
4 resp := c.OrderApi().SearchOrders(ctx, management_request.SearchOrdersRequest{})
5 assert.NoError(t, resp.Error)
6})
7
8t.Run("GetOrder", func(t *testing.T) {
9 resp := c.OrderApi().GetOrder(ctx, orderID)
10 assert.NoError(t, resp.Error)
11})
12
13t.Run("CreateOrder", func(t *testing.T) {
14 resp := c.OrderApi().CreateOrder(ctx, management_models.WebhookOrder{
15 Items: []management_models.OrderItem{
16 {
17 ProductCode: "code",
18 Licenses: []management_models.OrderLicense{
19 {
20 Key: "key",
21 },
22 },
23 },
24 },
25 })
26 assert.NoError(t, resp.Error)
27})
28
29t.Run("ExportToCSV", func(t *testing.T) {
30 timeStart := time.Now().Add(-5 * time.Hour)
31 timeEnd := time.Now()
32 resp := c.OrderApi().ExportToCsv(ctx, timeStart, timeEnd)
33 assert.NoError(t, resp.Error)
34})
35
36t.Run("ExportToCSVRange", func(t *testing.T) {
37 var r management_models.Range
38 r = r.Last30()
39 resp := c.OrderApi().ExportToCsvRange(ctx, r)
40 assert.NoError(t, resp.Error)
41})
42
43t.Run("GenerateLicenseKeys", func(t *testing.T) {
44 resp := c.OrderApi().GenerateLicenseKeys(ctx, management_request.GenerateLicenseRequest{
45 Product: "product",
46 Quantity: 1,
47 })
48 assert.NoError(t, resp.Error)
49})
50
51t.Run("AddManagerToOrder", func(t *testing.T) {
52 resp := c.OrderApi().AddManagerToOrder(ctx, orderID, management_request.AddManagerToOrderRequest{
53 Email: "email",
54 Password: "password",
55 })
56 assert.NoError(t, resp.Error)
57})
Go
1ctx := context.Background()
2
3t.Run("List", func(t *testing.T) {
4 resp := c.ProductApi().ListProducts(ctx, management_request.SearchProductsRequest{})
5 assert.NoError(t, resp.Error)
6 assert.Equal(t, 2, resp.Count)
7})
8
9t.Run("Show", func(t *testing.T) {
10 resp := c.ProductApi().ShowProduct(ctx, testProductID)
11 assert.NoError(t, resp.Error)
12})
13
14t.Run("Create", func(t *testing.T) {
15 resp := c.ProductApi().CreateInstallationFile(ctx, management_request.CreateInstallationFileRequest{
16 FullLink: "link",
17 Product: testProductID,
18 Version: "v1",
19 })
20 assert.NoError(t, resp.Error)
21 id = resp.Value.Id
22})
23
24t.Run("List", func(t *testing.T) {
25 resp2 := c.ProductApi().ListInstallationFiles(ctx, management_request.SearchInstallationFilesRequest{
26 Product: testProductID,
27 })
28 assert.NoError(t, resp2.Error)
29})
30
31t.Run("Show", func(t *testing.T) {
32 resp3 := c.ProductApi().ShowInstallationFile(ctx, id)
33 assert.NoError(t, resp3.Error)
34})
35
36t.Run("Create", func(t *testing.T) {
37 resp := c.ProductApi().CreateProductCustomField(ctx, management_request.CreateProductCustomFieldRequest{
38 Name: "field",
39 DefaultValue: "test",
40 Product: testProductID,
41 })
42 assert.NoError(t, resp.Error)
43 id = resp.Value.Id
44})
45
46t.Run("Show1", func(t *testing.T) {
47 respShow := c.ProductApi().ShowProductCustomField(ctx, id)
48 assert.NoError(t, respShow.Error)
49 assert.Equal(t, "test", respShow.Value.DefaultValue)
50})
51
52t.Run("Update", func(t *testing.T) {
53 respUpdate := c.ProductApi().UpdateProductCustomField(ctx, id, management_request.UpdateProductCustomFieldRequest{
54 Name: "field",
55 DefaultValue: "abcd",
56 })
57 assert.NoError(t, respUpdate.Error)
58})
59
60t.Run("Show2", func(t *testing.T) {
61 respShow := c.ProductApi().ShowProductCustomField(ctx, id)
62 assert.NoError(t, respShow.Error)
63 assert.Equal(t, "abcd", respShow.Value.DefaultValue)
64})
65
66t.Run("Delete", func(t *testing.T) {
67 err := c.ProductApi().DeleteProductCustomField(ctx, id)
68 assert.NoError(t, err)
69})
70
71t.Run("List", func(t *testing.T) {
72 respList := c.ProductApi().ListProductCustomFields(ctx, management_request.SearchProductCustomFieldsRequest{
73 Product: testProductID,
74 })
75 assert.NoError(t, respList.Error)
76 assert.Equal(t, 1, respList.Count)
77})
Updated 05 Sep 2023
Did this page help you?