// // NCCommunication.swift // Nextcloud // // Created by Marino Faggiana on 12/10/19. // Copyright © 2018 Marino Faggiana. All rights reserved. // // Author Marino Faggiana // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // import Foundation import Alamofire import SwiftyXMLParser class NCCommunication: NSObject { @objc static let sharedInstance: NCCommunication = { let instance = NCCommunication() return instance }() let NCResource = """ " """ @objc func readFolder(path: String, user: String, password: String, completionHandler: @escaping (_ result: [NCFile]?, _ error: Error?) -> Void) { // URL var url: URLConvertible do { try url = path.asURL() } catch _ { completionHandler(nil, nil) return } // Headers var headers: HTTPHeaders = [.authorization(username: user, password: password)] headers.update(.userAgent(CCUtility.getUserAgent())) headers.update(.contentType("application/xml")) headers.update(name: "Depth", value: "1") // Parameters //let parameters: Parameters = ["":"" + NCResource + ""] // Method let method = HTTPMethod(rawValue: "PROPFIND") AF.request(url, method: method, parameters:[:], encoding: URLEncoding.httpBody, headers: headers, interceptor: nil).validate(statusCode: 200..<300).responseData { (response) in switch response.result { case.failure(let error): completionHandler(nil, error) case .success( _): if let data = response.data { let xml = XML.parse(data) let numberOfHits = xml.ResultSet.Result.Hit.all?.count print("success") } print("success") } } } }