From eca05648ada9f99253e94958989700b9918f3d21 Mon Sep 17 00:00:00 2001 From: sbertix Date: Sun, 13 Dec 2020 23:01:29 +0100 Subject: [PATCH] Add username/name querying for followers/ing --- .../Swiftagram/Endpoints/EndpointFriendship.swift | 15 +++++++++++---- Tests/SwiftagramTests/EndpointTests.swift | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Sources/Swiftagram/Endpoints/EndpointFriendship.swift b/Sources/Swiftagram/Endpoints/EndpointFriendship.swift index a711d4b1..b18e2a84 100644 --- a/Sources/Swiftagram/Endpoints/EndpointFriendship.swift +++ b/Sources/Swiftagram/Endpoints/EndpointFriendship.swift @@ -19,11 +19,15 @@ public extension Endpoint { /// /// - parameters: /// - identifier: A `String` holding reference to a valid user identifier. + /// - query: An optional `String` representing a username or name component to query following. Defaults to `nil`. /// - page: An optional `String` holding reference to a valid cursor. Defaults to `nil`. /// - note: This is equal to the user's **following**. - public static func followed(by identifier: String, startingAt page: String? = nil) -> Paginated { + public static func followed(by identifier: String, + matching query: String? = nil, + startingAt page: String? = nil) -> Paginated { base.appending(path: identifier) .following + .appending(query: "q", with: query) .paginating(process: Swiftagram.User.Collection.self, value: page) .locking(Secret.self) } @@ -32,13 +36,16 @@ public extension Endpoint { /// /// - parameters: /// - identifier: A `String` holding reference to a valid user identifier. + /// - query: An optional `String` representing a username or name component to query followers. Defaults to `nil`. /// - page: An optional `String` holding reference to a valid cursor. Defaults to `nil`. /// - note: This is equal to the user's **followers**. - public static func following(_ identifier: String, startingAt page: String? = nil) -> Paginated { + public static func following(_ identifier: String, + matching query: String? = nil, + startingAt page: String? = nil) -> Paginated { base.appending(path: identifier) .followers - .paginating(process: Swiftagram.User.Collection.self, - value: page) + .appending(query: "q", with: query) + .paginating(process: Swiftagram.User.Collection.self, value: page) .locking(Secret.self) } diff --git a/Tests/SwiftagramTests/EndpointTests.swift b/Tests/SwiftagramTests/EndpointTests.swift index 677b9959..17def587 100644 --- a/Tests/SwiftagramTests/EndpointTests.swift +++ b/Tests/SwiftagramTests/EndpointTests.swift @@ -222,6 +222,8 @@ final class EndpointTests: XCTestCase { func testEndpointFriendship() { performTest(on: Endpoint.Friendship.followed(by: "183250726")) performTest(on: Endpoint.Friendship.following("183250726")) + performTest(on: Endpoint.Friendship.followed(by: "183250726", matching: "a")) + performTest(on: Endpoint.Friendship.following("183250726", matching: "a")) performTest(on: Endpoint.Friendship.summary(for: "25025320")) performTest(on: Endpoint.Friendship.summary(for: ["25025320"])) performTest(on: Endpoint.Friendship.pendingRequests())