|
| 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 |
0 commit comments