This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
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 #124 from mironal/add-reverse_chronological-timeline
Add reverse chronological timeline (Home Timeline)
- Loading branch information
Showing
6 changed files
with
173 additions
and
12 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...witterAPIKit/APIv2/Timeline/Requests/GetUsersTimelinesReverseChronologicalRequestV2.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,78 @@ | ||
import Foundation | ||
|
||
/// https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-reverse-chronological | ||
open class GetUsersTimelinesReverseChronologicalRequestV2: TwitterAPIRequest { | ||
|
||
public let id: String | ||
public let endTime: Date? | ||
public let exclude: Set<TwitterTimelineExcludeV2>? | ||
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 sinceID: String? | ||
public let startTime: Date? | ||
public let tweetFields: Set<TwitterTweetFieldsV2>? | ||
public let untilID: String? | ||
public let userFields: Set<TwitterUserFieldsV2>? | ||
|
||
public var method: HTTPMethod { | ||
return .get | ||
} | ||
|
||
public var path: String { | ||
return "/2/users/\(id)/timelines/reverse_chronological" | ||
} | ||
|
||
open var parameters: [String: Any] { | ||
var p = [String: Any]() | ||
endTime?.bind(param: &p, for: "end_time") | ||
exclude?.bind(param: &p) | ||
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) | ||
sinceID.map { p["since_id"] = $0 } | ||
startTime?.bind(param: &p, for: "start_time") | ||
tweetFields?.bind(param: &p) | ||
untilID.map { p["until_id"] = $0 } | ||
userFields?.bind(param: &p) | ||
return p | ||
} | ||
|
||
public init( | ||
id: String, | ||
endTime: Date? = .none, | ||
exclude: Set<TwitterTimelineExcludeV2>? = .none, | ||
expansions: Set<TwitterTweetExpansionsV2>? = .none, | ||
maxResults: Int? = .none, | ||
mediaFields: Set<TwitterMediaFieldsV2>? = .none, | ||
paginationToken: String? = .none, | ||
placeFields: Set<TwitterPlaceFieldsV2>? = .none, | ||
pollFields: Set<TwitterPollFieldsV2>? = .none, | ||
sinceID: String? = .none, | ||
startTime: Date? = .none, | ||
tweetFields: Set<TwitterTweetFieldsV2>? = .none, | ||
untilID: String? = .none, | ||
userFields: Set<TwitterUserFieldsV2>? = .none | ||
) { | ||
self.id = id | ||
self.endTime = endTime | ||
self.exclude = exclude | ||
self.expansions = expansions | ||
self.maxResults = maxResults | ||
self.mediaFields = mediaFields | ||
self.paginationToken = paginationToken | ||
self.placeFields = placeFields | ||
self.pollFields = pollFields | ||
self.sinceID = sinceID | ||
self.startTime = startTime | ||
self.tweetFields = tweetFields | ||
self.untilID = untilID | ||
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
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
16 changes: 16 additions & 0 deletions
16
Sources/TwitterAPIKit/APIv2/Timeline/TwitterTimelineExcludeV2.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,16 @@ | ||
import Foundation | ||
|
||
public enum TwitterTimelineExcludeV2: String, TwitterAPIv2RequestParameter { | ||
case retweets | ||
case replies | ||
|
||
public var stringValue: String { | ||
return rawValue | ||
} | ||
} | ||
|
||
extension Set where Element == TwitterTimelineExcludeV2 { | ||
func bind(param: inout [String: Any]) { | ||
param["exclude"] = commaSeparatedString | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...itterAPIKitTests/APIv2/Timeline/GetUsersTimelinesReverseChronologicalRequestV2Tests.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,63 @@ | ||
import TwitterAPIKit | ||
import XCTest | ||
|
||
class GetUsersTimelinesReverseChronologicalRequestV2Tests: XCTestCase { | ||
override func setUpWithError() throws { | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
} | ||
|
||
func test() throws { | ||
let req = GetUsersTimelinesReverseChronologicalRequestV2( | ||
id: "_i_", | ||
endTime: Date(timeIntervalSince1970: 50), | ||
exclude: [.retweets], | ||
expansions: [.authorID], | ||
maxResults: 10, | ||
mediaFields: [.altText], | ||
paginationToken: "_p_", | ||
placeFields: [.country], | ||
pollFields: [.options], | ||
sinceID: "_s_", | ||
startTime: Date(timeIntervalSince1970: 10), | ||
tweetFields: [.geo], | ||
untilID: "_u_", | ||
userFields: [.location] | ||
) | ||
|
||
XCTAssertEqual(req.method, .get) | ||
XCTAssertEqual(req.baseURLType, .api) | ||
XCTAssertEqual(req.path, "/2/users/_i_/timelines/reverse_chronological") | ||
XCTAssertEqual(req.bodyContentType, .wwwFormUrlEncoded) | ||
AssertEqualAnyDict( | ||
req.parameters, | ||
[ | ||
"end_time": "1970-01-01T00:00:50Z", | ||
"exclude": "retweets", | ||
"expansions": "author_id", | ||
"max_results": 10, | ||
"media.fields": "alt_text", | ||
"pagination_token": "_p_", | ||
"place.fields": "country", | ||
"poll.fields": "options", | ||
"since_id": "_s_", | ||
"start_time": "1970-01-01T00:00:10Z", | ||
"tweet.fields": "geo", | ||
"until_id": "_u_", | ||
"user.fields": "location", | ||
] | ||
) | ||
} | ||
|
||
func testDefaultArg() throws { | ||
let req = GetUsersTimelinesReverseChronologicalRequestV2( | ||
id: "_i_" | ||
) | ||
|
||
AssertEqualAnyDict( | ||
req.parameters, | ||
[:] | ||
) | ||
} | ||
} |
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