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
Missablebad 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
SetupClient.configbefore 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 }
-
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
foreignIdandtimewith 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 thefeedIdsproperty 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
foreignIdandtime. 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
-
Setup the current user with a default
Usertype.Declaration
Swift
@discardableResult public func setupUser(token: Token, completion: @escaping UserCompletion<User>) -> CancellableParameters
completiona completion block with an
Userobject in theResult.tokenthe user Client token.
Return Value
an object to cancel the request.
-
Setup the current user with a custom
Usertype.Declaration
Swift
@discardableResult public func setupUser<T>(_ user: T, token: Token, completion: @escaping UserCompletion<T>) -> Cancellable where T : UserProtocolParameters
usera custom user object.
tokenthe user Client token.
completiona completion block with a custom
Userobject in theResult.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, useClient.setupUserto 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 }
-
Add a collection object to the collection with a given name.
Declaration
Swift
@discardableResult public func add<T: CollectionObjectProtocol>(collectionObject: T, completion: @escaping CollectionObjectCompletion<T>) -> CancellableParameters
collectionObjecta collection object.
completiona completion block with a collection object that was added.
Return Value
an object to cancel the request.
-
Retreive a collection object from the collection by the collection object id.
Declaration
Swift
@discardableResult public func get<T: CollectionObjectProtocol>(typeOf: T.Type, collectionName: String, collectionObjectId: String, completion: @escaping CollectionObjectCompletion<T>) -> CancellableParameters
typeOfa type of a custom collection object type that conformed to
CollectionObjectProtocol.collectionNamea collection name.
collectionObjectIda collection object id.
completiona completion block with a requested collection object.
Return Value
an object to cancel the request.
-
Update a collection object.
Declaration
Swift
@discardableResult public func update<T: CollectionObjectProtocol>(collectionObject: T, completion: @escaping CollectionObjectCompletion<T>) -> CancellableParameters
collectionObjecta collection object.
completiona completion block with an updated collection object.
Return Value
an object to cancel the request.
-
Delete a collection object.
Declaration
Swift
@discardableResult public func delete<T: CollectionObjectProtocol>(collectionObject: T, completion: @escaping StatusCodeCompletion) -> CancellableParameters
collectionObjecta collection object.
completiona completion block with a response status code.
Return Value
an object to cancel the request.
-
Delete a collection object with a given collection name and object id.
Declaration
Swift
@discardableResult public func delete(collectionName: String, collectionObjectId: String, completion: @escaping StatusCodeCompletion) -> CancellableParameters
collectionNamea collection name.
collectionObjectIda collection object id.
completiona completion block with a response status code.
Return Value
an object to cancel the request.
-
Get an aggregated feed with a given feed group
feedSluganduserId.Declaration
Swift
public func aggregatedFeed(feedSlug: String, userId: String) -> AggregatedFeed -
Get an aggregated feed with a given feed group
feedSlugfor 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
feedSluga feed group name.
-
Get an aggregated feed with a given
feedId.Declaration
Swift
public func aggregatedFeed(_ feedId: FeedId) -> AggregatedFeed
-
Get a flat feed with a given feed group
feedSluganduserId.Declaration
Swift
public func flatFeed(feedSlug: String, userId: String) -> FlatFeed -
Get a flat feed with a given feed group
feedSlugfor 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
feedSluga feed group name.
-
Get a notification feed with a given feed group
feedSluganduserId.Declaration
Swift
public func notificationFeed(feedSlug: String, userId: String) -> NotificationFeed -
Get a notification feed with a given feed group
feedSlugfor 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
feedSluga feed group name.
-
Get a notification feed with a given
feedId.Declaration
Swift
public func notificationFeed(_ feedId: FeedId) -> NotificationFeed
-
Upload a
File.Declaration
Swift
@discardableResult public func upload(file: File, completion: @escaping UploadCompletion) -> Cancellable -
Upload a list of
File.Declaration
Swift
@discardableResult public func upload(files: [File], completion: @escaping MultipleUploadCompletion) -> Cancellable -
Delete a file with a given file URL.
Declaration
Swift
@discardableResult public func delete(fileURL: URL, completion: @escaping StatusCodeCompletion) -> Cancellable
-
Upload an image file.
Declaration
Swift
@discardableResult public func upload(image: File, completion: @escaping UploadCompletion) -> Cancellable -
Upload a list of image files.
Declaration
Swift
@discardableResult public func upload(images: [File], completion: @escaping MultipleUploadCompletion) -> Cancellable -
Delete an image file with a given image URL.
Declaration
Swift
@discardableResult public func delete(imageURL: URL, completion: @escaping StatusCodeCompletion) -> Cancellable -
Upload and resize an image with a given image process options.
Declaration
Swift
@discardableResult public func resizeImage(imageProcess: ImageProcess, completion: @escaping UploadCompletion) -> Cancellable
-
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) -> CancellableParameters
urlURL to scrape.
-
Add a reaction to the activity without any extra data.
Declaration
Swift
@discardableResult public func add(reactionTo activityId: String, parentReactionId: String? = nil, kindOf kind: ReactionKind, targetsFeedIds: FeedIds = [], completion: @escaping DefaultReactionCompletion) -> CancellableParameters
activityIdthe activity id for the reaction. Must be a valid activity id.
parentReactionIdthe id of the parent reaction. If provided, it must be the id of a reaction that has no parents.
kindthe type of the reaction. Must not be empty or longer than 255 characters.
targetsFeedIdstarget feeds for the reaction.
completiona completion block with an added reaction.
Return Value
an object to cancel the request.
-
Add a reaction to the activity with extra data type of
ReactionExtraDataProtocol.Declaration
Swift
@discardableResult public func add<T: ReactionExtraDataProtocol, U: UserProtocol>(reactionTo activityId: String, parentReactionId: String? = nil, kindOf kind: ReactionKind, extraData: T, userTypeOf: U.Type, targetsFeedIds: FeedIds = [], completion: @escaping ReactionCompletion<T, U>) -> CancellableParameters
activityIdthe activity id for the reaction. Must be a valid activity id.
parentReactionIdthe id of the parent reaction. If provided, it must be the id of a reaction that has no parents.
kindthe type of the reaction. Must not be empty or longer than 255 characters.
extraDataan extra data for the reaction. Should be an object type of
ReactionExtraDataProtocol.userTypeOfa custom user type of the reaction.
targetsFeedIdstarget feeds for the reaction.
completiona completion block with an added reaction.
Return Value
an object to cancel the request.
-
Add a child reaction without any extra data.
Declaration
Swift
@discardableResult public func add<P: ReactionExtraDataProtocol, U: UserProtocol>(reactionToParentReaction parentReaction: Reaction<P, U>, kindOf kind: ReactionKind, userTypeOf userType: U.Type, targetsFeedIds: FeedIds = [], completion: @escaping ReactionCompletion<EmptyReactionExtraData, U>) -> CancellableParameters
parentReactionthe parent reaction. It must be a reaction that has no parents.
kindthe type of the reaction. Must not be empty or longer than 255 characters.
userTypeOfa custom user type of the reaction.
targetsFeedIdstarget feeds for the reaction.
completiona completion block with an added reaction.
Return Value
an object to cancel the request.
-
Add a child reaction with extra data type of
ReactionExtraDataProtocol.Declaration
Swift
@discardableResult public func add<T: ReactionExtraDataProtocol, P: ReactionExtraDataProtocol, U: UserProtocol>(reactionToParentReaction parentReaction: Reaction<P, U>, kindOf kind: ReactionKind, extraData: T, userTypeOf userType: U.Type, targetsFeedIds: FeedIds = [], completion: @escaping ReactionCompletion<T, U>) -> CancellableParameters
parentReactionthe parent reaction. It must be a reaction that has no parents.
kindthe type of the reaction. Must not be empty or longer than 255 characters.
extraDataan extra data for the reaction. Should be an object type of
ReactionExtraDataProtocol.userTypeOfa custom user type of the reaction.
targetsFeedIdstarget feeds for the reaction.
completiona completion block with an added reaction.
Return Value
an object to cancel the request.
-
Add a reaction by id without any extra data.
Declaration
Swift
@discardableResult public func get(reactionId: String, completion: @escaping DefaultReactionCompletion) -> CancellableParameters
reactionIdthe reaction id.
completiona completion block with a reaction.
Return Value
an object to cancel the request.
-
Add a reaction by id with extra data type of
ReactionExtraDataProtocol.Declaration
Swift
@discardableResult public func get<T: ReactionExtraDataProtocol, U: UserProtocol>(reactionId: String, extraDataTypeOf: T.Type, userTypeOf: U.Type, completion: @escaping ReactionCompletion<T, U>) -> CancellableParameters
reactionIdthe reaction id.
extraDataTypeOfa custom reaction extra data type
ReactionExtraDataProtocolof an extra data.userTypeOfa custom user type of the reaction.
completiona completion block with a reaction.
Return Value
an object to cancel the request.
-
Update a reaction by id with extra data type of
ReactionExtraDataProtocol.Declaration
Swift
@discardableResult public func update<T: ReactionExtraDataProtocol, U: UserProtocol>(reactionId: String, extraData: T, userTypeOf: U.Type, targetsFeedIds: FeedIds = [], completion: @escaping ReactionCompletion<T, U>) -> CancellableParameters
reactionIdthe reaction id.
extraDatathe updated extra data for the reaction.
userTypeOfa custom user type of the reaction.
targetsFeedIdstarget feeds for the reaction.
completiona completion block with an updated reaction.
Return Value
an object to cancel the request.
-
Delete a reaction by id.
Declaration
Swift
@discardableResult public func delete(reactionId: String, completion: @escaping StatusCodeCompletion) -> CancellableParameters
reactionIdthe reaction id.
completiona completion block with a status code of the request.
Return Value
an object to cancel the request.
-
Fetch reactions without any extra data for the activityId.
Declaration
Swift
@discardableResult public func reactions(forActivityId activityId: String, kindOf kind: ReactionKind? = nil, pagination: Pagination = .none, withActivityData: Bool = false, completion: @escaping DefaultReactionsCompletion) -> CancellableParameters
activityIdthe activity id.
kindthe type of reactions.
paginationa pagination options.
withActivityDatareturns the activity data in the result for the given activity id.
completiona completion block with reactions and activity (optional).
Return Value
an object to cancel the request.
-
Fetch reactions for the activityId.
Declaration
Swift
@discardableResult public func reactions<T: ReactionExtraDataProtocol, U: UserProtocol>(forActivityId activityId: String, kindOf kind: ReactionKind? = nil, extraDataTypeOf: T.Type, userTypeOf: U.Type, pagination: Pagination = .none, withActivityData: Bool = false, completion: @escaping ReactionsCompletion<T, U>) -> CancellableParameters
activityIdthe activity id.
kindthe type of reactions.
extraDataTypeOfa custom reaction extra data type
ReactionExtraDataProtocolof an extra data.userTypeOfa custom user type of the reaction.
paginationa pagination options.
withActivityDatareturns the activity data in the result for the given activity id.
completiona completion block with reactions and activity (optional).
Return Value
an object to cancel the request.
-
Fetch reactions without any extra data for the reactionId.
Declaration
Swift
@discardableResult public func reactions(forReactionId reactionId: String, kindOf kind: ReactionKind? = nil, pagination: Pagination = .none, completion: @escaping DefaultReactionsCompletion) -> CancellableParameters
reactionIdthe reaction id.
kindthe type of reactions.
paginationa pagination options.
completiona completion block with reactions.
Return Value
an object to cancel the request.
-
Fetch reactions for the reactionId.
Declaration
Swift
@discardableResult public func reactions<T: ReactionExtraDataProtocol, U: UserProtocol>(forReactionId reactionId: String, kindOf kind: ReactionKind? = nil, extraDataTypeOf: T.Type, userTypeOf: U.Type, pagination: Pagination = .none, completion: @escaping ReactionsCompletion<T, U>) -> CancellableParameters
reactionIdthe reaction id.
kindthe type of reactions.
extraDataTypeOfa custom reaction extra data type
ReactionExtraDataProtocolof an extra data.userTypeOfa custom user type of the reaction.
paginationa pagination options.
completiona completion block with reactions.
Return Value
an object to cancel the request.
-
Fetch reactions without any extra data for the userId.
Declaration
Swift
@discardableResult public func reactions(forUserId userId: String, kindOf kind: ReactionKind? = nil, pagination: Pagination = .none, completion: @escaping DefaultReactionsCompletion) -> CancellableParameters
userIdthe user id.
kindthe type of reactions.
paginationa pagination options.
completiona completion block with reactions.
Return Value
an object to cancel the request.
-
Fetch reactions for the userId.
Declaration
Swift
@discardableResult public func reactions<T: ReactionExtraDataProtocol, U: UserProtocol>(forUserId userId: String, kindOf kind: ReactionKind? = nil, extraDataTypeOf: T.Type, userTypeOf: U.Type, pagination: Pagination = .none, completion: @escaping ReactionsCompletion<T, U>) -> CancellableParameters
userIdthe user id.
kindthe type of reactions.
extraDataTypeOfa custom reaction extra data type
ReactionExtraDataProtocolof an extra data.userTypeOfa custom user type of the reaction.
paginationa pagination options.
completiona completion block with reactions.
Return Value
an object to cancel the request.
-
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 : UserProtocolParameters
useran user of type
UserProtocol, whereidmust not be empty or longer than 255 characters.getOrCreateif true, if a user with the same
idalready exists, it will be returned. Otherwise, the endpoint will return409 Conflict. Default: true.completiona completion block with an user object of the
UserProtocolin theResult.Return Value
an object to cancel the request.
-
Get an user by default
Usertype with a givenuserId.Declaration
Swift
@discardableResult public func get(userId: String, withFollowCounts: Bool = false, completion: @escaping UserCompletion<User>) -> CancellableParameters
userIdan user id string.
withFollowCountsif true, the followingCount and followersCount will be included in the response. Default: false.
completiona completion block with an user object of the
UserProtocolin theResult.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>) -> CancellableParameters
typeOfa type of a custom user type that conformed to
UserProtocol.userIdan user id string.
withFollowCountsif true, the followingCount and followersCount will be included in the response. Default: false.
completiona completion block with an user object of the
UserProtocolin theResult.Return Value
an object to cancel the request.
-
Get the current user with a default
Usertype. If request was sucessful the user would be assigned to theclient.currentUserproperty.Declaration
Swift
@discardableResult public func getCurrentUser(withFollowCounts: Bool = false, completion: @escaping UserCompletion<User>) -> CancellableParameters
withFollowCountsif true, the followingCount and followersCount will be included in the response. Default: false.
completiona completion block with an user object of the
UserProtocolin theResult.Return Value
an object to cancel the request.
-
Get the current user. If request was sucessful the user would be assigned to the
client.currentUserproperty.Declaration
Swift
@discardableResult public func getCurrentUser<T: UserProtocol>(typeOf: T.Type, withFollowCounts: Bool = false, completion: @escaping UserCompletion<T>) -> CancellableParameters
typeOfa type of a custom user type that conformed to
UserProtocol.withFollowCountsif true, the followingCount and followersCount will be included in the response. Default: false.
completiona completion block with an user object of the
UserProtocolin theResult.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 : UserProtocolParameters
userthe user of type
UserProtocol, whereidmust not be empty or longer than 255 characters.completiona completion block with an user object of the
UserProtocolin theResult.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) -> CancellableParameters
userIdan user id string.
completiona completion block with a response status code.
Return Value
an object to cancel the request.
View on GitHub
Client Class Reference