From 7cb2dbb5e66c59469adeb0139f614c3176a4f93e Mon Sep 17 00:00:00 2001 From: wtimme Date: Wed, 6 May 2020 14:25:52 +0200 Subject: [PATCH] Add pagination support to "users.list" (#182) * #171 Have each parameter on a dedicated line This makes it easier to add new ones without exceeding a readable line length. * #171 Add optional parameter `cursor` to "users.list" * #171 Read `next_cursor` from "users.list" response This allows callers to properly use the pagination of this API method. * #171 Add support for "limit" parameter of users.list call --- SKWebAPI/Sources/WebAPI.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/SKWebAPI/Sources/WebAPI.swift b/SKWebAPI/Sources/WebAPI.swift index 78eef71..886cc42 100755 --- a/SKWebAPI/Sources/WebAPI.swift +++ b/SKWebAPI/Sources/WebAPI.swift @@ -1156,10 +1156,21 @@ extension WebAPI { } } - public func usersList(includePresence: Bool = false, success: ((_ userList: [[String: Any]]?) -> Void)?, failure: FailureClosure?) { - let parameters: [String: Any] = ["token": token, "presence": includePresence] + public func usersList(cursor: String? = nil, + limit: Int? = nil, + includePresence: Bool = false, + success: ((_ userList: [[String: Any]]?, _ nextCursor: String?) -> Void)?, + failure: FailureClosure?) { + var parameters: [String: Any] = ["token": token, "presence": includePresence] + if let cursor = cursor { + parameters["cursor"] = cursor + } + if let limit = limit { + parameters["limit"] = limit + } + networkInterface.request(.usersList, parameters: parameters, successClosure: {(response) in - success?(response["members"] as? [[String: Any]]) + success?(response["members"] as? [[String: Any]], (response["response_metadata"] as? [String: Any])?["next_cursor"] as? String) }) {(error) in failure?(error) }