Skip to content

Commit 44617d9

Browse files
committed
Remove expectedReturnType parameter from call
T can be inferred from the return type of the calling function by the compiler
1 parent de93f15 commit 44617d9

13 files changed

+62
-122
lines changed

Sources/Twift+API.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ extension Twift {
99
internal func call<T: Codable>(route: APIRoute,
1010
method: HTTPMethod = .GET,
1111
queryItems: [URLQueryItem] = [],
12-
body: Data? = nil,
13-
expectedReturnType: T.Type
12+
body: Data? = nil
1413
) async throws -> T {
1514
if case AuthenticationType.oauth2UserAuth(_, _) = self.authenticationType {
1615
try await self.refreshOAuth2AccessToken()

Sources/Twift+Blocks.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ extension Twift {
2828
queryItems += fieldsAndExpansions(for: User.self, fields: fields, expansions: expansions)
2929

3030
return try await call(route: .blocking(userId),
31-
queryItems: queryItems,
32-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
31+
queryItems: queryItems)
3332
}
3433

3534
/// Causes the source user to block the target user. The source user ID must match the currently authenticated user ID.
@@ -44,8 +43,7 @@ extension Twift {
4443
let serializedBody = try JSONSerialization.data(withJSONObject: body)
4544
return try await call(route: .blocking(sourceUserId),
4645
method: .POST,
47-
body: serializedBody,
48-
expectedReturnType: TwitterAPIData.self)
46+
body: serializedBody)
4947
}
5048

5149
/// Causes the source user to block the target user. The source user ID must match the currently authenticated user ID.
@@ -57,8 +55,7 @@ extension Twift {
5755
/// - Returns: A ``BlockResponse`` indicating the blocked status.
5856
public func unblockUser(sourceUserId: User.ID, targetUserId: User.ID) async throws -> TwitterAPIData<BlockResponse> {
5957
return try await call(route: .deleteBlock(sourceUserId: sourceUserId, targetUserId: targetUserId),
60-
method: .DELETE,
61-
expectedReturnType: TwitterAPIData.self)
58+
method: .DELETE)
6259
}
6360
}
6461

Sources/Twift+Bookmarks.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ extension Twift {
3030
let fieldsAndExpansions = fieldsAndExpansions(for: Tweet.self, fields: fields, expansions: expansions)
3131

3232
return try await call(route: .bookmarks(userId),
33-
queryItems: queryItems + fieldsAndExpansions,
34-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
33+
queryItems: queryItems + fieldsAndExpansions)
3534
}
3635

3736
/// Causes the user ID of an authenticated user identified in the path parameter to Bookmark the target Tweet
@@ -47,8 +46,7 @@ extension Twift {
4746

4847
return try await call(route: .bookmarks(userId),
4948
method: .POST,
50-
body: encodedBody,
51-
expectedReturnType: TwitterAPIData.self)
49+
body: encodedBody)
5250
}
5351

5452
/// Allows a user or authenticated user ID to remove a Bookmark of a Tweet.
@@ -60,8 +58,7 @@ extension Twift {
6058
/// - Returns: A response object containing a ``BookmarkResponse``
6159
public func deleteBookmark(_ tweetId: Tweet.ID, userId: User.ID) async throws -> TwitterAPIData<BookmarkResponse> {
6260
return try await call(route: .deleteBookmark(userId: userId, tweetId: tweetId),
63-
method: .DELETE,
64-
expectedReturnType: TwitterAPIData.self)
61+
method: .DELETE)
6562
}
6663
}
6764

Sources/Twift+Follows.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ extension Twift {
3535
queryItems += fieldsAndExpansions(for: User.self, fields: fields, expansions: expansions)
3636

3737
return try await call(route: .following(userId),
38-
queryItems: queryItems,
39-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
38+
queryItems: queryItems)
4039
}
4140

4241
/// Returns a list of users who are followers of the specified user ID.
@@ -64,8 +63,7 @@ extension Twift {
6463
queryItems += fieldsAndExpansions(for: User.self, fields: fields, expansions: expansions)
6564

6665
return try await call(route: .followers(userId),
67-
queryItems: queryItems,
68-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
66+
queryItems: queryItems)
6967
}
7068

