Skip to content

Commit

Permalink
normalized taskHandler
Browse files Browse the repository at this point in the history
            taskHandler(task)
        }.

Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana committed Mar 8, 2024
1 parent 4a33e6c commit 25e8788
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 84 deletions.
85 changes: 68 additions & 17 deletions Sources/NextcloudKit/API/NextcloudKit+API.swift

Large diffs are not rendered by default.

55 changes: 44 additions & 11 deletions Sources/NextcloudKit/E2EE/NextcloudKit+E2EE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extension NextcloudKit {
@objc public func markE2EEFolder(fileId: String,
delete: Bool,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -49,7 +50,9 @@ extension NextcloudKit {

let headers = self.nkCommonInstance.getStandardHeaders(options: options)

sessionManager.request(url, method: method, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: method, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -75,6 +78,7 @@ extension NextcloudKit {
e2eCounter: String?,
method: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ e2eToken: String?, _ data: Data?, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand Down Expand Up @@ -103,7 +107,9 @@ extension NextcloudKit {
headers.update(name: "X-NC-E2EE-COUNTER", value: e2eCounter)
}

sessionManager.request(url, method: method, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: method, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -128,6 +134,7 @@ extension NextcloudKit {
@objc public func getE2EEMetadata(fileId: String,
e2eToken: String?,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ e2eMetadata: String?, _ signature: String?, _ data: Data?, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -150,7 +157,9 @@ extension NextcloudKit {
parameters["e2e-token"] = e2eToken
}

sessionManager.request(url, method: .get, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: .get, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand Down Expand Up @@ -179,6 +188,7 @@ extension NextcloudKit {
signature: String?,
method: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ metadata: String?, _ data: Data?, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand Down Expand Up @@ -209,7 +219,9 @@ extension NextcloudKit {
headers.update(name: "X-NC-E2EE-SIGNATURE", value: signature)
}

sessionManager.request(url, method: method, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: method, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -235,6 +247,7 @@ extension NextcloudKit {

@objc public func getE2EECertificate(user: String? = nil,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ certificate: String?, _ certificateUser: String?, _ data: Data?, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand Down Expand Up @@ -262,7 +275,9 @@ extension NextcloudKit {

let headers = self.nkCommonInstance.getStandardHeaders(options: options)

sessionManager.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand Down Expand Up @@ -290,6 +305,7 @@ extension NextcloudKit {
}

@objc public func getE2EEPrivateKey(options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ privateKey: String?, _ data: Data?, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -307,7 +323,9 @@ extension NextcloudKit {

let headers = self.nkCommonInstance.getStandardHeaders(options: options)

sessionManager.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -330,6 +348,7 @@ extension NextcloudKit {
}

@objc public func getE2EEPublicKey(options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ publicKey: String?, _ data: Data?, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -347,7 +366,9 @@ extension NextcloudKit {

let headers = self.nkCommonInstance.getStandardHeaders(options: options)

sessionManager.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -371,6 +392,7 @@ extension NextcloudKit {

@objc public func signE2EECertificate(certificate: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ certificate: String?, _ data: Data?, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -390,7 +412,9 @@ extension NextcloudKit {

let parameters = ["csr": certificate]

sessionManager.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -415,6 +439,7 @@ extension NextcloudKit {

@objc public func storeE2EEPrivateKey(privateKey: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ privateKey: String?, _ data: Data?, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -434,7 +459,9 @@ extension NextcloudKit {

let parameters = ["privateKey": privateKey]

sessionManager.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -457,6 +484,7 @@ extension NextcloudKit {
}

@objc public func deleteE2EECertificate(options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -474,7 +502,9 @@ extension NextcloudKit {

let headers = self.nkCommonInstance.getStandardHeaders(options: options)

sessionManager.request(url, method: .delete, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).response(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: .delete, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.response(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -490,6 +520,7 @@ extension NextcloudKit {
}

@objc public func deleteE2EEPrivateKey(options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -507,7 +538,9 @@ extension NextcloudKit {

let headers = self.nkCommonInstance.getStandardHeaders(options: options)

sessionManager.request(url, method: .delete, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).response(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: .delete, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.response(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand Down
25 changes: 20 additions & 5 deletions Sources/NextcloudKit/NextcloudKit+Comments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extension NextcloudKit {

@objc public func getComments(fileId: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ items: [NKComments]?, _ data: Data?, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -50,7 +51,9 @@ extension NextcloudKit {
return options.queue.async { completion(account, nil, nil, NKError(error: error)) }
}

sessionManager.request(urlRequest).validate(statusCode: 200..<300).responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(urlRequest).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -73,6 +76,7 @@ extension NextcloudKit {
@objc public func putComments(fileId: String,
message: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -95,7 +99,9 @@ extension NextcloudKit {
return options.queue.async { completion(account, NKError(error: error)) }
}

sessionManager.request(urlRequest).validate(statusCode: 200..<300).response(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(urlRequest).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.response(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -114,6 +120,7 @@ extension NextcloudKit {
messageId: String,
message: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -137,7 +144,9 @@ extension NextcloudKit {
return options.queue.async { completion(account, NKError(error: error)) }
}

sessionManager.request(urlRequest).validate(statusCode: 200..<300).response(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(urlRequest).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.response(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -155,6 +164,7 @@ extension NextcloudKit {
@objc public func deleteComments(fileId: String,
messageId: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -168,7 +178,9 @@ extension NextcloudKit {

let headers = self.nkCommonInstance.getStandardHeaders(options: options)

sessionManager.request(url, method: .delete, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).response(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(url, method: .delete, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.response(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand All @@ -185,6 +197,7 @@ extension NextcloudKit {

@objc public func markAsReadComments(fileId: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in },
completion: @escaping (_ account: String, _ error: NKError) -> Void) {

let account = self.nkCommonInstance.account
Expand All @@ -208,7 +221,9 @@ extension NextcloudKit {
return options.queue.async { completion(account, NKError(error: error)) }
}

sessionManager.request(urlRequest).validate(statusCode: 200..<300).response(queue: self.nkCommonInstance.backgroundQueue) { response in
sessionManager.request(urlRequest).validate(statusCode: 200..<300).onURLSessionTaskCreation { task in
taskHandler(task)
}.response(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}
Expand Down
Loading

0 comments on commit 25e8788

Please sign in to comment.