Add hashtag support
This commit is contained in:
parent
5f8249ec54
commit
77fa966a23
@ -127,7 +127,9 @@ public struct TwitterFeedProvider: FeedProvider {
|
||||
}
|
||||
|
||||
default:
|
||||
if let screenName = deriveScreenName(urlComponents) {
|
||||
if let hashtag = deriveHashtag(urlComponents) {
|
||||
completion(.success("#\(hashtag)"))
|
||||
} else if let screenName = deriveScreenName(urlComponents) {
|
||||
retrieveUser(screenName: screenName) { result in
|
||||
switch result {
|
||||
case .success(let user):
|
||||
@ -170,6 +172,11 @@ public struct TwitterFeedProvider: FeedProvider {
|
||||
}
|
||||
isSearch = true
|
||||
default:
|
||||
if let hashtag = deriveHashtag(urlComponents) {
|
||||
api = "search/tweets.json"
|
||||
parameters["q"] = "#\(hashtag)"
|
||||
isSearch = true
|
||||
} else {
|
||||
api = "statuses/user_timeline.json"
|
||||
parameters["exclude_replies"] = true
|
||||
if let screenName = deriveScreenName(urlComponents) {
|
||||
@ -179,6 +186,7 @@ public struct TwitterFeedProvider: FeedProvider {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retrieveTweets(api: api, parameters: parameters, isSearch: isSearch) { result in
|
||||
switch result {
|
||||
@ -213,6 +221,14 @@ extension TwitterFeedProvider: OAuth1SwiftProvider {
|
||||
|
||||
private extension TwitterFeedProvider {
|
||||
|
||||
func deriveHashtag(_ urlComponents: URLComponents) -> String? {
|
||||
let path = urlComponents.path
|
||||
if path.starts(with: "/hashtag/"), let startIndex = path.index(path.startIndex, offsetBy: 9, limitedBy: path.endIndex), startIndex < path.endIndex {
|
||||
return String(path[startIndex..<path.endIndex])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deriveScreenName(_ urlComponents: URLComponents) -> String? {
|
||||
let path = urlComponents.path
|
||||
guard !Self.reservedPaths.contains(path) else { return nil }
|
||||
|
Loading…
x
Reference in New Issue
Block a user