BaasBox
public class BaasBox
The BaasBox
class.
usage is as follows:
In your app delegate you should setup Baasbox
let config = BaasConfig()
Here you can declare some variables, See BaasConfig
for more data
BaasBox.setup(url: "your url", appcode: "your appcode", config: config)
Now you are ready to user BaasBox
-
Baasbox setup, call this function in your AppDelegate.
BaasConfig Object:
- timeout: Double
- retrylogin: Boolean that indicates if the SDK should save the user password encrypted and use it when server returns 401
- loginStrategy: A login strategy ( user defined functions for login ), if empty the default one will be used
- signupStrategy: A signup strategy ( user defined functions for signup ), if empty the default one will be used
logoutStrategy: A logout strategy ( user defined functions for logout: called on logout or on user not authorized ), if empty the default one will be used
parameters:
- url: BaasBox url
- appcode: BaasBox Appcode
- config : a BaasConfig Object
Declaration
Swift
public static func setup(url: String, appcode: String, config: BaasConfig = BaasConfig())
Parameters
url
BaasBox url
appcode
BaasBox Appcode
config
a BaasConfig Object
-
Returns the appcode declared in setup.
- return : appcode from setup
Declaration
Swift
public static func getAppcode() -> String?
-
Returns the url declared in setup.
- return : url from setup
Declaration
Swift
public static func getBaseUrl() -> String?
-
Returns the config declared in setup.
- return : A BaasConfig object
Declaration
Swift
public static func getConfig() -> BaasConfig
-
Login the user specified in the parameters
- parameters:
- username: The username of the user you want to login
- password: The password of the user you want to login
Declaration
Swift
public func login(username: String, password: String, completion: BaasCompletion )
Parameters
username
The username of the user you want to login
password
The password of the user you want to login
- parameters:
-
Login the user specified in the parameters with the specified social platform
- parameters:
- to: The platform you want to login ( .facebook, .google )
- token: The token that will be used for the login, you can get it via the third party sdks
Declaration
Swift
public func socialLogin(to: socialTypes, token: String, completion: BaasCompletion )
Parameters
to
The platform you want to login ( .facebook, .google )
token
The token that will be used for the login, you can get it via the third party sdks
- parameters:
-
createUser(username:password:visibleByTheUser:visibleByFriends:visibleByRegisteredUsers:visibleByAnonymousUsers:completion:)
Create a user with the specified data
- parameters:
- username: The username that will be used for the user
- password: The password that will be used for the user
- visibleByTheUser: (Optional) Dictionary that will be visible only by yourself
- visibleByFriends: (Optional) Dictionary that will be visible only by friends
- visibleByRegisteredUsers: (Optional) Dictionary that will be visible for any registered user
- visibleByAnonymousUsers: (Optional) Dictionary that will be visible for any user
Declaration
Swift
public func createUser(username: String, password: String, visibleByTheUser : [String: Any] = [:], visibleByFriends : [String: Any] = [:], visibleByRegisteredUsers : [String: Any] = [:], visibleByAnonymousUsers : [String: Any] = [:], completion: BaasCompletion )
Parameters
username
The username that will be used for the user
password
The password that will be used for the user
visibleByTheUser
(Optional) Dictionary that will be visible only by yourself
visibleByFriends
(Optional) Dictionary that will be visible only by friends
visibleByRegisteredUsers
(Optional) Dictionary that will be visible for any registered user
visibleByAnonymousUsers
(Optional) Dictionary that will be visible for any user
- parameters:
-
Get the details of a specified user
- parameters:
- username: the username to fetch
Declaration
Swift
public func getUser(username: String, completion: BaasCompletion )
Parameters
username
the username to fetch
- parameters:
-
Get a list of users
- parameters:
- parameters: Dictionary of query criteria
Declaration
Swift
public func getUserList(parameters : [String:AnyHashable] = [:], completion: BaasCompletion)
Parameters
parameters
Dictionary of query criteria
- parameters:
-
Try reset password of the specified user
Note
The user need to have the
email
field in the visibleByTheUser dictionary- parameters:
- username: the username to try reset
Declaration
Swift
public func resetPassword(username: String, completion: BaasCompletion)
Parameters
username
the username to try reset
- parameters:
-
Saves the current stored user
Declaration
Swift
public static func saveCurrentUser()
-
Remove the current stored user
Declaration
Swift
public static func deleteCurrentUser()
-
Saves the current stored user pass encrypted
Declaration
Swift
public static func saveUserPass(pass: String)
-
Get the follows of a specified user
- parameters:
- username: the username to fetch
Declaration
Swift
public func getFollows(username: String, completion: BaasCompletion)
Parameters
username
the username to fetch
- parameters:
-
Get the followers of a specified user
- parameters:
- username: the username to fetch
Declaration
Swift
public func getFollowers(username: String, completion: BaasCompletion)
Parameters
username
the username to fetch
- parameters:
-
Create a document on the specified collection
- parameters:
- inCollection: The collection where you want to create the document
- body: Body of the document
Declaration
Swift
public func createDocument(inCollection coll:String, body: [String: Any], completion: BaasCompletion)
Parameters
inCollection
The collection where you want to create the document
body
Body of the document
- parameters:
-
delete a document on the specified collection
- parameters:
- fromCollection: The collection where you want to delete the document
- id: id of the document
Declaration
Swift
public func deleteDocument(fromCollection coll: String, id: String, completion:BaasCompletion)
Parameters
fromCollection
The collection where you want to delete the document
id
id of the document
- parameters:
-
Get a document/ a list of documents from the specified collection, you can pass query and pagination criteria
- parameters:
- fromCollection: The collection where you want to retrieve the document
- withID: (Optional) the id of the document
- parameters: (Optional) query criteria
Declaration
Swift
public func getDocuments(fromCollection coll: String, withID id: String = "", parameters: [String: AnyHashable] = [:], completion: BaasCompletion)
Parameters
fromCollection
The collection where you want to retrieve the document
withID
(Optional) the id of the document
parameters
(Optional) query criteria
- parameters:
-
Get the number of documents from the specified collection, you can pass query and pagination criteria
- parameters:
- inCollection: The collection where you want to count the documents
- parameters: (Optional) query criteria
Declaration
Swift
public func countDocuments(inCollection coll: String, parameters: [String:AnyHashable] = [:], completion: BaasCompletion)
Parameters
inCollection
The collection where you want to count the documents
parameters
(Optional) query criteria
- parameters:
-
update a document from the specified collection
- parameters:
- inCollection: The collection where you want to update the document
- withID: the id of the document
- body: (Optional) : new body of the document
NOTE
The whole document will be overwrited
Declaration
Swift
public func updateDocument(inCollection coll: String, withID id: String, body: [String: Any], completion: BaasCompletion)
Parameters
inCollection
The collection where you want to update the document
withID
the id of the document
body
(Optional) : new body of the document
- parameters:
-
Grant access to the specified user to the specified document
- parameters:
- toDocument: Id of the document
- inCollection: Name of the collection
- toUser: Username of the user
- accessType: enumeration of types of access ( read, delete, all, update )
Declaration
Swift
public func grantUserAccess(toDocument id: String, inCollection coll: String, toUser user: String, accessType: docAccessTypes, completion: BaasCompletion)
Parameters
toDocument
Id of the document
inCollection
Name of the collection
toUser
Username of the user
accessType
enumeration of types of access ( read, delete, all, update )
- parameters:
-
Grant access to the specified role to the specified document
- parameters:
- toDocument: Id of the document
- inCollection: Name of the collection
- toRole: name of the role
- accessType: enumeration of types of access ( read, delete, all, update )
Declaration
Swift
public func grantRoleAccess(toDocument id: String, inCollection coll: String, toRole roleid: String, accessType: docAccessTypes, completion: BaasCompletion)
Parameters
toDocument
Id of the document
inCollection
Name of the collection
toRole
name of the role
accessType
enumeration of types of access ( read, delete, all, update )
- parameters:
-
Revoke access to the specified user to the specified document
- parameters:
- toDocument: Id of the document
- inCollection: Name of the collection
- toUser: Username of the user
- accessType: enumeration of types of access ( read, delete, all, update )
Declaration
Swift
public func revokeUserAccess(toDocument id: String, inCollection coll: String, toUser user: String, accessType: docAccessTypes, completion: BaasCompletion)
Parameters
toDocument
Id of the document
inCollection
Name of the collection
toUser
Username of the user
accessType
enumeration of types of access ( read, delete, all, update )
- parameters:
-
Revoke access to the specified role to the specified document
- parameters:
- toDocument: Id of the document
- inCollection: Name of the collection
- toRole: name of the role
- accessType: enumeration of types of access ( read, delete, all, update )
Declaration
Swift
public func revokeRoleAccess(toDocument id: String, inCollection coll: String, toRole roleid: String, accessType: docAccessTypes, completion: BaasCompletion)
-
Create a link within two documents with a label
- parameters:
- label: Label of the link
- sourceID: Id of the first document
- destinationID: Id of the second document
Declaration
Swift
public func createLink(label: String, sourceID source: String, destinationID dest: String, completion: BaasCompletion)
Parameters
label
Label of the link
sourceID
Id of the first document
destinationID
Id of the second document
- parameters:
-
Get list of linked documents, you can pass query and pagination criteria
- parameters:
- withID: (Optional) The id of the link you want to retrieve
- parameters: (Optional) query criteria
Declaration
Swift
public func getLinks(withID id: String = "", parameters: [String:AnyHashable] = [:], completion: BaasCompletion)
Parameters
withID
(Optional) The id of the link you want to retrieve
parameters
(Optional) query criteria
- parameters:
-
Delete the link with the provided id
- parameters:
- withID: The id of the link you want to delete
Declaration
Swift
public func deleteLink(withID id: String, completion: BaasCompletion)
Parameters
withID
The id of the link you want to delete
- parameters:
-
Upload the file given as data
- parameters:
- data: data of the file you want to upload
- attachedData : More data you want to store
- permissions : The permissions of the file uploaded ( see ACL )
Declaration
Swift
public func uploadFile(data: Data, attachedData: [String:AnyHashable] = [:], permissions: [String:AnyHashable] = [:], completion: BaasCompletion)
Parameters
data
data of the file you want to upload
attachedData
More data you want to store
permissions
The permissions of the file uploaded ( see ACL )
- parameters:
-
Delete the file with the provided id
- parameters:
- withID: id of the file to delete
Declaration
Swift
public func deleteFile(withID id: String, completion: BaasCompletion)
Parameters
withID
id of the file to delete
- parameters:
-
Get the file with the provided id
- parameters:
- withID: id of the file to get
Declaration
Swift
public func getFile(withID id: String, completion: BaasFileCompletion)
Parameters
withID
id of the file to get
- parameters:
-
Get the file details with the provided id
- parameters:
- withID: id of the file to get
Declaration
Swift
public func getFileDetails(withID id: String, completion: BaasCompletion)
Parameters
withID
id of the file to get
- parameters:
-
Get a list of file details, you can pass query criteria
- parameters:
- parameters: Query criteria
Declaration
Swift
public func getFilesDetails(parameters: [String: AnyHashable] = [:], completion: BaasCompletion)
Parameters
parameters
Query criteria
- parameters:
-
Grant access to the specified user to the specified file
- parameters:
- toFile: Id of the document
- inCollection: Name of the collection
- toUser: Username of the user
- accessType: enumeration of types of access ( read, delete, all, update )
Declaration
Swift
public func grantUserAccess(toFile id: String, toUser userid: String, accessType: docAccessTypes, completion: BaasCompletion)
Parameters
toFile
Id of the document
inCollection
Name of the collection
toUser
Username of the user
accessType
enumeration of types of access ( read, delete, all, update )
- parameters:
-
Grant access to the specified role to the specified file
- parameters:
- toFile: Id of the document
- inCollection: Name of the collection
- toRole: name of the role
- accessType: enumeration of types of access ( read, delete, all, update )
Declaration
Swift
public func grantRoleAccess(toFile id: String, toRole roleid: String, accessType: docAccessTypes, completion: BaasCompletion)
Parameters
toFile
Id of the document
inCollection
Name of the collection
toRole
name of the role
accessType
enumeration of types of access ( read, delete, all, update )
- parameters:
-
Revoke access to the specified user to the specified file
- parameters:
- toFile: Id of the document
- inCollection: Name of the collection
- toUser: Username of the user
- accessType: enumeration of types of access ( read, delete, all, update )
Declaration
Swift
public func revokeUserAccess(toFile id: String, toUser userid: String, accessType: docAccessTypes, completion: BaasCompletion)
Parameters
toFile
Id of the document
inCollection
Name of the collection
toUser
Username of the user
accessType
enumeration of types of access ( read, delete, all, update )
- parameters:
-
Revoke access to the specified role to the specified file
- parameters:
- toFile: Id of the document
- inCollection: Name of the collection
- toRole: name of the role
- accessType: enumeration of types of access ( read, delete, all, update )
Declaration
Swift
public func revokeRoleAccess(toFile id: String, toRole roleid: String, accessType: docAccessTypes, completion: BaasCompletion)
Parameters
toFile
Id of the document
inCollection
Name of the collection
toRole
name of the role
accessType
enumeration of types of access ( read, delete, all, update )
- parameters:
-
Retrieve the asset with the specified name
- parameters:
- name: name of the asset
Declaration
Swift
public func getAsset(name: String, completion: BaasFileCompletion)
Parameters
name
name of the asset
- parameters:
-
Ask the user to enable push notification. You need to add to your AppDelegate:
import UserNotification extension UNUserNotificationDelegate if #available(iOS 10.0, *){ UNUserNotificationCenter.current().delegate = self }
for ios10
Declaration
Swift
public func askToEnablePushNotifications()
-
Add this method in AppDelegate:
didRegisterForRemoteNotificationsWithDeviceToken
Declaration
Swift
public func enablePushNotifications(deviceToken: Data, completion: BaasCompletion)
-
sendNotification(message:users:profiles:sound:badge:actionLocalizedKey:localizedKey:localizedArguments:custom:collapse_key:time_to_live:content_available:category:completion:)
Sends a push notification to the specified users
Declaration
Swift
public func sendNotification(message: String, users: [String], profiles: [pushProfiles] = [.one], sound:String = "", badge: Int = 1, actionLocalizedKey: String = "", localizedKey: String = "", localizedArguments: [String] = [], custom: [String: AnyHashable] = [:], collapse_key:String = "", time_to_live: Int = 2419200, content_available: Int = 1, category: String = "", completion:BaasCompletion)
-
HTTP GET, you can use this to call plugins
- parameters:
- url: the endpoint to call ( note: without the base url ) eg: /plugins/baasbox.plugin
- parameters: list of parameters for the query
Declaration
Swift
public func get(url: String, parameters:[String:AnyHashable], completion: BaasCompletion)
Parameters
url
the endpoint to call ( note: without the base url ) eg: /plugins/baasbox.plugin
parameters
list of parameters for the query
- parameters:
-
HTTP POST, you can use this to call plugins
- parameters:
- url: the endpoint to call ( note: without the base url ) eg: /plugins/baasbox.plugin
- parameters: list of parameters for the query
Declaration
Swift
public func post(url: String, parameters:[String:Any], completion: BaasCompletion)
Parameters
url
the endpoint to call ( note: without the base url ) eg: /plugins/baasbox.plugin
parameters
list of parameters for the query
- parameters:
-
HTTP PUT, you can use this to call plugins
- parameters:
- url: the endpoint to call ( note: without the base url ) eg: /plugins/baasbox.plugin
- parameters: list of parameters for the query
Declaration
Swift
public func put(url: String, parameters:[String:Any], completion: BaasCompletion)
Parameters
url
the endpoint to call ( note: without the base url ) eg: /plugins/baasbox.plugin
parameters
list of parameters for the query
- parameters:
-
HTTP DELETE, you can use this to call plugins
- parameters:
- url: the endpoint to call ( note: without the base url ) eg: /plugins/baasbox.plugin
- parameters: list of parameters for the query
Declaration
Swift
public func delete(url: String, parameters:[String:Any], completion: BaasCompletion)
Parameters
url
the endpoint to call ( note: without the base url ) eg: /plugins/baasbox.plugin
parameters
list of parameters for the query
- parameters:
-
Enum the possible social logins offered by BaasBox
See moreDeclaration
Swift
public enum socialTypes : String
-
Enum the possible access types for documents and files
See moreDeclaration
Swift
public enum docAccessTypes : String
-
Enum the possible app profiles for push notifications
See moreDeclaration
Swift
public enum pushProfiles : Int