Skip to content
Branch: master
Go to file
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

README.md

DiskStationSwift

A Swift client library for Synology Disk Station API.

GitHub license

Goals

  • Completeness All currently available Swift bindings for the DiskStation are specific for one application such as Download Station or File Station.
  • Extensibility It should be easily extensible. The only way how to extend most of the other implementations is to write a specific method with all the json parsing and error checking.
  • Strict typing Many of the other implementations do provide only a json response object to the response handler. With a little help from Swift generics and associated types, this implementation easily provides strict types even in response handlers.

Requirements & Installation

This package relies on some functionalities (URLSessionDataTask, JSONSerializable) from the Foundation framework, which is available only on the Apple platforms.

This libarary is a Swift package. To add it to your project, just use the Xcode -> File -> Swift Packages -> Add Package Dependency and paste the URL of this repository. The complete guide is available in the official Apple documentation.

Features

  • Base API
    • SYNO.API.Info Provides available API info.
    • SYNO.API.Auth Performs session login and logout.
  • Download Station
    • SYNO.DownloadStation.Info Provides Download Station info and settings. Sets Download Station settings.

Contributing

This library is still in developement. All contributions are welcome. If you want to help, please contact me. Official contribution guide is not yet available.

If you find this library usefull, please star the repository.

Examples

Create the client object

import DiskStationSwift

var components = URLComponents();
components.host = hostname
components.port = port
components.scheme = secure ? "https" : "http"
let session = DSSession(url: components)

Login with your account

The standard API calls are asynchronous, traditionally finished with the provided completion handler.

session.requestAsync(request: DSLogin(username: "user", password: "pass", session: .DownloadStation)){error, sid in
    if error != nil {
        print(error)
        return
    }
    if let sid = sid {
        print(sid)
    }
}

Or you can do this synchronously, because it is sometimes more convenient.

session.request(request: DSLogin(username: "user", password: "pass", session: .DownloadStation)){error, sid in
    if error != nil {
        print(error)
        return
    }
    if let sid = sid {
        print(sid)
    }
}

And since this is a synchronous call, the return value can be used directly, without the completion handler.

let (error, sid) = session.request(request: DSLogin(username: "user", password: "pass", session: .DownloadStation))

Similar software

Author

Vit Kabele vit@kabele.me

License

This repository is licensed under the MIT License

You can’t perform that action at this time.