This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from mironal/add-get-tweets-id-quote_tweets
Add get tweets id quote tweets
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
Sources/TwitterAPIKit/APIv2/Tweet/Requests/GetTweetsQuoteTweetsRequestV2.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Foundation | ||
|
||
/// https://developer.twitter.com/en/docs/twitter-api/tweets/quote-tweets/api-reference/get-tweets-id-quote_tweets | ||
open class GetTweetsQuoteTweetsRequestV2: TwitterAPIRequest { | ||
|
||
public let id: String | ||
public let expansions: Set<TwitterTweetExpansionsV2>? | ||
public let maxResults: Int? | ||
public let mediaFields: Set<TwitterMediaFieldsV2>? | ||
public let paginationToken: String? | ||
public let placeFields: Set<TwitterPlaceFieldsV2>? | ||
public let pollFields: Set<TwitterPollFieldsV2>? | ||
public let tweetFields: Set<TwitterTweetFieldsV2>? | ||
public let userFields: Set<TwitterUserFieldsV2>? | ||
|
||
public var method: HTTPMethod { | ||
return .get | ||
} | ||
|
||
public var path: String { | ||
return "/2/tweets/\(id)/quote_tweets" | ||
} | ||
|
||
open var parameters: [String: Any] { | ||
var p = [String: Any]() | ||
expansions?.bind(param: &p) | ||
maxResults.map { p["max_results"] = $0 } | ||
mediaFields?.bind(param: &p) | ||
paginationToken.map { p["pagination_token"] = $0 } | ||
placeFields?.bind(param: &p) | ||
pollFields?.bind(param: &p) | ||
tweetFields?.bind(param: &p) | ||
userFields?.bind(param: &p) | ||
return p | ||
} | ||
|
||
public init( | ||
id: String, | ||
expansions: Set<TwitterTweetExpansionsV2>? = .none, | ||
maxResults: Int? = .none, | ||
mediaFields: Set<TwitterMediaFieldsV2>? = .none, | ||
paginationToken: String? = .none, | ||
placeFields: Set<TwitterPlaceFieldsV2>? = .none, | ||
pollFields: Set<TwitterPollFieldsV2>? = .none, | ||
tweetFields: Set<TwitterTweetFieldsV2>? = .none, | ||
userFields: Set<TwitterUserFieldsV2>? = .none | ||
) { | ||
self.id = id | ||
self.expansions = expansions | ||
self.maxResults = maxResults | ||
self.mediaFields = mediaFields | ||
self.paginationToken = paginationToken | ||
self.placeFields = placeFields | ||
self.pollFields = pollFields | ||
self.tweetFields = tweetFields | ||
self.userFields = userFields | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Tests/TwitterAPIKitTests/APIv2/Tweet/GetTweetsQuoteTweetsRequestV2Tests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import TwitterAPIKit | ||
import XCTest | ||
|
||
class GetTweetsQuoteTweetsRequestV2Tests: XCTestCase { | ||
override func setUpWithError() throws { | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
} | ||
|
||
func test() throws { | ||
let req = GetTweetsQuoteTweetsRequestV2( | ||
id: "_i_", | ||
expansions: [.attachmentsMediaKeys], | ||
maxResults: 10, | ||
mediaFields: [.height], | ||
paginationToken: "_p_", | ||
placeFields: [.country], | ||
pollFields: [.options], | ||
tweetFields: [.authorID], | ||
userFields: [.entities] | ||
) | ||
|
||
XCTAssertEqual(req.method, .get) | ||
XCTAssertEqual(req.baseURLType, .api) | ||
XCTAssertEqual(req.path, "/2/tweets/_i_/quote_tweets") | ||
XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) | ||
AssertEqualAnyDict( | ||
req.parameters, | ||
[ | ||
"expansions": "attachments.media_keys", | ||
"max_results": 10, | ||
"media.fields": "height", | ||
"pagination_token": "_p_", | ||
"place.fields": "country", | ||
"poll.fields": "options", | ||
"tweet.fields": "author_id", | ||
"user.fields": "entities", | ||
] | ||
) | ||
} | ||
|
||
func testDefaultArg() throws { | ||
let req = GetTweetsQuoteTweetsRequestV2( | ||
id: "i" | ||
) | ||
|
||
XCTAssertEqual(req.path, "/2/tweets/i/quote_tweets") | ||
AssertEqualAnyDict( | ||
req.parameters, | ||
[:] | ||
) | ||
} | ||
} |