Skip to content
Snippets Groups Projects
Commit 3547ef46 authored by Jim Wallace's avatar Jim Wallace
Browse files

Sketch for Reddit Comment search

parent 03b2443d
No related branches found
No related tags found
No related merge requests found
Pipeline #108190 passed
......@@ -11,15 +11,22 @@ enum RedditContentType: String, CustomStringConvertible {
enum ListingSortOrder: String, CustomStringConvertible {
case relevance = "relevance"
case hot = "hot"
case top = "top"
case new = "new"
case comments = "comments"
case relevance = "relevance"
case hot = "hot"
case top = "top"
case new = "new"
case old = "old"
case random = "random"
case qa = "qa"
case live = "live"
case comments = "comments"
case confidence = "confidence"
case controversial = "controversial"
var description: String { rawValue }
}
enum ListingTime: String, CustomStringConvertible {
case hour = "hour"
case day = "day"
......
import Foundation
extension RedditClient {
func searchComment(
article: RedditSubmission
) async throws -> [RedditComment] {
guard let subreddit = article.subreddit, let articleID = article.id
else {
throw RedditClientError(message: "Submission must include article data.")
}
let (data, response) = try await _GET(
endpoint: "r/\(subreddit)/search/comment/\(articleID)",
parameters: parameters
)
print(response)
print(data)
do {
let redditListing = try JSONDecoder().decode([RedditComment].self, from: data)
return redditListing
} catch {
throw RedditClientError(message: "Unable to decode server response.")
}
}
}
public protocol RedditDataItem: Encodable, Decodable, Equatable {
public protocol RedditDataItem: Codable, Equatable {
var created_utc: Int32? { get }
var id: String? { get }
}
......@@ -91,4 +91,25 @@ final class RedditClientTest: XCTestCase {
XCTAssert(result.data.children.count > 0)
}
// func testCommentSearch() async throws {
//
// let id = ProcessInfo.processInfo.environment["REDDIT_CLIENT_ID"] ?? nil
// let secret = ProcessInfo.processInfo.environment["REDDIT_CLIENT_SECRET"] ?? nil
//
// guard let id = id, let secret = secret else {
// fatalError("Unable to fetch REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET from ProcessInfo.")
// }
//
// let client = RedditClient(id: id, secret: secret)
// guard let _ = try? await client.authenticate() else {
// throw RedditClientError(message: "Error authenticating client.")
// }
//
// let submission = RedditSubmission()
//
// let result = try await client.searchComment(article: nil)
//
// XCTAssert(result.data.children.count > 0)
// }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment