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
SetupClient.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 }
-
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
andtime
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 thefeedIds
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
andtime
. 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
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 theResult
.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 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.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 }
-
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>) -> Cancellable
Parameters
collectionObject
a collection object.
completion
a 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>) -> Cancellable
Parameters
typeOf
a type of a custom collection object type that conformed to
CollectionObjectProtocol
.collectionName
a collection name.
collectionObjectId
a collection object id.
completion
a 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>) -> Cancellable
Parameters
collectionObject
a collection object.
completion
a 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) -> Cancellable
Parameters
collectionObject
a collection object.
completion
a 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) -> Cancellable
Parameters
collectionName
a collection name.
collectionObjectId
a collection object id.
completion
a completion block with a response status code.
Return Value
an object to cancel the request.
-
Get an aggregated feed with a given feed group
feedSlug
anduserId
.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
-
Get a flat feed with a given feed group
feedSlug
anduserId
.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 notification feed with a given feed group
feedSlug
anduserId
.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
-
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) -> Cancellable
Parameters
url
URL 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) -> Cancellable
Parameters
activityId
the activity id for the reaction. Must be a valid activity id.
parentReactionId
the id of the parent reaction. If provided, it must be the id of a reaction that has no parents.
kind
the type of the reaction. Must not be empty or longer than 255 characters.
targetsFeedIds
target feeds for the reaction.
completion
a 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>) -> Cancellable
Parameters
activityId
the activity id for the reaction. Must be a valid activity id.
parentReactionId
the id of the parent reaction. If provided, it must be the id of a reaction that has no parents.
kind
the type of the reaction. Must not be empty or longer than 255 characters.
extraData
an extra data for the reaction. Should be an object type of
ReactionExtraDataProtocol
.userTypeOf
a custom user type of the reaction.
targetsFeedIds
target feeds for the reaction.
completion
a 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>) -> Cancellable
Parameters
parentReaction
the parent reaction. It must be a reaction that has no parents.
kind
the type of the reaction. Must not be empty or longer than 255 characters.
userTypeOf
a custom user type of the reaction.
targetsFeedIds
target feeds for the reaction.
completion
a 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>) -> Cancellable
Parameters
parentReaction
the parent reaction. It must be a reaction that has no parents.
kind
the type of the reaction. Must not be empty or longer than 255 characters.
extraData
an extra data for the reaction. Should be an object type of
ReactionExtraDataProtocol
.userTypeOf
a custom user type of the reaction.
targetsFeedIds
target feeds for the reaction.
completion
a 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) -> Cancellable
Parameters
reactionId
the reaction id.
completion
a 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>) -> Cancellable
Parameters
reactionId
the reaction id.
extraDataTypeOf
a custom reaction extra data type
ReactionExtraDataProtocol
of an extra data.userTypeOf
a custom user type of the reaction.
completion
a 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>) -> Cancellable
Parameters
reactionId
the reaction id.
extraData
the updated extra data for the reaction.
userTypeOf
a custom user type of the reaction.
targetsFeedIds
target feeds for the reaction.
completion
a 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) -> Cancellable
Parameters
reactionId
the reaction id.
completion
a 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) -> Cancellable
Parameters
activityId
the activity id.
kind
the type of reactions.
pagination
a pagination options.
withActivityData
returns the activity data in the result for the given activity id.
completion
a 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>) -> Cancellable
Parameters
activityId
the activity id.
kind
the type of reactions.
extraDataTypeOf
a custom reaction extra data type
ReactionExtraDataProtocol
of an extra data.userTypeOf
a custom user type of the reaction.
pagination
a pagination options.
withActivityData
returns the activity data in the result for the given activity id.
completion
a 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) -> Cancellable
Parameters
reactionId
the reaction id.
kind
the type of reactions.
pagination
a pagination options.
completion
a 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>) -> Cancellable
Parameters
reactionId
the reaction id.
kind
the type of reactions.
extraDataTypeOf
a custom reaction extra data type
ReactionExtraDataProtocol
of an extra data.userTypeOf
a custom user type of the reaction.
pagination
a pagination options.
completion
a 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) -> Cancellable
Parameters
userId
the user id.
kind
the type of reactions.
pagination
a pagination options.
completion
a 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>) -> Cancellable
Parameters
userId
the user id.
kind
the type of reactions.
extraDataTypeOf
a custom reaction extra data type
ReactionExtraDataProtocol
of an extra data.userTypeOf
a custom user type of the reaction.
pagination
a pagination options.
completion
a 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 : UserProtocol
Parameters
user
an user of type
UserProtocol
, whereid
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 return409 Conflict
. Default: true.completion
a completion block with an user object of the
UserProtocol
in theResult
.Return Value
an object to cancel the request.
-
Get an user by default
User
type with a givenuserId
.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 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>) -> 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 theResult
.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 theclient.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 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.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 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 : UserProtocol
Parameters
user
the user of type
UserProtocol
, whereid
must not be empty or longer than 255 characters.completion
a completion block with an user object of the
UserProtocol
in 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) -> Cancellable
Parameters
userId
an user id string.
completion
a completion block with a response status code.
Return Value
an object to cancel the request.