7169
/// Allows a user ID to follow another user.
@@ -87,8 +85,7 @@ extension Twift {
8785
let serializedBody = try JSONSerialization.data(withJSONObject: body)
8886
return try await call(route: .following(sourceUserId),
8987
method: .POST,
90-
body: serializedBody,
91-
expectedReturnType: TwitterAPIData.self)
88+
body: serializedBody)
9289
}
9390

9491
/// Allows a user ID to unfollow another user.
@@ -104,8 +101,7 @@ extension Twift {
104101
targetUserId: User.ID
105102
) async throws -> TwitterAPIData<FollowResponse> {
106103
return try await call(route: .deleteFollow(sourceUserId: sourceUserId, targetUserId: targetUserId),
107-
method: .DELETE,
108-
expectedReturnType: TwitterAPIData.self)
104+
method: .DELETE)
109105
}
110106
}
111107

Sources/Twift+Likes.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ extension Twift {
1414

1515
return try await call(route: .userLikes(userId),
1616
method: .POST,
17-
body: encodedBody,
18-
expectedReturnType: TwitterAPIData.self)
17+
body: encodedBody)
1918
}
2019

2120
/// Causes the user ID to unlike the target Tweet.
@@ -27,8 +26,7 @@ extension Twift {
2726
/// - Returns: A response object containing a ``LikeResponse``
2827
public func unlikeTweet(_ tweetId: Tweet.ID, userId: User.ID) async throws -> TwitterAPIData<LikeResponse> {
2928
return try await call(route: .deleteUserLikes(userId, tweetId: tweetId),
30-
method: .DELETE,
31-
expectedReturnType: TwitterAPIData.self)
29+
method: .DELETE)
3230
}
3331

3432
/// Allows you to get information about a Tweet’s liking users.
@@ -54,8 +52,7 @@ extension Twift {
5452

5553
return try await call(route: .likingUsers(tweetId),
5654
method: .GET,
57-
queryItems: queryItems,
58-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
55+
queryItems: queryItems)
5956
}
6057

6158
/// Allows you to get information about a user’s liked Tweets.
@@ -81,8 +78,7 @@ extension Twift {
8178

8279
return try await call(route: .likedTweets(userId),
8380
method: .GET,
84-
queryItems: queryItems,
85-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
81+
queryItems: queryItems)
8682
}
8783
}
8884

Sources/Twift+Lists.swift

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ extension Twift {
2828
queryItems += fieldsAndExpansions(for: Tweet.self, fields: fields, expansions: expansions)
2929

3030
return try await call(route: .listTweets(listId),
31-
queryItems: queryItems,
32-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
31+
queryItems: queryItems)
3332
}
3433

3534
// MARK: List Lookup
@@ -48,8 +47,7 @@ extension Twift {
4847
) async throws -> TwitterAPIDataAndIncludes<List, List.Includes> {
4948
return try await call(route: .list(listId),
5049
method: .GET,
51-
queryItems: fieldsAndExpansions(for: List.self, fields: fields, expansions: expansions),
52-
expectedReturnType: TwitterAPIDataAndIncludes.self)
50+
queryItems: fieldsAndExpansions(for: List.self, fields: fields, expansions: expansions))
5351
}
5452

5553
/// Returns all Lists owned by the specified user.
@@ -77,8 +75,7 @@ extension Twift {
7775
queryItems += fieldsAndExpansions(for: List.self, fields: fields, expansions: expansions)
7876

7977
return try await call(route: .userOwnedLists(userId),
80-
queryItems: queryItems,
81-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
78+
queryItems: queryItems)
8279
}
8380

8481
// MARK: Manage Lists
@@ -87,7 +84,7 @@ extension Twift {
8784
/// - Parameter listId: The ID of the List to be deleted.
8885
/// - Returns: A response object containing the result of the delete request
8986
public func deleteList(_ listId: List.ID) async throws -> TwitterAPIData<DeleteResponse> {
90-
return try await call(route: .list(listId), method: .DELETE, expectedReturnType: TwitterAPIData.self)
87+
return try await call(route: .list(listId), method: .DELETE)
9188
}
9289

9390
/// Enables the authenticated user to create a new List.
@@ -111,8 +108,7 @@ extension Twift {
111108
let serializedBody = try JSONSerialization.data(withJSONObject: body)
112109
return try await call(route: .createList,
113110
method: .POST,
114-
body: serializedBody,
115-
expectedReturnType: TwitterAPIData.self)
111+
body: serializedBody)
116112
}
117113

