Network
final class Network
The purpose of the Network class is to gather all Synology FileStation API Requests.
-
The
ipvariable is use to reach a Synology NAS, please fill it with your NASip.Declaration
Swift
fileprivate(set) var ip: String -
The
portvariable is use to reach a Synology NAS, please fill it with your NASport.Declaration
Swift
fileprivate(set) var port: String -
If you want to configure API Requests in http or https change this
httpTypevariable.Declaration
Swift
fileprivate(set) var httpType: String -
Undocumented
Declaration
Swift
var sid: String -
Undocumented
Declaration
Swift
init()
-
Login Request to Synology FileStation API. Connect the user if the request is successful. Set the session key in the preferences and class attribute. Also handle errors. Handle NAS Password Policy (4 connection tests and blocked account during 1 min). Therefore, connection alerts are displayed.
Warning
This function is needed as first API Request. The answered sid will be used by all the other API requests.
Declaration
Swift
func doLogin(_ viewController: ViewController, _ user: String, _ pwd: String, otp_code: String = "")Parameters
viewControllerPermit access to local Controller attributes.
userUsername who have to correspond to the NAS LDAP user.
pwdPassword who have also to correspond to the NAS LDAP user.
otp_codeIf a 2-step verification code is required.
-
Create Request to Synology FileStation API. Create the folder if the request is successful. Also handle errors.
Declaration
Swift
func createFolder(_ fileViewController: FileViewController, _ folderName: String)Parameters
fileViewControllerPermit access to local Controller attributes.
folderNameFolderName that the user wants to create.
-
List Share Request to Synology FileStation API. List the shared folders if the request is successful. Also handle errors.
Declaration
Swift
func fetchDirectories(_ fileViewController: FileViewController, refresh: Bool = false)Parameters
fileViewControllerPermit access to local Controller attributes.
refreshIf the dev wants to use this function to refresh. Refresher indicator ends after the request response.
-
List Request to Synology FileStation API. List the folder needed if the request is successful. Also handle errors.
Declaration
Swift
func fetchDirectoriesDetails(_ fileViewController: FileViewController, _ folderPath: String, noBackButton: Bool, refresh: Bool = false)Parameters
fileViewControllerPermit access to local Controller attributes.
refreshIf the dev wants to use this function to refresh. Refresher indicator ends after the request response.
folderPathSynology FileStation path to the folder needed.
noBackButtonIf the dev wants to use this function without enable back button history.
-
Upload Request to Synology FileStation API. Upload the file needed if the request is successful. Also handle errors.
Declaration
Swift
func uploadFile(_ fileViewController: FileViewController, _ urls: [URL])Parameters
fileViewControllerPermit access to local Controller attributes.
urlsLocal application Urls of selected files. In our case it is only one url to the file selected.
-
Create the http POST body.
Declaration
Swift
func createBody(contentFile: Data, _ folderPath: String, _ selectedFileUrl: URL, _ boundary: String) -> NSMutableDataParameters
contentFileContent of the file the user wants to upload.
selectedFileUrlLocal application url to the file selected.
boundaryBoundary.
folderPathSynology FileStation path to the wanted folder to upload the file.
-
Delete Request to Synology FileStation API. Delete the folder or file needed if the request is successful. Also handle errors.
Declaration
Swift
func deleteFile(_ fileViewController: FileViewController, _ path: String)Parameters
fileViewControllerPermit access to local Controller attributes.
pathSynology FileStation path to the folder or file the user wants to delete.
Network Class Reference