Skip to content

Commit 9844637

Browse files
committed
fix v2 post tweet request
1 parent 41c470d commit 9844637

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

Sources/TwitterAPIKit/APIv2/Tweet/Requests/PostTweetsRequestV2.swift

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ open class PostTweetsRequestV2: TwitterAPIRequest {
66
public struct Geo {
77
public let placeID: String
88

9+
public init(placeID: String) {
10+
self.placeID = placeID
11+
}
12+
913
func bind(param: inout [String: Any]) {
1014
var p = [String: Any]()
1115

@@ -19,11 +23,19 @@ open class PostTweetsRequestV2: TwitterAPIRequest {
1923
public let mediaIDs: [String]
2024
public let taggedUserIDs: [String]?
2125

26+
public init(
27+
mediaIDs: [String],
28+
taggedUserIDs: [String]? = .none
29+
) {
30+
self.mediaIDs = mediaIDs
31+
self.taggedUserIDs = taggedUserIDs
32+
}
33+
2234
func bind(param: inout [String: Any]) {
2335
var p = [String: Any]()
2436

25-
p["media_ids"] = mediaIDs.joined(separator: ",")
26-
taggedUserIDs.map { $0.joined(separator: ",") }.map { p["tagged_user_ids"] = $0 }
37+
p["media_ids"] = mediaIDs
38+
taggedUserIDs.map { p["tagged_user_ids"] = $0 }
2739

2840
param["media"] = p
2941
}
@@ -33,11 +45,19 @@ open class PostTweetsRequestV2: TwitterAPIRequest {
3345
public let durationMinutes: Int
3446
public let options: [String]
3547

48+
public init(
49+
durationMinutes: Int,
50+
options: [String]
51+
) {
52+
self.durationMinutes = durationMinutes
53+
self.options = options
54+
}
55+
3656
func bind(param: inout [String: Any]) {
3757
var p = [String: Any]()
3858

3959
p["duration_minutes"] = durationMinutes
40-
p["options"] = options.joined(separator: ",")
60+
p["options"] = options
4161

4262
param["poll"] = p
4363
}
@@ -47,10 +67,18 @@ open class PostTweetsRequestV2: TwitterAPIRequest {
4767
public let excludeReplyUserIDs: [String]?
4868
public let inReplyToTweetID: String
4969

70+
public init(
71+
excludeReplyUserIDs: [String]? = .none,
72+
inReplyToTweetID: String
73+
) {
74+
self.excludeReplyUserIDs = excludeReplyUserIDs
75+
self.inReplyToTweetID = inReplyToTweetID
76+
}
77+
5078
func bind(param: inout [String: Any]) {
5179
var p = [String: Any]()
5280

53-
excludeReplyUserIDs.map { $0.joined(separator: ",") }.map { p["exclude_reply_user_ids"] = $0 }
81+
excludeReplyUserIDs.map { p["exclude_reply_user_ids"] = $0 }
5482
p["in_reply_to_tweet_id"] = inReplyToTweetID
5583

5684
param["reply"] = p

0 commit comments

Comments
 (0)