EventClient
public class EventClient : BaseClient
Responsible for sending data to a PredictionIO Event Server.
-
Creates a client instance to connect to the Event Server.
Declaration
Swift
public init(accessKey: String, baseURL: String = "http://localhost:7070", channel: String? = nil, timout: TimeInterval = 5)
Parameters
accessKey
The access key to the Event Server’s app.
baseURL
The base URL of the Event Server.
http://localhost:8000
by default.channel
The channel name of the app.
nil
by default.timeout
The request timeout. 5 seconds by default.
Return Value
The
EventClient
instance.
-
Creates an event in the Event Server.
Declaration
Swift
public func createEvent(_ event: Event, completionHandler: @escaping (Result<CreateEventResponse, PIOError>) -> Void)
Parameters
event
The
Event
to be created.completionHandler
The callback to be executed when the request has finished.
-
Creates a batch of events in the Event Server.
Declaration
Swift
public func createBatchEvents(_ events: [Event], completionHandler: @escaping (Result<CreateBatchEventsResponse, PIOError>) -> Void)
Parameters
events
The
Event
s to be created.completionHandler
The callback to be executed when the request has finished.
-
Retrieves events from the Event Server.
Declaration
Parameters
startTime
Find events with
eventTime >= startTime
.nil
by default.endTime
Find events with
eventTime < endTime
.nil
by default.entityType
Find events with this
entityType
only.nil
by default.entityID
Find events with this
entityID
only.nil
by default.limit
The number of record events returned. Set -1 to get all. 20 by default.
reversed
Returns events in reversed chronological order. Must be used with both
entityType
andentityID
specified.false
by default.completionHandler
The callback to be executed when the request has finished.
-
Deletes an event from the Event Server.
Declaration
Swift
public func deleteEvent(eventID: String, completionHandler: @escaping (PIOError?) -> Void)
Parameters
eventID
The event ID.
completionHandler
The callback to be executed when the request has finished.
-
Sets properties of a user.
Declaration
Swift
func setUser(userID: String, properties: [String: Any], eventTime: Date = Date(), completionHandler: @escaping (Result<CreateEventResponse, PIOError>) -> Void)
Parameters
userID
The user ID.
properties
The properties to be set.
eventTime
The event time. Current local time by default.
completionHandler
The callback to be executed when the request has finished.
-
Unsets properties of a user.
Declaration
Swift
func unsetUser(userID: String, properties: [String: Any], eventTime: Date = Date(), completionHandler: @escaping (Result<CreateEventResponse, PIOError>) -> Void)
Parameters
userID
The user ID.
properties
The properties to be unset.
eventTime
The event time. Current local time by default.
completionHandler
The callback to be executed when the request has finished.
-
Deletes a user.
Declaration
Swift
func deleteUser(userID: String, eventTime: Date = Date(), completionHandler: @escaping (Result<CreateEventResponse, PIOError>) -> Void)
Parameters
userID
The user ID.
eventTime
The event time. Current local time by default.
completionHandler
The callback to be executed when the request has finished.
-
Sets properties of an item.
Declaration
Swift
func setItem(itemID: String, properties: [String: Any], eventTime: Date = Date(), completionHandler: @escaping (Result<CreateEventResponse, PIOError>) -> Void)
Parameters
itemID
The item ID.
properties
The properties to be set.
eventTime
The event time. Current local time by default.
completionHandler
The callback to be executed when the request has finished.
-
Unsets properties of an item.
Declaration
Swift
func unsetItem(itemID: String, properties: [String: Any], eventTime: Date = Date(), completionHandler: @escaping (Result<CreateEventResponse, PIOError>) -> Void)
Parameters
itemID
The item ID.
properties
The properties to be unset.
eventTime
The event time. Current local time by default.
completionHandler
The callback to be executed when the request has finished.
-
Deletes an item.
Declaration
Swift
func deleteItem(itemID: String, eventTime: Date = Date(), completionHandler: @escaping (Result<CreateEventResponse, PIOError>) -> Void)
Parameters
itemID
The item ID.
eventTime
The event time. Current local time by default.
completionHandler
The callback to be executed when the request has finished.
-
Creates a user-to-item action.
Declaration
Swift
func recordAction(_ action: String, byUserID userID: String, onItemID itemID: String, properties: [String: Any]? = nil, eventTime: Date = Date(), completionHandler: @escaping (Result<CreateEventResponse, PIOError>) -> Void)
Parameters
action
The action to be used as event name.
userID
The userID.
itemID
The item ID.
properties
The properties of the event.
nil
by default.eventTime
The event time. Current local time by default.
completionHandler
The callback to be executed when the request has finished.