Client

public final class Client
extension Client: CustomStringConvertible

GetStream client.

  • The current user id from the Token.

    Declaration

    Swift

    public internal(set) var currentUserId: String? { get }
  • The current user.

    Declaration

    Swift

    public internal(set) var currentUser: UserProtocol? { get }
  • A configuration to initialize the shared Client.

    Declaration

    Swift

    public static var config: Client.Config
  • Enable this if you want to wrap any Missable bad decoded objects as missed.

    Note

    If it’s enabled the parser will return a response with missed objects and print errors in logs.

    Declaration

    Swift

    public static var keepBadDecodedObjectsAsMissed: Bool
  • A shared client.

    Note

    Setup Client.config before using a shared client. “` // Setup a shared client. Client.config = .init(apiKey: "API_KEY”, appId: “APP_ID”, token: “TOKEN”)

    // Create Chris’s user feed. let chrisFeed = Client.shared.flatFeed(feedSlug: “user”, userId: “chris”)

    Declaration

    Swift

    public static let shared: Client
  • Checks if API key and App Id are valid.

    Declaration

    Swift

    public var isValid: Bool { get }

Client Activities

  • Receive activities by activity ids with a custom activity type.

    Note

    A maximum length of list of activityIds is 100.

    Declaration

    Swift

    @discardableResult
    public func get<T: ActivityProtocol>(enrich: Bool = true,
                                         typeOf type: T.Type,
                                         activityIds: [String],
                                         completion: @escaping ActivitiesCompletion<T>) -> Cancellable
  • Receive activities by pairs of foreignId and time with a custom activity type.

    Note

    A maximum length of list of foreignIds and times is 100.

    Declaration

    Swift

    @discardableResult
    public func get<T: ActivityProtocol>(enrich: Bool = true,
                                         typeOf type: T.Type,
                                         foreignIds: [String],
                                         times: [Date],
                                         completion: @escaping ActivitiesCompletion<T>) -> Cancellable
  • Update activities data.

    Note

    When you update an activity, you must include the following fields both when adding and updating the activity:
    • time
    • foreignId

    Note

    It is not possible to update more than 100 activities per request with this method.

    Note

    When updating an activity any changes to the feedIds property are ignored.

    Declaration

    Swift

    @discardableResult
    public func update<T>(activities: [T], completion: @escaping StatusCodeCompletion) -> Cancellable where T : ActivityProtocol
  • Update an activity fields by activityId. It is possible to update only a part of an activity with the partial update request. You can think of it as a quick “patching operation”.

    Note

    Note: it is not possible to include the following reserved fields in a partial update request (set or unset):
    • id
    • actor
    • verb
    • object
    • time
    • target
    • foreign_id
    • to
    • origin

    Note

    Note: the size of an activity’s payload must be less than 10KB after all set and unset operations are applied. The size is based on the size of the JSON-encoded activity.

    Declaration

    Swift

    @discardableResult
    public func updateActivity<T: ActivityProtocol>(typeOf type: T.Type,
                                                    setProperties properties: Properties? = nil,
                                                    unsetPropertiesNames names: [String]? = nil,
                                                    activityId: String,
                                                    completion: @escaping ActivityCompletion<T>) -> Cancellable
  • Update an activity fields by foreignId and time. It is possible to update only a part of an activity with the partial update request. You can think of it as a quick “patching operation”.

    Note

    Note: it is not possible to include the following reserved fields in a partial update request (set or unset):
    • id
    • actor
    • verb
    • object
    • time
    • target
    • foreign_id
    • to
    • origin

    Note

    Note: the size of an activity’s payload must be less than 10KB after all set and unset operations are applied. The size is based on the size of the JSON-encoded activity.

    Declaration

    Swift

    @discardableResult
    public func updateActivity<T: ActivityProtocol>(typeOf type: T.Type,
                                                    setProperties properties: Properties? = nil,
                                                    unsetPropertiesNames names: [String]? = nil,
                                                    foreignId: String,
                                                    time: Date,
                                                    completion: @escaping ActivityCompletion<T>) -> Cancellable

Client User Setup

  • Setup the current user with a default User type.

    Declaration

    Swift

    @discardableResult
    public func setupUser(token: Token, completion: @escaping UserCompletion<User>) -> Cancellable

    Parameters

    completion

    a completion block with an User object in the Result.

    token

    the user Client token.

    Return Value

    an object to cancel the request.

  • Setup the current user with a custom User type.

    Declaration

    Swift

    @discardableResult
    public func setupUser<T>(_ user: T, token: Token, completion: @escaping UserCompletion<T>) -> Cancellable where T : UserProtocol

    Parameters

    user

    a custom user object.

    token

    the user Client token.

    completion

    a completion block with a custom User object in the Result.

    Return Value

    an object to cancel the request.

  • Disconnect from Stream and reset the current user.

    Resets and removes the user/token pair as well as relevant network connections.

    Note

    To restore the connection, use Client.setupUser to set a valid user/token pair.

    Declaration

    Swift

    public func disconnect()
  • GetStream version number.

    Declaration

    Swift

    public static let version: String
  • Declaration

    Swift

    public var description: String { get }

Config

  • A configuration for the shared Stream Client.

    See more

    Declaration

    Swift

    public struct Config

Client Collections

Client Aggregated Feed

  • Get an aggregated feed with a given feed group feedSlug and userId.

    Declaration

    Swift

    public func aggregatedFeed(feedSlug: String, userId: String) -> AggregatedFeed
  • Get an aggregated feed with a given feed group feedSlug for the current user if it specified in the Token.

    Note

    If the current user is nil in the Token, then the returned feed would be nil.

    Declaration

    Swift

    public func aggregatedFeed(feedSlug: String) -> AggregatedFeed?

    Parameters

    feedSlug

    a feed group name.

  • Get an aggregated feed with a given feedId.

    Declaration

    Swift

    public func aggregatedFeed(_ feedId: FeedId) -> AggregatedFeed

Client Flat Feed

  • Get a flat feed with a given feed group feedSlug and userId.

    Declaration

    Swift

    public func flatFeed(feedSlug: String, userId: String) -> FlatFeed
  • Get a flat feed with a given feed group feedSlug for the current user if it specified in the Token.

    Note

    If the current user is nil in the Token, then the returned feed would be nil.

    Declaration

    Swift

    public func flatFeed(feedSlug: String) -> FlatFeed?

    Parameters

    feedSlug

    a feed group name.

  • Get a flat feed with a given feedId.

    Declaration

    Swift

    public func flatFeed(_ feedId: FeedId) -> FlatFeed

Client Notification Feed

  • Get a notification feed with a given feed group feedSlug and userId.

    Declaration

    Swift

    public func notificationFeed(feedSlug: String, userId: String) -> NotificationFeed
  • Get a notification feed with a given feed group feedSlug for the current user if it specified in the Token.

    Note

    If the current user is nil in the Token, then the returned feed would be nil.

    Declaration

    Swift

    public func notificationFeed(feedSlug: String) -> NotificationFeed?

    Parameters

    feedSlug

    a feed group name.

  • Get a notification feed with a given feedId.

    Declaration

    Swift

    public func notificationFeed(_ feedId: FeedId) -> NotificationFeed

Client Files

Client Images

Client Open Graph

  • The Open Graph can be used to scrape (GET) open graph data from a website.

    Declaration

    Swift

    @discardableResult
    public func og(url: URL, completion: @escaping OGCompletion) -> Cancellable

    Parameters

    url

    URL to scrape.

Client Reactions

Client User

  • Create or add an user with a given data.

    Declaration

    Swift

    @discardableResult
    public func create<T>(user: T, getOrCreate: Bool = true, completion: @escaping UserCompletion<T>) -> Cancellable where T : UserProtocol

    Parameters

    user

    an user of type UserProtocol, where id must not be empty or longer than 255 characters.

    getOrCreate

    if true, if a user with the same id already exists, it will be returned. Otherwise, the endpoint will return 409 Conflict. Default: true.

    completion

    a completion block with an user object of the UserProtocol in the Result.

    Return Value

    an object to cancel the request.

  • Get an user by default User type with a given userId.

    Declaration

    Swift

    @discardableResult
    public func get(userId: String, withFollowCounts: Bool = false, completion: @escaping UserCompletion<User>) -> Cancellable

    Parameters

    userId

    an user id string.

    withFollowCounts

    if true, the followingCount and followersCount will be included in the response. Default: false.

    completion

    a completion block with an user object of the UserProtocol in the Result.

    Return Value

    an object to cancel the request.

  • Get an user with a given userId.

    Declaration

    Swift

    @discardableResult
    public func get<T: UserProtocol>(typeOf: T.Type,
                                     userId: String,
                                     withFollowCounts: Bool = false,
                                     completion: @escaping UserCompletion<T>) -> Cancellable

    Parameters

    typeOf

    a type of a custom user type that conformed to UserProtocol.

    userId

    an user id string.

    withFollowCounts

    if true, the followingCount and followersCount will be included in the response. Default: false.

    completion

    a completion block with an user object of the UserProtocol in the Result.

    Return Value

    an object to cancel the request.

  • Get the current user with a default User type. If request was sucessful the user would be assigned to the client.currentUser property.

    Declaration

    Swift

    @discardableResult
    public func getCurrentUser(withFollowCounts: Bool = false, completion: @escaping UserCompletion<User>) -> Cancellable

    Parameters

    withFollowCounts

    if true, the followingCount and followersCount will be included in the response. Default: false.

    completion

    a completion block with an user object of the UserProtocol in the Result.

    Return Value

    an object to cancel the request.

  • Get the current user. If request was sucessful the user would be assigned to the client.currentUser property.

    Declaration

    Swift

    @discardableResult
    public func getCurrentUser<T: UserProtocol>(typeOf: T.Type,
                                                withFollowCounts: Bool = false,
                                                completion: @escaping UserCompletion<T>) -> Cancellable

    Parameters

    typeOf

    a type of a custom user type that conformed to UserProtocol.

    withFollowCounts

    if true, the followingCount and followersCount will be included in the response. Default: false.

    completion

    a completion block with an user object of the UserProtocol in the Result.

    Return Value

    an object to cancel the request.

  • Update the user data.

    Declaration

    Swift

    @discardableResult
    public func update<T>(user: T, completion: @escaping UserCompletion<T>) -> Cancellable where T : UserProtocol

    Parameters

    user

    the user of type UserProtocol, where id must not be empty or longer than 255 characters.

    completion

    a completion block with an user object of the UserProtocol in the Result.

    Return Value

    an object to cancel the request.

  • Delete a user with a given userId.

    Declaration

    Swift

    @discardableResult
    public func delete(userId: String, completion: @escaping StatusCodeCompletion) -> Cancellable

    Parameters

    userId

    an user id string.

    completion

    a completion block with a response status code.

    Return Value

    an object to cancel the request.