diff --git a/CHANGELOG.md b/CHANGELOG.md index 413e7b5..507cec2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Get 0.x +## Get 0.2.1 + +*Dec 24, 2021* + +- Remove `value(for:)`. It's not a great convenience method if it requires the same amount of code as an regular version. + +```swift +let user: User = try await client.send(.get("/user")).value +let user: User = try await client.value(for: .get("/user")) +``` + ## Get 0.2 *Dec 23, 2021* diff --git a/Sources/Get/APIClient.swift b/Sources/Get/APIClient.swift index b1156b2..1bd56e0 100644 --- a/Sources/Get/APIClient.swift +++ b/Sources/Get/APIClient.swift @@ -58,11 +58,6 @@ public actor APIClient { self.delegate = configuration.delegate ?? DefaultAPIClientDelegate() self.serializer = Serializer(decoder: configuration.decoder, encoder: configuration.encoder) } - - /// Returns a decoded response value for the given request. - public func value(for request: Request) async throws -> T { - try await send(request).value - } /// Sends the given request and returns a response with a decoded response value. public func send(_ request: Request) async throws -> Response { diff --git a/Tests/GetTests/ClientAuthorizationTests.swift b/Tests/GetTests/ClientAuthorizationTests.swift index 9f7aa41..d7a130f 100644 --- a/Tests/GetTests/ClientAuthorizationTests.swift +++ b/Tests/GetTests/ClientAuthorizationTests.swift @@ -39,7 +39,7 @@ final class APIClientAuthorizationTests: XCTestCase { mock.register() // WHEN - let user: User = try await client.value(for: .get("/user")) + let user: User = try await client.send(.get("/user")).value // THEN XCTAssertEqual(user.login, "kean") diff --git a/Tests/GetTests/ClientIIntegrationTests.swift b/Tests/GetTests/ClientIIntegrationTests.swift index 7cc4480..232aa00 100644 --- a/Tests/GetTests/ClientIIntegrationTests.swift +++ b/Tests/GetTests/ClientIIntegrationTests.swift @@ -16,7 +16,7 @@ final class APIClientIntegrationTests: XCTestCase { } func _testGitHubUsersApi() async throws { - let user = try await sut.value(for: Resources.users("kean").get) + let user = try await sut.send(Paths.users("kean").get).value XCTAssertEqual(user.login, "kean") } diff --git a/Tests/GetTests/ClientTests.swift b/Tests/GetTests/ClientTests.swift index d2ee140..9b62bc5 100644 --- a/Tests/GetTests/ClientTests.swift +++ b/Tests/GetTests/ClientTests.swift @@ -27,7 +27,7 @@ final class APIClientTests: XCTestCase { Mock.get(url: url, json: "user").register() // WHEN - let user: User = try await client.value(for: .get("/user")) + let user: User = try await client.send(.get("/user")).value // THEN XCTAssertEqual(user.login, "kean") @@ -39,7 +39,7 @@ final class APIClientTests: XCTestCase { Mock.get(url: url, json: "user").register() // WHEN - let response = try await client.send(Resources.user.get) + let response = try await client.send(Paths.user.get) // THEN the client returns not just the value, but data, original // request, and more @@ -86,7 +86,7 @@ final class APIClientTests: XCTestCase { Mock.get(url: url, json: "user").register() // WHEN - let user: User = try await client.value(for: .get("/user")) + let user: User = try await client.send(.get("/user")).value // THEN returns decoded JSON XCTAssertEqual(user.login, "kean") @@ -101,7 +101,7 @@ final class APIClientTests: XCTestCase { ]).register() // WHEN - let data: Data = try await client.value(for: .get("/user")) + let data: Data = try await client.send(.get("/user")).value // THEN return unprocessed data (NOT what Data: Decodable does by default) XCTAssertEqual(String(data: data, encoding: .utf8), "Hello") @@ -116,7 +116,7 @@ final class APIClientTests: XCTestCase { ]).register() // WHEN - let text: String = try await client.value(for: .get("/user")) + let text: String = try await client.send(.get("/user")).value // THEN XCTAssertEqual(text, "hello") diff --git a/Tests/GetTests/GitHubAPI.swift b/Tests/GetTests/GitHubAPI.swift index 4951ee1..0a35123 100644 --- a/Tests/GetTests/GitHubAPI.swift +++ b/Tests/GetTests/GitHubAPI.swift @@ -7,11 +7,11 @@ import Get // An example of an API definition. Feel free to use any other method for // organizing the resources. -public enum Resources {} +public enum Paths {} // MARK: - /user -extension Resources { +extension Paths { public static var user: UserResource { UserResource() } public struct UserResource { @@ -23,7 +23,7 @@ extension Resources { // MARK: - /user/emails -extension Resources.UserResource { +extension Paths.UserResource { public var emails: EmailsResource { EmailsResource() } public struct EmailsResource { @@ -43,7 +43,7 @@ extension Resources.UserResource { // MARK: - /users/{username} -extension Resources { +extension Paths { public static func users(_ name: String) -> UsersResource { UsersResource(path: "/users/\(name)") } @@ -57,7 +57,7 @@ extension Resources { // MARK: - /users/{username}/followers -extension Resources.UsersResource { +extension Paths.UsersResource { public var followers: FollowersResource { FollowersResource(path: path + "/followers") } public struct FollowersResource { @@ -121,12 +121,12 @@ func usage() async throws { $0.delegate = GitHubAPIClientDelegate() } - let _ = try await client.value(for: Resources.user.get) - let _ = try await client.value(for: Resources.user.emails.get) + let _ = try await client.send(Paths.user.get) + let _ = try await client.send(Paths.user.emails.get) // try await client.send(Resources.user.emails.delete(["octocat@gmail.com"])) - let _ = try await client.value(for: Resources.users("kean").followers.get) + let _ = try await client.send(Paths.users("kean").followers.get) - let _: User = try await client.value(for: .get("/user")) + let _: User = try await client.send(.get("/user")).value }