DSB

public class DSB

DSB Instance.

  • Declaration

    Swift

    public var sessionCookies: [HTTPCookie];
  • Initialize a new instance.

    Declaration

    Swift

    public init(with username: String, and password: String, and optionalSessionCookie: [HTTPCookie]?, enableDebug: Bool?)

    Parameters

    username

    The username for your dsb login.

    password

    The password

    optionalSessionCookie

    (Optional) An array with session cookies to reuse sessions. Default: []

    enableDebug

    (Optional) Print debug output. Default: false

  • Login method. You don’t need to run it manual. Both smartFetch() and fetch() will run it for you. It also will save the cookies, but only for this instance.

    Declaration

    Swift

    public func login() -> Promise<[HTTPCookie]>

    Return Value

    An array with session cookies.

  • Fetch data from dsbmobile, runs login method if you are not logged in. If you already have a session, it just tries to fetch the data and only if it fails, it will try to login.

    Declaration

    Swift

    public func smartFetch() -> Promise<String>

    Return Value

    Promise which resolves to a json string.

  • Use this function to find news, timetable and tiles in your response string.

    Declaration

    Swift

    public func getData(from json: String, methodName: String) -> String?

    Parameters

    json

    The response string from fetch() or smartFetch()

    methodName

    The method your try to find. Example: timetable

    Return Value

    A json array string. If it can’t find your method it just returns nil.

  • Fetch data from dsbmobile. It automaticly runs the login method. If you are already logged in, it will check first if the session is valid with the validateLogin() method.

    Declaration

    Swift

    public func fetch() -> Promise<String>

    Return Value

    A Promise which resolves with a json string.

  • Validate already existing session cookies.

    Declaration

    Swift

    public func validateLogin(with sessionCookies: [HTTPCookie]?) -> Promise<Bool>

    Parameters

    sessionCookies

    (Optional) An array of cookies to use. Default: self.sessionCookies

    Return Value

    An promise which resolves to an boolean