Skip to content

Commit 90696a7

Browse files
authored
Merge pull request #53 from makinosp/develop
refact: rename parameters in the client method
2 parents 7140457 + 87fb029 commit 90696a7

File tree

8 files changed

+27
-27
lines changed

8 files changed

+27
-27
lines changed

Sources/VRCKit/APIServices/AuthenticationService.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public struct AuthenticationService {
2424
public static func isExists(_ client: APIClient, userId: String) async throws -> Bool {
2525
let path = "\(authPath)/exists"
2626
let queryItems = [URLQueryItem(name: "username", value: userId.description)]
27-
let response = try await client.request(path: path, httpMethod: .get, queryItems: queryItems)
27+
let response = try await client.request(path: path, method: .get, queryItems: queryItems)
2828
let result: ExistsResponse = try Util.shared.decode(response.data)
2929
return result.userExists
3030
}
@@ -34,7 +34,7 @@ public struct AuthenticationService {
3434
_ client: APIClient
3535
) async throws -> UserOrRequires {
3636
let path = "\(authPath)/user"
37-
let response = try await client.request(path: path, httpMethod: .get, basic: true)
37+
let response = try await client.request(path: path, method: .get, basic: true)
3838
do {
3939
let user: User = try Util.shared.decode(response.data)
4040
return user
@@ -57,23 +57,23 @@ public struct AuthenticationService {
5757
let requestData = try Util.shared.encode(VerifyRequest(code: code))
5858
let response = try await client.request(
5959
path: path,
60-
httpMethod: .post,
61-
httpBody: requestData
60+
method: .post,
61+
body: requestData
6262
)
6363
let result: VerifyResponse = try Util.shared.decode(response.data)
6464
return result.verified
6565
}
6666

6767
/// Verify Auth Token
6868
public static func verifyAuthToken(_ client: APIClient) async throws -> Bool {
69-
let response = try await client.request(path: authPath, httpMethod: .get)
69+
let response = try await client.request(path: authPath, method: .get)
7070
let result: VerifyAuthTokenResponse = try Util.shared.decode(response.data)
7171
return result.ok
7272
}
7373

7474
/// Logout
7575
public static func logout(_ client: APIClient) async throws {
76-
_ = try await client.request(path: "logout", httpMethod: .put)
76+
_ = try await client.request(path: "logout", method: .put)
7777
client.deleteCookies()
7878
}
7979
}

Sources/VRCKit/APIServices/FavoriteService.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public struct FavoriteService {
2929
_ client: APIClient
3030
) async throws -> [FavoriteGroup] {
3131
let path = "favorite/groups"
32-
let response = try await client.request(path: path, httpMethod: .get)
32+
let response = try await client.request(path: path, method: .get)
3333
return try Util.shared.decode(response.data)
3434
}
3535

@@ -46,7 +46,7 @@ public struct FavoriteService {
4646
if let tag = tag {
4747
queryItems.append(URLQueryItem(name: "tag", value: tag.description))
4848
}
49-
let response = try await client.request(path: path, httpMethod: .get, queryItems: queryItems)
49+
let response = try await client.request(path: path, method: .get, queryItems: queryItems)
5050
return try Util.shared.decode(response.data)
5151
}
5252

@@ -110,15 +110,15 @@ public struct FavoriteService {
110110
let requestData = try Util.shared.encode(
111111
RequestToAddFavorite(type: type, favoriteId: favoriteId, tags: [tag])
112112
)
113-
let response = try await client.request(path: path, httpMethod: .post, httpBody: requestData)
113+
let response = try await client.request(path: path, method: .post, body: requestData)
114114
return try Util.shared.decode(response.data)
115115
}
116116

117117
public static func removeFavorite(
118118
_ client: APIClient,
119119
favoriteId: String
120120
) async throws -> SuccessResponse {
121-
let response = try await client.request(path: path, httpMethod: .delete)
121+
let response = try await client.request(path: path, method: .delete)
122122
return try Util.shared.decode(response.data)
123123
}
124124
}

Sources/VRCKit/APIServices/FriendService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public struct FriendService {
2828
URLQueryItem(name: "n", value: n.description),
2929
URLQueryItem(name: "offline", value: offline.description)
3030
]
31-
let response = try await client.request(path: path, httpMethod: .get)
31+
let response = try await client.request(path: path, method: .get)
3232
return try Util.shared.decode(response.data)
3333
}
3434

@@ -75,7 +75,7 @@ public struct FriendService {
7575
}
7676

7777
public static func unfriend(_ client: APIClient, id: String) async throws {
78-
try await client.request(path: "\(path)/\(id)", httpMethod: .delete)
78+
try await client.request(path: "\(path)/\(id)", method: .delete)
7979
}
8080

