Skip to content

Commit

Permalink
Improve Objective-C compatibility
Browse files Browse the repository at this point in the history
Removed implicit “internal” access levels.
  • Loading branch information
damien-rivet committed Feb 22, 2018
1 parent b162874 commit 3e1d25c
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 36 deletions.
12 changes: 6 additions & 6 deletions .github/ISSUE_TEMPLATE.md
@@ -1,5 +1,3 @@
# {Issue} OR {New feature} #

:warning:

New issue checklist:
Expand All @@ -13,12 +11,12 @@ New issue checklist:

:warning:

*Please change the section title with the right issue type.*

## Short description ##
# Short description #

*Please fill this section with a short description of your issue / new feature.*

-----

**If the ticket is about an issue, use the following sections to give more details about the issue you're facing.**

### Expected outcome ###
Expand All @@ -27,7 +25,9 @@ New issue checklist:

### Actual outcome ###

*Please fill this section with a description of what is actually happening. Please add as much information as you can (how easy it is to reproduce, steps, etc.).*
*Please fill the following section with a description of what is actually happening. Please add as much information as you can (how easy it is to reproduce, steps, etc.).*

-----

**If the ticket is about a new feature, use the following sections to give more details about the changes you ask for / want to implement.**

Expand Down
2 changes: 1 addition & 1 deletion JamfKit/Sources/Constants.swift
Expand Up @@ -6,7 +6,7 @@
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//