118114
/// Enables the authenticated user to create a new List.
@@ -134,8 +130,7 @@ extension Twift {
134130
let serializedBody = try JSONSerialization.data(withJSONObject: body)
135131
return try await call(route: .list(id),
136132
method: .PUT,
137-
body: serializedBody,
138-
expectedReturnType: TwitterAPIData.self)
133+
body: serializedBody)
139134
}
140135

141136
}
@@ -168,8 +163,7 @@ extension Twift {
168163
queryItems += fieldsAndExpansions(for: List.self, fields: fields, expansions: expansions)
169164

170165
return try await call(route: .userListMemberships(userId),
171-
queryItems: queryItems,
172-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
166+
queryItems: queryItems)
173167
}
174168

175169
/// Returns a list of users who are members of the specified List.
@@ -197,8 +191,7 @@ extension Twift {
197191
queryItems += fieldsAndExpansions(for: User.self, fields: fields, expansions: expansions)
198192

199193
return try await call(route: .listMembers(listId),
200-
queryItems: queryItems,
201-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
194+
queryItems: queryItems)
202195
}
203196

204197
/// Enables the authenticated user to remove a member from a List they own.
@@ -208,8 +201,7 @@ extension Twift {
208201
/// - Returns: A response object containing the result of this delete request
209202
public func deleteListMember(_ userId: User.ID, from listId: List.ID) async throws -> TwitterAPIData<ListMembershipResponse> {
210203
return try await call(route: .removeListMember(listId, userId: userId),
211-
method: .DELETE,
212-
expectedReturnType: TwitterAPIData.self)
204+
method: .DELETE)
213205
}
214206

215207
/// Enables the authenticated user to add a member to a List they own.
@@ -222,8 +214,7 @@ extension Twift {
222214
let serializedBody = try JSONSerialization.data(withJSONObject: body)
223215
return try await call(route: .listMembers(listId),
224216
method: .POST,
225-
body: serializedBody,
226-
expectedReturnType: TwitterAPIData.self)
217+
body: serializedBody)
227218
}
228219
}
229220

@@ -243,8 +234,7 @@ extension Twift {
243234
/// - Returns: A response object containing the result of the unfollow request
244235
public func unfollowList(_ listId: List.ID, userId: User.ID) async throws -> TwitterAPIData<FollowResponse> {
245236
return try await call(route: .userFollowingLists(userId, listId: listId),
246-
method: .DELETE,
247-
expectedReturnType: TwitterAPIData.self)
237+
method: .DELETE)
248238
}
249239

250240
/// Enables the authenticated user to follow a List.
@@ -258,8 +248,7 @@ extension Twift {
258248

259249
return try await call(route: .userFollowingLists(userId),
260250
method: .POST,
261-
body: serializedBody,
262-
expectedReturnType: TwitterAPIData.self)
251+
body: serializedBody)
263252
}
264253

265254
/// Returns a list of users who are followers of the specified List.
@@ -286,8 +275,7 @@ extension Twift {
286275

287276
return try await call(route: .listFollowers(listId),
288277
method: .GET,
289-
queryItems: queryItems,
290-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
278+
queryItems: queryItems)
291279
}
292280

293281
/// Returns all Lists a specified user follows.
@@ -315,8 +303,7 @@ extension Twift {
315303

316304
return try await call(route: .userFollowingLists(userId),
317305
method: .GET,
318-
queryItems: queryItems,
319-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
306+
queryItems: queryItems)
320307
}
321308
}
322309

@@ -333,8 +320,7 @@ extension Twift {
333320
let serializedBody = try JSONSerialization.data(withJSONObject: body)
334321
return try await call(route: .userPinnedLists(userId),
335322
method: .POST,
336-
body: serializedBody,
337-
expectedReturnType: TwitterAPIData.self)
323+
body: serializedBody)
338324
}
339325

