Network
final class Network
The purpose of the Network
class is to gather all Synology FileStation API Requests.
-
The
ip
variable is use to reach a Synology NAS, please fill it with your NASip
.Declaration
Swift
fileprivate(set) var ip: String
-
The
port
variable 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
httpType
variable.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
viewController
Permit access to local Controller attributes.
user
Username who have to correspond to the NAS LDAP user.
pwd
Password who have also to correspond to the NAS LDAP user.
otp_code
If 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
fileViewController
Permit access to local Controller attributes.
folderName
FolderName 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
fileViewController
Permit access to local Controller attributes.
refresh
If 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
fileViewController
Permit access to local Controller attributes.
refresh
If the dev wants to use this function to refresh. Refresher indicator ends after the request response.
folderPath
Synology FileStation path to the folder needed.
noBackButton
If 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
fileViewController
Permit access to local Controller attributes.
urls
Local 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) -> NSMutableData
Parameters
contentFile
Content of the file the user wants to upload.
selectedFileUrl
Local application url to the file selected.
boundary
Boundary.
folderPath
Synology 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
fileViewController
Permit access to local Controller attributes.
path
Synology FileStation path to the folder or file the user wants to delete.