8181
public static func friendsGroupedByLocation(_ friends: [Friend]) -> [FriendsLocation] {

Sources/VRCKit/APIServices/InstanceService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public struct InstanceService {
2323
) async throws -> Instance {
2424
let response = try await client.request(
2525
path: "\(path)/\(worldId):\(instanceId)",
26-
httpMethod: .get
26+
method: .get
2727
)
2828
return try Util.shared.decode(response.data)
2929
}
@@ -32,7 +32,7 @@ public struct InstanceService {
3232
_ client: APIClient,
3333
location: String
3434
) async throws -> Instance {
35-
let response = try await client.request(path: "\(path)/\(location)", httpMethod: .get)
35+
let response = try await client.request(path: "\(path)/\(location)", method: .get)
3636
return try Util.shared.decode(response.data)
3737
}
3838
}

Sources/VRCKit/APIServices/UserNoteService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public struct UserNoteService {
2020
) async throws -> UserNoteResponse {
2121
let userNoteRequest = UserNoteRequest(targetUserId: targetUserId, note: note)
2222
let requestData = try Util.shared.encode(userNoteRequest)
23-
let response = try await client.request(path: path, httpMethod: .post, httpBody: requestData)
23+
let response = try await client.request(path: path, method: .post, body: requestData)
2424
return try Util.shared.decode(response.data)
2525
}
2626
}

Sources/VRCKit/APIServices/UserService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public struct UserService {
2121
_ client: APIClient,
2222
userId: String
2323
) async throws -> UserDetail {
24-
let response = try await client.request(path: "\(path)/\(userId)", httpMethod: .get)
24+
let response = try await client.request(path: "\(path)/\(userId)", method: .get)
2525
return try Util.shared.decode(response.data)
2626
}
2727

@@ -60,7 +60,7 @@ public struct UserService {
6060
_ client: APIClient,
6161
id: String
6262
) async throws -> User {
63-
let response = try await client.request(path: "\(path)/\(id)", httpMethod: .put)
63+
let response = try await client.request(path: "\(path)/\(id)", method: .put)
6464
return try Util.shared.decode(response.data)
6565
}
6666
}

Sources/VRCKit/APIServices/WorldService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public struct WorldService {
1717
static let path = "worlds"
1818

1919
public static func fetchWorld(_ client: APIClient, worldId: String) async throws -> World {
20-
let response = try await client.request(path: "\(path)/\(worldId)", httpMethod: .get)
20+
let response = try await client.request(path: "\(path)/\(worldId)", method: .get)
2121
return try Util.shared.decode(response.data)
2222
}
2323
}

Sources/VRCKit/Client.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class APIClient {
3131
private let domainUrl: String
3232
private let baseUrl: String
3333

34-
enum HttpMethod: String {
34+
enum Method: String {
3535
case get, post, patch, put, delete
3636
}
3737

@@ -80,17 +80,17 @@ public final class APIClient {
8080
/// Sends a request to the API.
8181
/// - Parameters:
8282
/// - path: The path for the request.
83-
/// - httpMethod: The HTTP method to use for the request.
83+
/// - method: The HTTP method to use for the request.
8484
/// - basic: Whether to include basic authorization.
85-
/// - httpBody: The HTTP body to include in the request.
85+
/// - body: The HTTP body to include in the request.
8686
/// - Returns: A tuple containing the data and the HTTP response.
8787
/// - Throws: `VRCKitError` if an error occurs during the request.
8888
func request(
8989
path: String,
90-
httpMethod: HttpMethod,
90+
method: Method,
9191
basic: Bool = false,
9292
queryItems: [URLQueryItem] = [],
93-
httpBody: Data? = nil
93+
body: Data? = nil
9494
) async throws -> HTTPResponse {
9595
guard var urlComponents = URLComponents(string: "\(baseUrl)/\(path)") else {
9696
throw VRCKitError.urlError
@@ -102,7 +102,7 @@ public final class APIClient {
102102
throw VRCKitError.urlError
103103
}
104104
var request = URLRequest(url: url)
105-
request.httpMethod = httpMethod.description
105+
request.httpMethod = method.description
106106

107107
// Add authorization header if required.
108108
if basic, let username = username, let password = password {
@@ -114,9 +114,9 @@ public final class APIClient {
114114
request.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookies)
115115

116116
// Add HTTP body and content type if body is provided.
117-
if let httpBody = httpBody {
117+
if let body = body {
118118
request.addValue(ContentType.json.rawValue, forHTTPHeaderField: "Content-Type")
119-
request.httpBody = httpBody
119+
request.httpBody = body
120120
}
121121

122122
let (data, response) = try await URLSession.shared.data(for: request)
@@ -128,7 +128,7 @@ public final class APIClient {
128128
}
129129

130130
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
131-
extension APIClient.HttpMethod: CustomStringConvertible {
131+
extension APIClient.Method: CustomStringConvertible {
132132
var description: String {
133133
self.rawValue.uppercased()
134134
}

0 commit comments

Comments
 (0)