Swiftpack.co - Package - kibosoftware/kibo-rti-swift


RTI SDK provides access to Kibo recommendation system for iOS devices.

To install the package you can use Swift package system. Example of a package which uses Rti package:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "PlayRti",
    pkgConfig: nil,
    providers: nil,
    dependencies: [
        .package(url: "https://github.com/kibosoftware/kibo-rti-swift.git",
                 from: "1.1.1"),
    targets: [.target(name: "PlayRti", dependencies: ["Rti"])]

Results of API requests are available in callbacks. As a rule, client passes parsed value, raw data and error to callback.

To use RTI API, userId and condition have to be set up. You can get these values using, getPolicy function.

let client = RtiClient(instance: "sun_fun", domain: "sun-fun")
client.customer = client.getCustomerNameCode()

try! client.getPolicy { policy, data, response, error in
    client.customer = policy!.customer
    client.condition = policy?.condition!
    client.userId = policy?.userId!

sendEvent uploades events like moving another screen or clicking on recommendation to event collector. To use it, you have to initialize Event record:

try! client.sendEvent(
    event: Event(action: .visit, document: "http://document/address",
                 destination: nil, widget: nil,
                 trackingData: /* tracking data */,
                 interval: nil,
                     [Event.PurchaseDetails(productId: "productId",
                                            amount: 2, cost: 45)],
                 discoveryInfo: [Event.DiscoveryInfo(
                     name: "document",
                     id: "http://www.yourshop.com/productId",
                     attrs: [
                         Attr(name: "page_type_web", values: ["detail"]),
)) { data, response, error in
    /* Process results */

To get recommendation, you can use getRecommendations function. It's possible to change content of recommendation by adding additional parameters.

    pageTemplate: "ProductDetailPage",
    entities: [Param(name: .productId, value: "3423063301700"),
               Param(name: .productId, value: "0874063791550"),
               Param(name: .visitstrail,
                     value: ["id0", "id1", "id2"].joined(separator: ", "))],
    attributes: ["*"]) { rec, data, response, error in
    /* Process results */

Param record is wrapper for url parameters in API requests. There're two ways of setting parameter key: with string or with enumeration.

// Parameter name is set by enum
[Param(name: .externalId, value: "your_custom_user_id"),
// Same parameter name is set by String
 Param(name: "bnExtUserId", value: "your_custom_user_id")]

Play target is a playground with example of client usage.


Stars: 0
Help us keep the lights on


Used By

Total: 0