BaaS

open class BaaS

Backend as a Service (BaaS)

This class is used for the BaaS Server Interface.

.

Simple usage

  class myClass: UIViewController, BaaSDelegate {
      let db = BaaS.shared

      override func viewDidLoad() {
          db.delegate = self
          db.set(apiKey: "YOURAPIKEY")
          db.set(server: "https://yourserver.tld/BaaS")
      }
  }
  • This is the delegate where it calls back to.

    Declaration

    Swift

    public weak var delegate: BaaSDelegate?
  • Shared (instance)

    Init this for all your calls.

    Declaration

    Swift

    public static var shared: BaaS
  • BaaS Color

    BaaS Color (hex, rgb, hsv, cmyk)

    See more

    Declaration

    Swift

    public enum BaaS_Color : String
  • Init

    We’re live.

    Declaration

    Swift

    public init()
  • Log

    This is used to send log messages with the following syntax

     [BaaS] Filename:line functionName(...):
      Message
    

    Declaration

    Swift

    @discardableResult
    open func log(_ message: Any, file: String = #file, line: Int = #line, function: String = #function) -> Bool

    Parameters

    message

    the message to send

    file

    the filename

    line

    the line

    function

    function name

  • Undocumented, Help us document it!

    Declaration

    Swift

    public func checkForNotificationsInBackground() -> UIBackgroundFetchResult
  • NOOP (NO OPeration)

    This performs nothing.

    Declaration

    Swift

    public func noop()
  • Set the API key

    This saves your API key

    Declaration

    Swift

    public func set(apiKey: String)

    Parameters

    apiKey

    Your personal API key

  • Set hash of the server’s certificate

    This saves the hash of the server’s certificate

    Declaration

    Swift

    public func set(certificateHash: String)

    Parameters

    certificateHash

    Server’s certificate hash

  • Set hash of the server’s public key

    This saves the hash of the server’s public key

    Declaration

    Swift

    public func set(publicKeyHash: String)

    Parameters

    publicKeyHash

    Server’s public key hash

  • Get hash of the server’s certificate

    This gets the hash of the server’s certificate

    Declaration

    Swift

    public func getCertificateHash() -> String
  • Get hash of the server’s public key

    This gets the hash of the server’s public key

    Declaration

    Swift

    public func getPublicKeyHash() -> String
  • Set server URL

    Declaration

    Swift

    @discardableResult
    public func set(server: String) -> Bool

    Parameters

    server

    Server URL (Without /)

  • Set server URL

    Declaration

    Swift

    public func set(server: URL)

    Parameters

    server

    Server URL (Without /)

  • Set server maximum Timeout

    Declaration

    Swift

    public func set(timeout: Int)

    Parameters

    timeout

    Maximum timeout

  • BaaS database Field

     name:         Field Name
     type:         Field Type
     defaultValue: Field Default Value
     canBeEmpty:   Field can be empty?
    

    Declaration

    Swift

    public struct BaaS_dbField : Codable
  • BaaS database Field Type

    .text

    For text fields

    .number

    For numberic fields

    See more

    Declaration

    Swift

    public enum BaaS_dbFieldType : String
  • BaaS database Search Type

    For Equal (==) ___ .value, .equals, .eq

    For not Equal (!=) .notValue, .notEquals, .neq

    For like (~=) _____ .like

    For in range: _____ .location

     valueWhere("lat,lon", .location, "distanceInMeters")
    

    see: BaaS_SearchType

    See more

    Declaration

    Swift

    public enum BaaS_SearchType : String
  • BaaS expression Field

     searchType:   Search type (see BaaS_SearchType)
     expression1:  Search expression1
     expression2:  Search expression2
    

    Declaration

    Swift

    public struct BaaS_WhereExpression : Codable
  • BaaS possible errors

     parameter unableToDecodeJSON
    
    See more

    Declaration

    Swift

    public enum BaaS_Errors : Error
  • BaaS possible status

     success
     failed
     warning
    
    See more

    Declaration

    Swift

    public enum BaaS_Status : String, CodingKey
  • BaaS Response JSON Field

     Status:    This is the Status of the BaaS Server call
     Error:     This a Error thrown by the BaaS Server call
     Fix:       This a how to fix the BaaS Server call
     Exception: This a Exception thrown by the BaaS Server call
     ReqURI:    This the requested URL which the BaaS Server has received
     Table:     This the current table where the BaaS Server is working in
     Data:      This a Data string returned by the BaaS Server call
     Where:     This the Where cause where the BaaS Server searched on
     Method:    This Method is not recognized by the BaaS Server
     info:      This is extra information
     rowID:     This the row ID of the (last) inserted row
     Debug:     This a Debug message thrown by the BaaS Server call
     FilePath:  The FilePath is not writeable error thrown by the BaaS Server call
    
    See more

    Declaration

    Swift

    public struct BaaS_Response : Codable
  • Create Database Field

    Declaration

    Swift

    public func database(
        createFieldWithName: String,
        type: BaaS_dbFieldType = .text,
        defaultValue: String = "",
        canBeEmpty: Bool = true
        ) -> BaaS_dbField

    Parameters

    createFieldWithName

    Field name

    type

    Field type (.text / .number)

    defaultValue

    Fields default value

    canBeEmpty

    Can the field be empty?

    Return Value

    BaaS_dbField

  • Create Database

    Declaration

    Swift

    public func database(createWithName: String, withFields: [BaaS_dbField]) -> Bool

    Parameters

    createWithName

    Table name

    withFields

    Table fields

    Return Value

    Boolean

  • Database Exists?

    Declaration

    Swift

    public func database(existsWithName: String) -> Bool

    Parameters

    existsWithName

    Table name

    Return Value

    Boolean

  • user Login

    Declaration

    Swift

    public func userLogin(username: String, password: String) -> Bool

    Parameters

    username

    The username

    password

    The password

    Return Value

    Boolean

  • user Create

    Declaration

    Swift

    public func userCreate(username: String, password: String, email: String) -> Bool

    Parameters

    username

    The username

    password

    The password

    email

    The email

    Return Value

    Boolean

  • database Expression

    Declaration

    Swift

    public func expression(
        _ expression1: String,
        _ searchType: BaaS_SearchType,
        _ expression2: String
        ) -> BaaS_WhereExpression

    Parameters

    expression1

    Expression #1

    searchType

    .eq, .neq, .like, .location (See BaaS_SearchType)

    expression2

    Expression #2

    Return Value

    BaaS_WhereExpression

  • Undocumented, Help us document it!

    Declaration

    Swift

    public func value(expression: [BaaS_WhereExpression], inDatabase: String) -> Any
  • Create data

    Declaration

    Swift

    public func create(values: [String : String], inDatabase: String) -> Bool

    Parameters

    values

    Which values?

    inDatabase

    Which database?

    Return Value

    Bool

  • Rename table

    Declaration

    Swift

    public func rename(from: String, to: String) -> Bool

    Parameters

    from

    Old name

    to

    New name

    Return Value

    Bool

  • Empty table

    Declaration

    Swift

    public func empty(table: String) -> Bool

    Parameters

    table

    The table

    Return Value

    Bool

  • Remove table

    Declaration

    Swift

    public func remove(table: String) -> Bool

    Parameters

    table

    The table

    Return Value

    Bool

  • Get last Row ID

    Declaration

    Swift

    public func getLastRowID() -> Int

    Return Value

    Last row ID

  • Upload file

    Declaration

    Swift

    public func fileUpload(data fileData: Data, saveWithFileID fileID: String) -> Any

    Parameters

    data

    File data

    saveWithFileID

    Preffered file ID

    Return Value

    [Boolean, FileID]

  • File Exists

    Declaration

    Swift

    public func fileExists(withFileID fileID: String) -> Bool

    Parameters

    withFileID

    The file identifier

    Return Value

    Boolean

  • Undocumented, Help us document it!

    Declaration

    Swift

    public func fileDownload(withFileID fileID: String) -> Data
  • Undocumented, Help us document it!

    Declaration

    Swift

    @discardableResult
    public func fileDelete(withFileID fileID: String) -> Any
  • No operation

    Declaration

    Swift

    public func noop(_ any: Any)

    Parameters

    _

    Any

  • networkRequest

    Start a network request

    Declaration

    Swift

    public func networkRequest(
        _ url: String,
        _ posting: Dictionary<String, Any>? = ["nothing": "send"]
        ) -> Data

    Parameters

    url

    The url to be parsed

    posting

    What do you need to post

    Return Value

    the data we’ve got from the server