340326
/// Enables the authenticated user to unpin a List.
@@ -346,8 +332,7 @@ extension Twift {
346332
/// - Returns: A response object containing the result of this unpin list request
347333
public func unpinList(_ listId: List.ID, userId: User.ID) async throws -> TwitterAPIData<PinnedResponse> {
348334
return try await call(route: .userPinnedLists(userId, listId: listId),
349-
method: .DELETE,
350-
expectedReturnType: TwitterAPIData.self)
335+
method: .DELETE)
351336
}
352337

353338
/// Returns all Lists a specified user has pinned.
@@ -362,8 +347,7 @@ extension Twift {
362347
) async throws -> TwitterAPIDataAndIncludes<[List], List.Includes> {
363348
return try await call(route: .userPinnedLists(userId),
364349
method: .GET,
365-
queryItems: fieldsAndExpansions(for: List.self, fields: fields, expansions: expansions),
366-
expectedReturnType: TwitterAPIDataAndIncludes.self)
350+
queryItems: fieldsAndExpansions(for: List.self, fields: fields, expansions: expansions))
367351
}
368352
}
369353

Sources/Twift+Mutes.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ extension Twift {
2828
let fieldsAndExpansions = fieldsAndExpansions(for: User.self, fields: fields, expansions: expansions)
2929

3030
return try await call(route: .muting(userId),
31-
queryItems: queryItems + fieldsAndExpansions,
32-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
31+
queryItems: queryItems + fieldsAndExpansions)
3332
}
3433

3534
/// Causes the source user to mute the target user. The source user ID must match the currently authenticated user ID.
@@ -44,8 +43,7 @@ extension Twift {
4443
let serializedBody = try JSONSerialization.data(withJSONObject: body)
4544
return try await call(route: .muting(sourceUserId),
4645
method: .POST,
47-
body: serializedBody,
48-
expectedReturnType: TwitterAPIData.self)
46+
body: serializedBody)
4947
}
5048

5149
/// Causes the source user to mute the target user. The source user ID must match the currently authenticated user ID.
@@ -57,8 +55,7 @@ extension Twift {
5755
/// - Returns: A ``MuteResponse`` indicating the muted status.
5856
public func unmuteUser(sourceUserId: User.ID, targetUserId: User.ID) async throws -> TwitterAPIData<MuteResponse> {
5957
return try await call(route: .deleteMute(sourceUserId: sourceUserId, targetUserId: targetUserId),
60-
method: .DELETE,
61-
expectedReturnType: TwitterAPIData.self)
58+
method: .DELETE)
6259
}
6360
}
6461

Sources/Twift+Retweets.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ extension Twift {
1414

1515
return try await call(route: .retweets(userId),
1616
method: .POST,
17-
body: encodedBody,
18-
expectedReturnType: TwitterAPIData.self)
17+
body: encodedBody)
1918
}
2019

2120
/// Causes the user ID to remove the Retweet of a Tweet
@@ -27,8 +26,7 @@ extension Twift {
2726
/// - Returns: A response object containing the result of the request
2827
public func unretweet(_ tweetId: Tweet.ID, userId: User.ID) async throws -> TwitterAPIData<RetweetResponse> {
2928
return try await call(route: .retweets(userId, tweetId: tweetId),
30-
method: .DELETE,
31-
expectedReturnType: TwitterAPIData.self)
29+
method: .DELETE)
3230
}
3331

3432
/// Allows you to get information about who has Retweeted a Tweet.
@@ -52,8 +50,7 @@ extension Twift {
5250

5351
return try await call(route: .retweetedBy(tweetId),
5452
method: .GET,
55-
queryItems: queryItems,
56-
expectedReturnType: TwitterAPIDataAndIncludes.self)
53+
queryItems: queryItems)
5754
}
5855

5956
/// Returns Quote Tweets for a Tweet specified by the requested Tweet ID.
@@ -81,8 +78,7 @@ extension Twift {
8178
let fieldsAndExpansions = fieldsAndExpansions(for: Tweet.self, fields: fields, expansions: expansions)
8279

8380
return try await call(route: .quoteTweets(tweetId),
84-
queryItems: queryItems + fieldsAndExpansions,
85-
expectedReturnType: TwitterAPIDataIncludesAndMeta.self)
81+
queryItems: queryItems + fieldsAndExpansions)
8682
}
8783
}
8884

0 commit comments

Comments
 (0)