Skip to content

Commit 1033b91

Browse files
committed
feat: added v3 for testing
1 parent 4a584fe commit 1033b91

File tree

19 files changed

+3118
-0
lines changed

19 files changed

+3118
-0
lines changed

v3/README.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Apple Business Manager API SDK v3
2+
3+
A completely refactored Go SDK for the Apple Business Manager API with direct service access and no wrappers.
4+
5+
## Key V3 Features
6+
7+
**No Wrappers** - Direct service access without intermediate client layers
8+
**Clean API** - `client.Service.Method()` pattern
9+
**Type Safety** - Full type safety with proper interfaces
10+
**Preserved Functionality** - All original CRUD methods and comments maintained
11+
**Integrated Pagination** - Pagination logic moved into CRUD functions where appropriate
12+
13+
## Architecture
14+
15+
```
16+
v3/
17+
├── client/ # Core HTTP client and shared utilities
18+
├── devicemanagement/ # Device management service (no wrappers)
19+
├── devices/ # Devices service (no wrappers)
20+
└── examples/ # Updated examples
21+
```
22+
23+
## Usage
24+
25+
### Before (V2 - Unwanted Pattern)
26+
```go
27+
// V2 pattern with wrapper clients
28+
axmClient, _ := axm.NewClient(config)
29+
dmClient := devicemanagement.NewClient(axmClient) // Wrapper!
30+
devicesClient := devices.NewClient(axmClient) // Wrapper!
31+
32+
response, err := dmClient.GetDeviceManagementServices(ctx, opts)
33+
```
34+
35+
### After (V3 - Target Pattern)
36+
```go
37+
// V3 pattern with direct service access
38+
client, err := axm.NewClient(config)
39+
40+
// Direct access - no wrappers!
41+
response, err := client.DeviceManagement.GetDeviceManagementServices(ctx, opts)
42+
devices, err := client.Devices.GetOrganizationDevices(ctx, opts)
43+
```
44+
45+
## Quick Start
46+
47+
```go
48+
package main
49+
50+
import (
51+
"context"
52+
53+
axm "github.com/deploymenttheory/go-api-sdk-apple/v3"
54+
"github.com/deploymenttheory/go-api-sdk-apple/v3/devices"
55+
)
56+
57+
func main() {
58+
// Parse your private key
59+
privateKey, err := axm.ParsePrivateKey([]byte(privateKeyPEM))
60+
if err != nil {
61+
panic(err)
62+
}
63+
64+
// Create client with embedded services
65+
client, err := axm.NewClientBuilder().
66+
WithJWTAuth(keyID, issuerID, privateKey).
67+
WithDebug(true).
68+
Build()
69+
if err != nil {
70+
panic(err)
71+
}
72+
73+
ctx := context.Background()
74+
75+
// Direct service access - no wrappers needed!
76+
devicesResponse, err := client.Devices.GetOrganizationDevices(ctx, &devices.GetOrganizationDevicesOptions{
77+
Fields: []string{
78+
devices.FieldSerialNumber,
79+
devices.FieldDeviceModel,
80+
devices.FieldStatus,
81+
},
82+
Limit: 10,
83+
})
84+
85+
// Direct device management access
86+
servers, err := client.DeviceManagement.GetDeviceManagementServices(ctx, nil)
87+
88+
// Chain service calls naturally
89+
for _, device := range devicesResponse.Data {
90+
assigned, err := client.DeviceManagement.GetAssignedDeviceManagementServiceIDForADevice(ctx, device.ID)
91+
// ... handle assigned server
92+
}
93+
}
94+
```
95+
96+
## Available Services
97+
98+
### Device Management (`client.DeviceManagement`)
99+
- `GetDeviceManagementServices()` - Get MDM servers
100+
- `GetMDMServerDeviceLinkages()` - Get device linkages for MDM server
101+
- `GetAssignedDeviceManagementServiceIDForADevice()` - Get assigned server ID for device
102+
- `GetAssignedDeviceManagementServiceInformationByDeviceID()` - Get assigned server info
103+
- `AssignDevicesToServer()` - Assign devices to MDM server
104+
- `UnassignDevicesFromServer()` - Unassign devices from MDM server
105+
106+
### Devices (`client.Devices`)
107+
- `GetOrganizationDevices()` - Get organization devices
108+
- `GetDeviceInformationByDeviceID()` - Get specific device information
109+
110+
## Authentication
111+
112+
Same authentication as V2, but with cleaner builder pattern:
113+
114+
```go
115+
client, err := axm.NewClientBuilder().
116+
WithJWTAuth(keyID, issuerID, privateKey).
117+
WithBaseURL("https://api-business.apple.com/v1").
118+
WithTimeout(30 * time.Second).
119+
WithRetry(3, time.Second).
120+
WithDebug(true).
121+
Build()
122+
```
123+
124+
## Migration from V2
125+
126+
1. Update imports:
127+
```go
128+
// Old
129+
import "github.com/deploymenttheory/go-api-sdk-apple/client/axm"
130+
import "github.com/deploymenttheory/go-api-sdk-apple/services/axm/devicemanagement"
131+
132+
// New
133+
import axm "github.com/deploymenttheory/go-api-sdk-apple/v3"
134+
```
135+
136+
2. Replace wrapper clients:
137+
```go
138+
// Old
139+
axmClient, _ := axm.NewClient(config)
140+
dmClient := devicemanagement.NewClient(axmClient)
141+
response, _ := dmClient.GetDeviceManagementServices(ctx, opts)
142+
143+
// New
144+
client, _ := axm.NewClient(config)
145+
response, _ := client.DeviceManagement.GetDeviceManagementServices(ctx, opts)
146+
```
147+
148+
3. All method signatures and functionality remain identical - only the access pattern changes!
149+
150+
## Why V3?
151+
152+
- **Eliminates Complexity**: No need to manage multiple client instances
153+
- **Improves DX**: Intuitive `client.service.method()` pattern
154+
- **Type Safety**: Proper interfaces without wrapper overhead
155+
- **Maintains Compatibility**: All existing CRUD methods preserved
156+
- **Better Performance**: Removes unnecessary abstraction layers
157+
- **Cleaner Code**: Less boilerplate, more focus on business logic
158+
159+
## Examples
160+
161+
See `examples/` directory for complete working examples demonstrating:
162+
- Direct service access patterns
163+
- Mixed service operations
164+
- Error handling
165+
- Pagination usage
166+
- Authentication setup

