Skip to content

Commit 0f0d252

Browse files
committed
feat: added func Get AppleCare Coverage Information for a Device with tests and examples
1 parent 645b5ca commit 0f0d252

File tree

12 files changed

+781
-42
lines changed

12 files changed

+781
-42
lines changed

axm/docs/architecture.svg

Lines changed: 1 addition & 1 deletion
Loading

axm/services/devicemanagement/crud.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ type (
1313
// GetDeviceManagementServices retrieves a list of device management services (MDM servers) in an organization
1414
//
1515
// Apple Business Manager API docs:
16-
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-mdm-servers
16+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-device-management-services
1717
GetDeviceManagementServices(ctx context.Context, opts *RequestQueryOptions) (*ResponseMDMServers, error)
1818

19-
// GetMDMServerDeviceLinkages retrieves a list of device IDs assigned to an MDM server
19+
// GetDeviceSerialNumbersForDeviceManagementService retrieves a list of device IDs assigned to an MDM server
2020
//
2121
// Apple Business Manager API docs:
22-
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-all-device-ids-for-a-mdmserver
23-
GetMDMServerDeviceLinkages(ctx context.Context, mdmServerID string, opts *RequestQueryOptions) (*ResponseMDMServerDevicesLinkages, error)
22+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-all-device-ids-for-a-device-management-service
23+
GetDeviceSerialNumbersForDeviceManagementService(ctx context.Context, mdmServerID string, opts *RequestQueryOptions) (*ResponseMDMServerDevicesLinkages, error)
2424

2525
// GetAssignedDeviceManagementServiceIDForADevice retrieves the assigned device management service ID linkage for a device
2626
//
2727
// Apple Business Manager API docs:
28-
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-the-assigned-server-id-for-an-orgdevice
28+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-the-assigned-device-management-service-id-for-an-orgdevice
2929
GetAssignedDeviceManagementServiceIDForADevice(ctx context.Context, deviceID string) (*ResponseOrgDeviceAssignedServerLinkage, error)
3030

3131
// GetAssignedDeviceManagementServiceInformationByDeviceID retrieves the assigned device management service information for a device
3232
//
3333
// Apple Business Manager API docs:
34-
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-the-assigned-server-information-for-an-orgdevice
34+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-the-assigned-device-management-service-information-for-an-orgdevice
3535
GetAssignedDeviceManagementServiceInformationByDeviceID(ctx context.Context, deviceID string, opts *RequestQueryOptions) (*MDMServerResponse, error)
3636

3737
// AssignDevicesToServer assigns devices to an MDM server
@@ -67,7 +67,7 @@ func NewService(client interfaces.HTTPClient) *DeviceManagementService {
6767

6868
// GetDeviceManagementServices retrieves a list of device management services (MDM servers) in an organization
6969
// URL: GET https://api-business.apple.com/v1/mdmServers
70-
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-mdm-servers
70+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-device-management-services
7171
func (s *DeviceManagementService) GetDeviceManagementServices(ctx context.Context, opts *RequestQueryOptions) (*ResponseMDMServers, error) {
7272
if opts == nil {
7373
opts = &RequestQueryOptions{}
@@ -102,10 +102,10 @@ func (s *DeviceManagementService) GetDeviceManagementServices(ctx context.Contex
102102
return &result, nil
103103
}
104104

105-
// GetMDMServerDeviceLinkages retrieves a list of device IDs assigned to an MDM server
105+
// GetDeviceSerialNumbersForDeviceManagementService retrieves a list of device IDs assigned to an MDM server
106106
// URL: GET https://api-business.apple.com/v1/mdmServers/{id}/relationships/devices
107-
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-all-device-ids-for-a-mdmserver
108-
func (s *DeviceManagementService) GetMDMServerDeviceLinkages(ctx context.Context, mdmServerID string, opts *RequestQueryOptions) (*ResponseMDMServerDevicesLinkages, error) {
107+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-all-device-ids-for-a-device-management-service
108+
func (s *DeviceManagementService) GetDeviceSerialNumbersForDeviceManagementService(ctx context.Context, mdmServerID string, opts *RequestQueryOptions) (*ResponseMDMServerDevicesLinkages, error) {
109109
if mdmServerID == "" {
110110
return nil, fmt.Errorf("MDM server ID is required")
111111
}
@@ -142,7 +142,7 @@ func (s *DeviceManagementService) GetMDMServerDeviceLinkages(ctx context.Context
142142

143143
// GetAssignedDeviceManagementServiceIDForADevice retrieves the assigned device management service ID linkage for a device
144144
// URL: GET https://api-business.apple.com/v1/orgDevices/{id}/relationships/assignedServer
145-
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-the-assigned-server-id-for-an-orgdevice
145+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-the-assigned-device-management-service-id-for-an-orgdevice
146146
func (s *DeviceManagementService) GetAssignedDeviceManagementServiceIDForADevice(ctx context.Context, deviceID string) (*ResponseOrgDeviceAssignedServerLinkage, error) {
147147
if deviceID == "" {
148148
return nil, fmt.Errorf("device ID is required")
@@ -166,7 +166,7 @@ func (s *DeviceManagementService) GetAssignedDeviceManagementServiceIDForADevice
166166

167167
// GetAssignedDeviceManagementServiceInformationByDeviceID retrieves the assigned device management service information for a device
168168
// URL: GET https://api-business.apple.com/v1/orgDevices/{id}/assignedServer
169-
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-the-assigned-server-information-for-an-orgdevice
169+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-the-assigned-device-management-service-information-for-an-orgdevice
170170
func (s *DeviceManagementService) GetAssignedDeviceManagementServiceInformationByDeviceID(ctx context.Context, deviceID string, opts *RequestQueryOptions) (*MDMServerResponse, error) {
171171
if deviceID == "" {
172172
return nil, fmt.Errorf("device ID is required")

axm/services/devicemanagement/crud_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func TestGetDeviceManagementServices_HTTPError(t *testing.T) {
152152
assert.Equal(t, 4, httpmock.GetTotalCallCount()) // 1 original + 3 retries
153153
}
154154

155-
func TestGetMDMServerDeviceLinkages_Success(t *testing.T) {
155+
func TestGetDeviceSerialNumbersForDeviceManagementService_Success(t *testing.T) {
156156
client := setupMockClient(t)
157157
mockHandler := &mocks.DeviceManagementMock{}
158158
mockHandler.RegisterMocks()
@@ -164,7 +164,7 @@ func TestGetMDMServerDeviceLinkages_Success(t *testing.T) {
164164
Limit: 100,
165165
}
166166

167-
result, err := client.GetMDMServerDeviceLinkages(ctx, serverID, opts)
167+
result, err := client.GetDeviceSerialNumbersForDeviceManagementService(ctx, serverID, opts)
168168

169169
require.NoError(t, err)
170170
require.NotNil(t, result)
@@ -182,7 +182,7 @@ func TestGetMDMServerDeviceLinkages_Success(t *testing.T) {
182182
assert.Equal(t, 1, httpmock.GetTotalCallCount())
183183
}
184184

185-
func TestGetMDMServerDeviceLinkages_EmptyServerID(t *testing.T) {
185+
func TestGetDeviceSerialNumbersForDeviceManagementService_EmptyServerID(t *testing.T) {
186186
client := setupMockClient(t)
187187
mockHandler := &mocks.DeviceManagementMock{}
188188
mockHandler.RegisterMocks()
@@ -191,7 +191,7 @@ func TestGetMDMServerDeviceLinkages_EmptyServerID(t *testing.T) {
191191
ctx := context.Background()
192192
opts := &RequestQueryOptions{}
193193

194-
result, err := client.GetMDMServerDeviceLinkages(ctx, "", opts)
194+
result, err := client.GetDeviceSerialNumbersForDeviceManagementService(ctx, "", opts)
195195

196196
require.Error(t, err)
197197
assert.Nil(t, result)
@@ -201,7 +201,7 @@ func TestGetMDMServerDeviceLinkages_EmptyServerID(t *testing.T) {
201201
assert.Equal(t, 0, httpmock.GetTotalCallCount())
202202
}
203203

204-
func TestGetMDMServerDeviceLinkages_WithNilOptions(t *testing.T) {
204+
func TestGetDeviceSerialNumbersForDeviceManagementService_WithNilOptions(t *testing.T) {
205205
client := setupMockClient(t)
206206
mockHandler := &mocks.DeviceManagementMock{}
207207
mockHandler.RegisterMocks()
@@ -210,7 +210,7 @@ func TestGetMDMServerDeviceLinkages_WithNilOptions(t *testing.T) {
210210
ctx := context.Background()
211211
serverID := "1F97349736CF4614A94F624E705841AD"
212212

213-
result, err := client.GetMDMServerDeviceLinkages(ctx, serverID, nil)
213+
result, err := client.GetDeviceSerialNumbersForDeviceManagementService(ctx, serverID, nil)
214214

215215
require.NoError(t, err)
216216
require.NotNil(t, result)

axm/services/devices/constants.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,31 @@ const (
6767
ProductFamilyiPhone = "iPhone"
6868
ProductFamilyiPad = "iPad"
6969
ProductFamilyMac = "Mac"
70-
)
70+
)
71+
72+
// AppleCare coverage field constants for field selection
73+
const (
74+
FieldAppleCareStatus = "status"
75+
FieldAppleCarePaymentType = "paymentType"
76+
FieldAppleCareDescription = "description"
77+
FieldAppleCareAgreementNumber = "agreementNumber"
78+
FieldAppleCareStartDateTime = "startDateTime"
79+
FieldAppleCareEndDateTime = "endDateTime"
80+
FieldAppleCareIsRenewable = "isRenewable"
81+
FieldAppleCareIsCanceled = "isCanceled"
82+
FieldAppleCareContractCancelDateTime = "contractCancelDateTime"
83+
)
84+
85+
// AppleCare coverage status constants
86+
const (
87+
AppleCareStatusActive = "ACTIVE"
88+
AppleCareStatusInactive = "INACTIVE"
89+
AppleCareStatusExpired = "EXPIRED"
90+
)
91+
92+
// AppleCare payment type constants
93+
const (
94+
PaymentTypeNone = "NONE"
95+
PaymentTypeSubscription = "SUBSCRIPTION"
96+
PaymentTypeABESubscription = "ABE_SUBSCRIPTION"
97+
)

axm/services/devices/crud.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ type (
2323
// Apple Business Manager API docs:
2424
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-orgdevice-information
2525
GetDeviceInformationByDeviceID(ctx context.Context, deviceID string, opts *RequestQueryOptions) (*OrgDeviceResponse, error)
26+
27+
// GetAppleCareInformationByDeviceID retrieves AppleCare coverage information
28+
// for a specific device.
29+
//
30+
// Apple Business Manager API docs:
31+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-all-apple-care-coverage-for-an-orgdevice
32+
GetAppleCareInformationByDeviceID(ctx context.Context, deviceID string, opts *RequestQueryOptions) (*AppleCareCoverageResponse, error)
2633
}
2734

2835
// DevicetService handles communication with the device
@@ -115,3 +122,45 @@ func (s *DevicesService) GetDeviceInformationByDeviceID(ctx context.Context, dev
115122

116123
return &result, nil
117124
}
125+
126+
// GetAppleCareInformationByDeviceID retrieves AppleCare coverage information for a specific device
127+
// URL: GET https://api-business.apple.com/v1/orgDevices/{id}/appleCareCoverage
128+
// https://developer.apple.com/documentation/applebusinessmanagerapi/get-all-apple-care-coverage-for-an-orgdevice
129+
func (s *DevicesService) GetAppleCareInformationByDeviceID(ctx context.Context, deviceID string, opts *RequestQueryOptions) (*AppleCareCoverageResponse, error) {
130+
if deviceID == "" {
131+
return nil, fmt.Errorf("device ID is required")
132+
}
133+
134+
endpoint := "/orgDevices/" + deviceID + "/appleCareCoverage"
135+
136+
headers := map[string]string{
137+
"Accept": "application/json",
138+
"Content-Type": "application/json",
139+
}
140+
141+
if opts == nil {
142+
opts = &RequestQueryOptions{}
143+
}
144+
145+
queryParams := s.client.QueryBuilder()
146+
147+
if len(opts.Fields) > 0 {
148+
queryParams.AddStringSlice("fields[appleCareCoverage]", opts.Fields)
149+
}
150+
151+
if opts.Limit > 0 {
152+
if opts.Limit > 1000 {
153+
opts.Limit = 1000 // Enforce API maximum
154+
}
155+
queryParams.AddInt("limit", opts.Limit)
156+
}
157+
158+
var result AppleCareCoverageResponse
159+
160+
err := s.client.GetPaginated(ctx, endpoint, queryParams.Build(), headers, &result)
161+
if err != nil {
162+
return nil, err
163+
}
164+
165+
return &result, nil
166+
}

0 commit comments

Comments
 (0)