From 3376d7ffd20d2183d4b6d59142671ca63b69e8da Mon Sep 17 00:00:00 2001 From: Jim Wallace <james.wallace@uwaterloo.ca> Date: Tue, 19 Dec 2023 11:45:36 -0500 Subject: [PATCH] Fixed comment endpoint --- Sources/SwiftNLP/1. Data Collection/Reddit/Listing.swift | 8 ++------ .../SwiftNLP/1. Data Collection/Reddit/RedditClient.swift | 2 +- Tests/SwiftNLPTests/Reddit API/RedditClient.swift | 8 ++++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Sources/SwiftNLP/1. Data Collection/Reddit/Listing.swift b/Sources/SwiftNLP/1. Data Collection/Reddit/Listing.swift index 3c27d92a..0a22dafb 100644 --- a/Sources/SwiftNLP/1. Data Collection/Reddit/Listing.swift +++ b/Sources/SwiftNLP/1. Data Collection/Reddit/Listing.swift @@ -26,17 +26,13 @@ import Foundation struct RedditListing: Decodable { let kind: String let data: RedditListingData - - var after: String? { data.after } - var before: String? { data.before } - var children: [RedditListingDataItem] { data.children } } struct RedditListingData: Decodable { + let after: String? + let dist: Int? let modhash: String? - let dist: Int let before: String? - let after: String? let geo_filter: String? let children: [RedditListingDataItem] } diff --git a/Sources/SwiftNLP/1. Data Collection/Reddit/RedditClient.swift b/Sources/SwiftNLP/1. Data Collection/Reddit/RedditClient.swift index f37f8a7a..09f38b5c 100644 --- a/Sources/SwiftNLP/1. Data Collection/Reddit/RedditClient.swift +++ b/Sources/SwiftNLP/1. Data Collection/Reddit/RedditClient.swift @@ -159,7 +159,7 @@ extension RedditClient { let (data, response) = try await session.data(for: request) - //print(String(data: data, encoding: .utf8)!) + print(String(data: data, encoding: .utf8)!) guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else { throw RedditClientError(message: "Bad server response" + response.description) diff --git a/Tests/SwiftNLPTests/Reddit API/RedditClient.swift b/Tests/SwiftNLPTests/Reddit API/RedditClient.swift index 1a7952a0..c4efb021 100644 --- a/Tests/SwiftNLPTests/Reddit API/RedditClient.swift +++ b/Tests/SwiftNLPTests/Reddit API/RedditClient.swift @@ -114,6 +114,7 @@ final class RedditClientTest: XCTestCase { // https://www.reddit.com/r/uwaterloo/comments/18lbokl/conestoga_college_finally_being_called_out_by_the/ let submission = RedditSubmission(id: "18lbokl", subreddit: "uwaterloo") + // This should return an array of listings, one with original submisison and one with responses. let result = try await client.searchComment(submission: submission) @@ -136,13 +137,13 @@ final class RedditClientTest: XCTestCase { } let overviewResult = try await client.searchUserOverview(userName: "jimntonik") - XCTAssert(overviewResult.children.count > 0) + XCTAssert(overviewResult.data.children.count > 0) let submittedResult = try await client.searchUserSubmitted(userName: "jimntonik") - XCTAssert(submittedResult.children.count > 0) + XCTAssert(submittedResult.data.children.count > 0) let commentResult = try await client.searchUserComments(userName: "jimntonik") - XCTAssert(commentResult.children.count > 0) + XCTAssert(commentResult.data.children.count > 0) //let upvotedResult = try await client.searchUserUpvoted(userName: "jimntonik") // TODO: 403 - Forbidden - requires login? //XCTAssert(upvotedResult.children.count > 0) @@ -159,5 +160,4 @@ final class RedditClientTest: XCTestCase { //let gildedResult = try await client.searchUserGilded(userName: "jimntonik") // TODO: 403 - Forbidden //XCTAssert(gildedResult.children.count > 0) } - } -- GitLab