Skip to content

Commit 6d71b2d

Browse files
committed
Improve models
Reworked documentation to reflect the current state of the Framework. Added basic init for all objects. Added default values for all properties.
1 parent 4295951 commit 6d71b2d

File tree

65 files changed

+913
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+913
-308
lines changed

JamfKit/JamfKit.xcodeproj/project.pbxproj

+8-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
ED3E04811FFCCA58001600CA /* NetworkSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED3E047F1FFCCA58001600CA /* NetworkSegment.swift */; };
9898
ED3E04831FFCCDAD001600CA /* NetworkSegmentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED3E04821FFCCDAD001600CA /* NetworkSegmentTests.swift */; };
9999
ED3E04841FFCCDAD001600CA /* NetworkSegmentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED3E04821FFCCDAD001600CA /* NetworkSegmentTests.swift */; };
100+
ED406202203D81BA008B4B6A /* HardwareGroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED406201203D81BA008B4B6A /* HardwareGroupTests.swift */; };
101+
ED406203203D81BA008B4B6A /* HardwareGroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED406201203D81BA008B4B6A /* HardwareGroupTests.swift */; };
100102
ED47ED1220206B3A00AF1BF6 /* SessionManagerError.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED47ED1120206B3A00AF1BF6 /* SessionManagerError.swift */; };
101103
ED47ED1320206B3A00AF1BF6 /* SessionManagerError.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED47ED1120206B3A00AF1BF6 /* SessionManagerError.swift */; };
102104
ED47ED1520206FBC00AF1BF6 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED47ED1420206FBC00AF1BF6 /* Constants.swift */; };
@@ -291,6 +293,7 @@
291293
ED3597821FAA11B6006E3B66 /* JSONHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = "<group>"; };
292294
ED3E047F1FFCCA58001600CA /* NetworkSegment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NetworkSegment.swift; path = ../../../JamfKit/Sources/Models/NetworkSegment.swift; sourceTree = "<group>"; };
293295
ED3E04821FFCCDAD001600CA /* NetworkSegmentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkSegmentTests.swift; sourceTree = "<group>"; };
296+
ED406201203D81BA008B4B6A /* HardwareGroupTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HardwareGroupTests.swift; sourceTree = "<group>"; };
294297
ED47ED1120206B3A00AF1BF6 /* SessionManagerError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionManagerError.swift; sourceTree = "<group>"; };
295298
ED47ED1420206FBC00AF1BF6 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
296299
ED4C59051FFE3CCE00E84A25 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
@@ -516,10 +519,10 @@
516519
ED1D93061FA20F49005589F5 /* Protocols */ = {
517520
isa = PBXGroup;
518521
children = (
519-
ED3441882036E50E0078450E /* Requests */,
522+
EDB331912036D1DF00F43D31 /* Endpoint.swift */,
520523
EDB3318E2036D0B500F43D31 /* Identifiable.swift */,
521524
ED21F25B2020D89600E4F852 /* Requestable.swift */,
522-
EDB331912036D1DF00F43D31 /* Endpoint.swift */,
525+
ED3441882036E50E0078450E /* Requests */,
523526
EDE3AA25203C863F00ABB163 /* Subset.swift */,
524527
);
525528
path = Protocols;
@@ -816,6 +819,7 @@
816819
isa = PBXGroup;
817820
children = (
818821
ED2DF2A92000213500FD0A30 /* HardwareGroupCriterionTests.swift */,
822+
ED406201203D81BA008B4B6A /* HardwareGroupTests.swift */,
819823
);
820824
path = HardwareGroup;
821825
sourceTree = "<group>";
@@ -1155,6 +1159,7 @@
11551159
EDA3CFD51FFC195100B22D36 /* SMTPServerTests.swift in Sources */,
11561160
ED1D93111FA20FB9005589F5 /* BaseObjectTests.swift in Sources */,
11571161
ED3441BB20370CE20078450E /* MobileDeviceRequestsTests.swift in Sources */,
1162+
ED406202203D81BA008B4B6A /* HardwareGroupTests.swift in Sources */,
11581163
ED3441A62036EF0C0078450E /* ComputerRequestsTests.swift in Sources */,
11591164
EDB9B9621FFF9BB500287739 /* PolicyGeneralTests.swift in Sources */,
11601165
EDF70B7020076079006B5DFF /* SessionManagerRequestsTests.swift in Sources */,
@@ -1273,6 +1278,7 @@
12731278
EDA3CFD61FFC195100B22D36 /* SMTPServerTests.swift in Sources */,
12741279
ED1D93101FA20FB9005589F5 /* BaseObjectTests.swift in Sources */,
12751280
ED3441BC20370CE20078450E /* MobileDeviceRequestsTests.swift in Sources */,
1281+
ED406203203D81BA008B4B6A /* HardwareGroupTests.swift in Sources */,
12761282
ED3441A72036EF0C0078450E /* ComputerRequestsTests.swift in Sources */,
12771283
EDB9B9631FFF9BB500287739 /* PolicyGeneralTests.swift in Sources */,
12781284
EDF70B7120076079006B5DFF /* SessionManagerRequestsTests.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//: [Previous](@previous)
2+
3+
//: # JamfKit - Requests
4+
5+
//: 1. Import JamfKit
6+
7+
import JamfKit
8+
9+
//: 2. Instantiate any class you need for your current usage
10+
11+
let building = Building(identifier: 12345, name: "Building")
12+
let computer = Computer(identifier: 12345, name: "Computer")
13+
let computerCommand = ComputerCommand(command: "Command", passcode: 12345)
14+
let computerConfiguration = ComputerConfiguration(identifier: 12345, name: "Computer configuration")
15+
let computerGroup = ComputerGroup(identifier: 12345, name: "Computer group")
16+
let department = Department(identifier: 12345, name: "Department")
17+
let directoryBinding = DirectoryBinding(identifier: 12345, name: "Directory binding")
18+
let mobileDevice = MobileDevice(identifier: 12345, name: "Mobile device")
19+
let mobileDeviceGroup = MobileDeviceGroup(identifier: 12345, name: "Mobile device group")
20+
let netbootServer = NetbootServer(identifier: 12345, name: "Netboot server")
21+
let networkSegment = NetworkSegment(identifier: 12345, name: "Network segment")
22+
let package = Package(identifier: 12345, name: "Package")
23+
let partition = Partition(name: "Partition")
24+
let policy = Policy(identifier: 12345, name: "Policy")
25+
let printer = Printer(identifier: 12345, name: "Printer")
26+
let script = Script(identifier: 12345, name: "Script")
27+
let site = Site(identifier: 12345, name: "Site")
28+
let smtpServer = SMTPServer(host: "127.0.0.1", port: 1234)
29+
let user = User(identifier: 12345, name: "User")
30+
31+
//: [Next](@next)

JamfKit/Playgrounds/Examples.playground/Pages/Summary.xcplaygroundpage/Contents.swift

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
//: You'll find below the summary of the available Playgrounds to get you started with `JamfKit`.
44

5+
//: [Classes](Classes)
6+
57
//: [Requests](Requests)

JamfKit/Playgrounds/Examples.playground/contents.xcplayground

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<playground version='6.0' target-platform='ios' display-mode='raw'>
33
<pages>
44
<page name='Summary'/>
5+
<page name='Classes'/>
56
<page name='Requests'/>
67
</pages>
78
</playground>

JamfKit/Sources/Models/BaseObject.swift

+12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public class BaseObject: NSObject, Requestable, Identifiable {
4444
self.name = name
4545
}
4646

47+
@objc
48+
public init?(identifier: UInt, name: String) {
49+
guard !name.isEmpty else {
50+
return nil
51+
}
52+
53+
self.identifier = identifier
54+
self.name = name
55+
56+
super.init()
57+
}
58+
4759
// MARK: - Functions
4860

4961
@objc

JamfKit/Sources/Models/Computer/Computer.swift

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ public final class Computer: NSObject, Requestable, Endpoint, Subset {
5353
}
5454
}
5555

56+
public init?(identifier: UInt, name: String) {
57+
guard let general = ComputerGeneral(identifier: identifier, name: name) else {
58+
return nil
59+
}
60+
61+
self.general = general
62+
location = ComputerLocation()
63+
purchasing = ComputerPurchasing()
64+
65+
super.init()
66+
}
67+
5668
// MARK: - Functions
5769

5870
public func toJSON() -> [String: Any] {

JamfKit/Sources/Models/Computer/ComputerGeneral.swift

+23-17
Original file line numberDiff line numberDiff line change
@@ -40,46 +40,46 @@ public final class ComputerGeneral: BaseObject {
4040
// MARK: - Properties
4141

4242
@objc
43-
public var macAddress: String
43+
public var macAddress = ""
4444

4545
@objc
46-
public var alternativeMacAddress: String
46+
public var alternativeMacAddress = ""
4747

4848
@objc
49-
public var ipAddress: String
49+
public var ipAddress = ""
5050

5151
@objc
52-
public var lastReportedIpAddress: String
52+
public var lastReportedIpAddress = ""
5353

5454
@objc
55-
public var serialNumber: String
55+
public var serialNumber = ""
5656

5757
@objc
58-
public var udid: String
58+
public var udid = ""
5959

6060
@objc
61-
public var jamfVersion: String
61+
public var jamfVersion = ""
6262

6363
@objc
64-
public var platform: String
64+
public var platform = ""
6565

6666
@objc
67-
public var barcode1: String
67+
public var barcode1 = ""
6868

6969
@objc
70-
public var barcode2: String
70+
public var barcode2 = ""
7171

7272
@objc
73-
public var assetTag: String
73+
public var assetTag = ""
7474

7575
@objc
7676
public var remoteManagement: ComputerRemoteManagement?
7777

7878
@objc
79-
public var isMdmCapable: Bool
79+
public var isMdmCapable = false
8080

8181
@objc
82-
public var mdmCapableUsers: [String]
82+
public var mdmCapableUsers = [String]()
8383

8484
@objc
8585
public var reportDate: PreciseDate?
@@ -97,19 +97,19 @@ public final class ComputerGeneral: BaseObject {
9797
public var lastEnrolledDate: PreciseDate?
9898

9999
@objc
100-
public var distributionPoint: String
100+
public var distributionPoint = ""
101101

102102
@objc
103-
public var sus: String
103+
public var sus = ""
104104

105105
@objc
106-
public var netbootServer: String
106+
public var netbootServer = ""
107107

108108
@objc
109109
public var site: Site?
110110

111111
@objc
112-
public var isITunesStoreAcccountActivated: Bool
112+
public var isITunesStoreAcccountActivated = false
113113

114114
// MARK: - Initialization
115115

@@ -142,6 +142,12 @@ public final class ComputerGeneral: BaseObject {
142142
super.init(json: json)
143143
}
144144

145+
public override init?(identifier: UInt, name: String) {
146+
remoteManagement = ComputerRemoteManagement()
147+
148+
super.init(identifier: identifier, name: name)
149+
}
150+
145151
// MARK: - Functions
146152

147153
public override func toJSON() -> [String: Any] {

JamfKit/Sources/Models/Computer/ComputerLocation.swift

+12-8
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ public final class ComputerLocation: NSObject, Requestable {
2323
// MARK: - Properties
2424

2525
@objc
26-
public var username: String
26+
public var username = ""
2727

2828
@objc
29-
public var realName: String
29+
public var realName = ""
3030

3131
@objc
32-
public var emailAddress: String
32+
public var emailAddress = ""
3333

3434
@objc
35-
public var position: String
35+
public var position = ""
3636

3737
@objc
38-
public var phoneNumber: String
38+
public var phoneNumber = ""
3939

4040
@objc
41-
public var department: String
41+
public var department = ""
4242

4343
@objc
44-
public var building: String
44+
public var building = ""
4545

4646
@objc
47-
public var room: UInt
47+
public var room: UInt = 0
4848

4949
// MARK: - Initialization
5050

@@ -59,6 +59,10 @@ public final class ComputerLocation: NSObject, Requestable {
5959
room = json[ComputerLocation.RoomKey] as? UInt ?? 0
6060
}
6161

62+
public override init() {
63+
super.init()
64+
}
65+
6266
// MARK: - Functions
6367

6468
public func toJSON() -> [String: Any] {

JamfKit/Sources/Models/Computer/ComputerPurchasing.swift

+13-9
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,28 @@ public final class ComputerPurchasing: NSObject, Requestable {
2727
// MARK: - Properties
2828

2929
@objc
30-
public var isPurchased: Bool
30+
public var isPurchased = false
3131

3232
@objc
33-
public var isLeased: Bool
33+
public var isLeased = false
3434

3535
@objc
36-
public var poNumber: String
36+
public var poNumber = ""
3737

3838
@objc
39-
public var vendor: String
39+
public var vendor = ""
4040

4141
@objc
42-
public var appleCareIdentifier: String
42+
public var appleCareIdentifier = ""
4343

4444
@objc
45-
public var purchasePrice: String
45+
public var purchasePrice = ""
4646

4747
@objc
48-
public var purchasingAccount: String
48+
public var purchasingAccount = ""
4949

5050
@objc
51-
public var purchasingContact: String
51+
public var purchasingContact = ""
5252

5353
@objc
5454
public var poDate: PreciseDate?
@@ -60,7 +60,7 @@ public final class ComputerPurchasing: NSObject, Requestable {
6060
public var leaseExpires: PreciseDate?
6161

6262
@objc
63-
public var lifeExpectancy: UInt
63+
public var lifeExpectancy: UInt = 0
6464

6565
// MARK: - Initialization
6666

@@ -79,6 +79,10 @@ public final class ComputerPurchasing: NSObject, Requestable {
7979
lifeExpectancy = json[ComputerPurchasing.LifeExpectancyKey] as? UInt ?? 0
8080
}
8181

82+
public override init() {
83+
super.init()
84+
}
85+
8286
// MARK: - Functions
8387

8488
public func toJSON() -> [String: Any] {

JamfKit/Sources/Models/Computer/ComputerRemoteManagement.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public final class ComputerRemoteManagement: NSObject, Requestable {
1717
// MARK: - Properties
1818

1919
@objc
20-
public var isManaged: Bool
20+
public var isManaged = false
2121

2222
@objc
23-
public var managementUsername: String
23+
public var managementUsername = ""
2424

2525
// MARK: - Initialization
2626

@@ -29,6 +29,10 @@ public final class ComputerRemoteManagement: NSObject, Requestable {
2929
managementUsername = json[ComputerRemoteManagement.ManagementUsernameKey] as? String ?? ""
3030
}
3131

32+
public override init() {
33+
super.init()
34+
}
35+
3236
// MARK: - Functions
3337

3438
public func toJSON() -> [String: Any] {

JamfKit/Sources/Models/ComputerCommand/ComputerCommand.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public final class ComputerCommand: NSObject, Requestable, Endpoint, Subset {
2222
public var general: ComputerCommandGeneral
2323

2424
@objc
25-
public var computers: [UInt]
25+
public var computers = [UInt]()
2626

2727
public override var description: String {
2828
return "[\(String(describing: type(of: self)))][\(general.command)]"
@@ -47,6 +47,14 @@ public final class ComputerCommand: NSObject, Requestable, Endpoint, Subset {
4747
}
4848
}
4949

50+
public init?(command: String, passcode: UInt) {
51+
guard let general = ComputerCommandGeneral(command: command, passcode: passcode) else {
52+
return nil
53+
}
54+
55+
self.general = general
56+
}
57+
5058
// MARK: - Functions
5159

5260
public func toJSON() -> [String: Any] {

0 commit comments

Comments
 (0)