v3/client.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package axm
2+
3+
import (
4+
core "github.com/deploymenttheory/go-api-sdk-apple/v3/core"
5+
"github.com/deploymenttheory/go-api-sdk-apple/v3/devicemanagement"
6+
"github.com/deploymenttheory/go-api-sdk-apple/v3/devices"
7+
)
8+
9+
// Client provides unified access to all Apple Business Manager API services
10+
// This eliminates the need for wrapper clients and provides direct service access
11+
type Client struct {
12+
*core.Client
13+
DeviceManagement *devicemanagement.Service
14+
Devices *devices.Service
15+
}
16+
17+
// NewClient creates a new unified client with all services embedded
18+
func NewClient(config core.Config) (*Client, error) {
19+
coreClient, err := core.NewClient(config)
20+
if err != nil {
21+
return nil, err
22+
}
23+
24+
return &Client{
25+
Client: coreClient,
26+
DeviceManagement: devicemanagement.NewService(coreClient),
27+
Devices: devices.NewService(coreClient),
28+
}, nil
29+
}
30+
31+
// NewClientBuilder returns a new client builder for fluent configuration
32+
func NewClientBuilder() *core.ClientBuilder {
33+
return core.NewClientBuilder()
34+
}
35+
36+
// NewClientFromEnv creates a client using environment variables
37+
func NewClientFromEnv() (*Client, error) {
38+
coreClient, err := core.NewClientFromEnv()
39+
if err != nil {
40+
return nil, err
41+
}
42+
43+
return &Client{
44+
Client: coreClient,
45+
DeviceManagement: devicemanagement.NewService(coreClient),
46+
Devices: devices.NewService(coreClient),
47+
}, nil
48+
}
49+
50+
// NewClientFromFile creates a client using credentials from files
51+
func NewClientFromFile(keyID, issuerID, privateKeyPath string) (*Client, error) {
52+
coreClient, err := core.NewClientFromFile(keyID, issuerID, privateKeyPath)
53+
if err != nil {
54+
return nil, err
55+
}
56+
57+
return &Client{
58+
Client: coreClient,
59+
DeviceManagement: devicemanagement.NewService(coreClient),
60+
Devices: devices.NewService(coreClient),
61+
}, nil
62+
}
63+
64+
// Crypto functions exported from core
65+
var (
66+
LoadPrivateKeyFromFile = core.LoadPrivateKeyFromFile
67+
ParsePrivateKey = core.ParsePrivateKey
68+
ValidatePrivateKey = core.ValidatePrivateKey
69+
)
70+
71+
// Config type exported from core
72+
type Config = core.Config
73+
74+
// NewClientWithBuilder creates a client using the builder pattern
75+
func NewClientWithBuilder() *core.ClientBuilder {
76+
return core.NewClientBuilder()
77+
}
78+
79+
// BuildClient creates a unified client from a configured builder
80+
func BuildClient(builder *core.ClientBuilder) (*Client, error) {
81+
coreClient, err := builder.Build()
82+
if err != nil {
83+
return nil, err
84+
}
85+
86+
return &Client{
87+
Client: coreClient,
88+
DeviceManagement: devicemanagement.NewService(coreClient),
89+
Devices: devices.NewService(coreClient),
90+
}, nil
91+
}

0 commit comments

Comments
 (0)