internal struct Constants {
struct Constants {

static let domain = "com.github.ethenyl.JamfKit"
}
2 changes: 1 addition & 1 deletion JamfKit/Sources/Extensions/StringExtension.swift
Expand Up @@ -6,7 +6,7 @@
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//

internal extension String {
extension String {

// MARK: - Functions

Expand Down
2 changes: 1 addition & 1 deletion JamfKit/Sources/Models/BaseObject.swift
Expand Up @@ -76,7 +76,7 @@ public class BaseObject: NSObject, Requestable, Identifiable {
* - Parameter singleNodeKey: The string key used to identify a single element within the main node.
*
*/
internal static func parseElements<Element: Requestable>(from json: [String: Any], nodeKey: String, singleNodeKey: String) -> [Element] {
static func parseElements<Element: Requestable>(from json: [String: Any], nodeKey: String, singleNodeKey: String) -> [Element] {
var elements = [Element]()

guard let elementsNode = json[nodeKey] as? [[String: [String: Any]]] else {
Expand Down
11 changes: 10 additions & 1 deletion JamfKit/Sources/Models/Building.swift
Expand Up @@ -15,6 +15,15 @@ public final class Building: BaseObject, Endpoint {
public static let Endpoint: String = "buildings"
}

// MARK: - Creatable

extension Building: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

extension Building: Creatable, Readable, Updatable, Deletable { }
extension Building: Readable, Updatable, Deletable { }
11 changes: 10 additions & 1 deletion JamfKit/Sources/Models/ComputerGroup/ComputerGroup.swift
Expand Up @@ -51,6 +51,15 @@ public final class ComputerGroup: HardwareGroup, Endpoint {
}
}

// MARK: - Creatable

extension ComputerGroup: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

extension ComputerGroup: Creatable, Readable, Updatable, Deletable { }
extension ComputerGroup: Readable, Updatable, Deletable { }
11 changes: 10 additions & 1 deletion JamfKit/Sources/Models/Department.swift
Expand Up @@ -15,6 +15,15 @@ public final class Department: BaseObject, Endpoint {
public static let Endpoint: String = "departments"
}

// MARK: - Creatable

extension Department: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

extension Department: Creatable, Readable, Updatable, Deletable { }
extension Department: Readable, Updatable, Deletable { }
11 changes: 10 additions & 1 deletion JamfKit/Sources/Models/DirectoryBinding.swift
Expand Up @@ -73,6 +73,15 @@ public final class DirectoryBinding: BaseObject, Endpoint {
}
}

// MARK: - Creatable

extension DirectoryBinding: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

extension DirectoryBinding: Creatable, Readable, Updatable, Deletable { }
extension DirectoryBinding: Readable, Updatable, Deletable { }
2 changes: 1 addition & 1 deletion JamfKit/Sources/Models/HardwareGroup/HardwareGroup.swift
Expand Up @@ -36,7 +36,7 @@ public class HardwareGroup: BaseObject {
super.init(json: json)
}

internal override init?(identifier: UInt, name: String) {
override init?(identifier: UInt, name: String) {
super.init(identifier: identifier, name: name)
}

Expand Down
11 changes: 10 additions & 1 deletion JamfKit/Sources/Models/MobileDeviceGroup/MobileDeviceGroup.swift
Expand Up @@ -51,6 +51,15 @@ public final class MobileDeviceGroup: HardwareGroup, Endpoint {
}
}

// MARK: - Creatable

extension MobileDeviceGroup: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

extension MobileDeviceGroup: Creatable, Readable, Updatable, Deletable { }
extension MobileDeviceGroup: Readable, Updatable, Deletable { }
11 changes: 10 additions & 1 deletion JamfKit/Sources/Models/NetbootServer.swift
Expand Up @@ -113,6 +113,15 @@ public final class NetbootServer: BaseObject, Endpoint {
}
}

// MARK: - Creatable

extension NetbootServer: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

extension NetbootServer: Creatable, Readable, Updatable, Deletable { }
extension NetbootServer: Readable, Updatable, Deletable { }
11 changes: 10 additions & 1 deletion JamfKit/Sources/Models/Printer.swift
Expand Up @@ -119,6 +119,15 @@ public final class Printer: BaseObject, Endpoint {
}
}

// MARK: - Creatable

extension Printer: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

extension Printer: Creatable, Readable, Updatable, Deletable { }
extension Printer: Readable, Updatable, Deletable { }
11 changes: 10 additions & 1 deletion JamfKit/Sources/Models/Script.swift
Expand Up @@ -99,6 +99,15 @@ public final class Script: BaseObject, Endpoint {
}
}

// MARK: - Creatable

extension Script: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

extension Script: Creatable, Readable, Updatable, Deletable { }
extension Script: Readable, Updatable, Deletable { }
11 changes: 10 additions & 1 deletion JamfKit/Sources/Models/Site.swift
Expand Up @@ -15,6 +15,15 @@ public final class Site: BaseObject, Endpoint {
public static let Endpoint: String = "sites"
}

// MARK: - Creatable

extension Site: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

extension Site: Creatable, Readable, Updatable, Deletable { }
extension Site: Readable, Updatable, Deletable { }
7 changes: 6 additions & 1 deletion JamfKit/Sources/Models/User.swift
Expand Up @@ -110,7 +110,12 @@ public final class User: BaseObject, Endpoint {

// MARK: - Creatable

extension User: Creatable { }
extension User: Creatable {

public func create() -> URLRequest? {
return self.createRequest()
}
}

// MARK: - Protocols

Expand Down
3 changes: 2 additions & 1 deletion JamfKit/Sources/Protocols/Requests/Creatable.swift
Expand Up @@ -7,6 +7,7 @@
//

/// Represents an object that can be created with an URLRequest
@objc(JMFKCreatable)
public protocol Creatable {

// MARK: - Functions
Expand All @@ -21,7 +22,7 @@ public extension Creatable where Self: Endpoint & Identifiable & Requestable {

// MARK: - Functions

func create() -> URLRequest? {
func createRequest() -> URLRequest? {
return SessionManager.instance.createRequest(for: self, key: BaseObject.CodingKeys.identifier.rawValue, value: String(identifier))
}
}
28 changes: 14 additions & 14 deletions JamfKit/Sources/Session/Requests/SessionManagerRequests.swift
Expand Up @@ -6,13 +6,13 @@
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//

internal enum HttpHeader: String {
enum HttpHeader: String {
case accept = "Accept"
case authorization = "Authorization"
case contentType = "Content-Type"
}

internal enum HeaderContentType: String {
enum HeaderContentType: String {
case json = "application/json"
}

Expand All @@ -21,7 +21,7 @@ extension SessionManager {
// MARK: - Functions

/// Returns a Base64 encoded username & password pair to be used for Basic HTTP authentication
internal static func computeAuthorizationHeader(from username: String, password: String) -> String {
static func computeAuthorizationHeader(from username: String, password: String) -> String {
guard
!username.isEmpty,
!password.isEmpty,
Expand All @@ -34,15 +34,15 @@ extension SessionManager {
}

/// Returns an authentified URLRequst matching the supplied configuration
internal func authentifiedRequest(for url: URL, authorizationHeader: String, method: HttpMethod) -> URLRequest {
func authentifiedRequest(for url: URL, authorizationHeader: String, method: HttpMethod) -> URLRequest {
var request = URLRequest(url: url)
request.httpMethod = method.rawValue
request.setValue(authorizationHeader, forHTTPHeaderField: HttpHeader.authorization.rawValue)

return request
}

internal func baseRequest(endpoint: String, key: String, value: String, method: HttpMethod) -> URLRequest? {
func baseRequest(endpoint: String, key: String, value: String, method: HttpMethod) -> URLRequest? {
guard let url = host?.appendingPathComponent("\(endpoint)/\(key.asCleanedKey())/\(value)") else {
return nil
}
Expand All @@ -56,7 +56,7 @@ extension SessionManager {
extension SessionManager {

/// Returns a `CREATE` URLRequest for the supplied URL
internal func createRequest(for object: Endpoint & Requestable, key: String, value: String) -> URLRequest? {
func createRequest(for object: Endpoint & Requestable, key: String, value: String) -> URLRequest? {
guard
var request = baseRequest(endpoint: object.endpoint, key: key, value: value, method: .post),
let data = try? JSONSerialization.data(withJSONObject: object.toJSON(), options: .prettyPrinted) else {
Expand All @@ -75,7 +75,7 @@ extension SessionManager {
extension SessionManager {

/// Returns a `READ` URLRequest for the supplied JSS endpoint
internal func readAllRequest(for endpoint: String) -> URLRequest? {
func readAllRequest(for endpoint: String) -> URLRequest? {
guard let url = host?.appendingPathComponent("\(endpoint)") else {
return nil
}
Expand All @@ -87,7 +87,7 @@ extension SessionManager {
}

/// Returns a `READ` URLRequest for the supplied endpoint type & identifier
internal func readRequest(for endpoint: Endpoint.Type, key: String, value: String) -> URLRequest? {
func readRequest(for endpoint: Endpoint.Type, key: String, value: String) -> URLRequest? {
guard var request = baseRequest(endpoint: endpoint.Endpoint, key: key, value: value, method: .get) else {
return nil
}
Expand All @@ -98,7 +98,7 @@ extension SessionManager {
}

/// Returns a `READ` URLRequest for the supplied JSS object
internal func readRequest(for object: Endpoint) -> URLRequest? {
func readRequest(for object: Endpoint) -> URLRequest? {
guard let url = host?.appendingPathComponent("\(object.endpoint)") else {
return nil
}
Expand All @@ -110,7 +110,7 @@ extension SessionManager {
}

/// Returns a `READ` URLRequest for the supplied JSS object
internal func readRequest(for object: Endpoint, key: String, value: String) -> URLRequest? {
func readRequest(for object: Endpoint, key: String, value: String) -> URLRequest? {
guard var request = baseRequest(endpoint: object.endpoint, key: key, value: value, method: .get) else {
return nil
}
Expand All @@ -126,7 +126,7 @@ extension SessionManager {
extension SessionManager {

/// Returns an `UPDATE` URLRequest for the supplied JSS object
internal func updateRequest(for object: Endpoint & Requestable) -> URLRequest? {
func updateRequest(for object: Endpoint & Requestable) -> URLRequest? {
guard
let url = host?.appendingPathComponent("\(object.endpoint)"),
let data = try? JSONSerialization.data(withJSONObject: object.toJSON(), options: .prettyPrinted) else {
Expand All @@ -141,7 +141,7 @@ extension SessionManager {
}

/// Returns an `UPDATE` URLRequest for the supplied JSS object
internal func updateRequest(for object: Endpoint & Requestable, key: String, value: String) -> URLRequest? {
func updateRequest(for object: Endpoint & Requestable, key: String, value: String) -> URLRequest? {
guard
var request = self.baseRequest(endpoint: object.endpoint, key: key, value: value, method: .put),
let data = try? JSONSerialization.data(withJSONObject: object.toJSON(), options: .prettyPrinted) else {
Expand All @@ -160,12 +160,12 @@ extension SessionManager {
extension SessionManager {

/// Returns a `DELETE` URLRequest for the supplied endpoint type & identifier
internal func deleteRequest(for endpoint: Endpoint.Type, key: String, value: String) -> URLRequest? {
func deleteRequest(for endpoint: Endpoint.Type, key: String, value: String) -> URLRequest? {
return baseRequest(endpoint: endpoint.Endpoint, key: key, value: value, method: .delete)
}

/// Returns a `DELETE` URLRequest for the supplied URL
internal func deleteRequest(for object: Endpoint, key: String, value: String) -> URLRequest? {
func deleteRequest(for object: Endpoint, key: String, value: String) -> URLRequest? {
return baseRequest(endpoint: object.endpoint, key: key, value: value, method: .delete)
}
}
2 changes: 1 addition & 1 deletion JamfKit/Sources/Session/SessionManagerError.swift
Expand Up @@ -29,7 +29,7 @@ public class SessionManagerError: NSError {

// MARK: - Initialization

convenience internal init(code: SessionManagerErrorCode) {
convenience init(code: SessionManagerErrorCode) {
self.init(domain: Constants.domain, code: code.rawValue)
}
}

0 comments on commit 3e1d25c

Please sign in to comment.