From 155b0e6153005fcda2616102fe63a84484a37263 Mon Sep 17 00:00:00 2001 From: dcamenisch Date: Tue, 21 Nov 2023 22:09:59 +0100 Subject: [PATCH 1/3] FIX: TV Episode images missing language code --- Sources/TMDb/Extensions/URL+QueryItem.swift | 2 +- .../Endpoints/TVEpisodesEndpoint.swift | 10 ++++++---- .../TVEpisodeService.swift | 15 +++++++++++---- .../ENdpoints/TVEpisodesEndpointTests.swift | 14 ++++++++++---- .../TVEpisodes/TVEpisodeServiceTests.swift | 11 ++++++++--- 5 files changed, 36 insertions(+), 16 deletions(-) rename Sources/TMDb/{TVEpisodes => TVEpisodes 2}/Endpoints/TVEpisodesEndpoint.swift (85%) rename Sources/TMDb/{TVEpisodes => TVEpisodes 2}/TVEpisodeService.swift (86%) diff --git a/Sources/TMDb/Extensions/URL+QueryItem.swift b/Sources/TMDb/Extensions/URL+QueryItem.swift index 8e118a86..977233ad 100644 --- a/Sources/TMDb/Extensions/URL+QueryItem.swift +++ b/Sources/TMDb/Extensions/URL+QueryItem.swift @@ -37,7 +37,7 @@ extension URL { guard let languageCode else { return self } - + return appendingQueryItem(name: QueryItemName.language, value: languageCode) } diff --git a/Sources/TMDb/TVEpisodes/Endpoints/TVEpisodesEndpoint.swift b/Sources/TMDb/TVEpisodes 2/Endpoints/TVEpisodesEndpoint.swift similarity index 85% rename from Sources/TMDb/TVEpisodes/Endpoints/TVEpisodesEndpoint.swift rename to Sources/TMDb/TVEpisodes 2/Endpoints/TVEpisodesEndpoint.swift index 32eb79ce..c2f0fb8b 100644 --- a/Sources/TMDb/TVEpisodes/Endpoints/TVEpisodesEndpoint.swift +++ b/Sources/TMDb/TVEpisodes 2/Endpoints/TVEpisodesEndpoint.swift @@ -3,8 +3,8 @@ import Foundation enum TVEpisodesEndpoint { case details(tvSeriesID: TVSeries.ID, seasonNumber: Int, episodeNumber: Int) - case images(tvSeriesID: TVSeries.ID, seasonNumber: Int, episodeNumber: Int) - case videos(tvSeriesID: TVSeries.ID, seasonNumber: Int, episodeNumber: Int) + case images(tvSeriesID: TVSeries.ID, seasonNumber: Int, episodeNumber: Int, languageCode: String?) + case videos(tvSeriesID: TVSeries.ID, seasonNumber: Int, episodeNumber: Int, languageCode: String?) } @@ -23,19 +23,21 @@ extension TVEpisodesEndpoint: Endpoint { .appendingPathComponent("episode") .appendingPathComponent(episodeNumber) - case .images(let tvSeriesID, let seasonNumber, let episodeNumber): + case .images(let tvSeriesID, let seasonNumber, let episodeNumber, let languageCode): return Self.basePath(for: tvSeriesID) .appendingPathComponent(seasonNumber) .appendingPathComponent("episode") .appendingPathComponent(episodeNumber) .appendingPathComponent("images") + .appendingImageLanguage(languageCode) - case .videos(let tvSeriesID, let seasonNumber, let episodeNumber): + case .videos(let tvSeriesID, let seasonNumber, let episodeNumber, let languageCode): return Self.basePath(for: tvSeriesID) .appendingPathComponent(seasonNumber) .appendingPathComponent("episode") .appendingPathComponent(episodeNumber) .appendingPathComponent("videos") + .appendingVideoLanguage(languageCode) } } diff --git a/Sources/TMDb/TVEpisodes/TVEpisodeService.swift b/Sources/TMDb/TVEpisodes 2/TVEpisodeService.swift similarity index 86% rename from Sources/TMDb/TVEpisodes/TVEpisodeService.swift rename to Sources/TMDb/TVEpisodes 2/TVEpisodeService.swift index 8b5481b7..d39d28a0 100644 --- a/Sources/TMDb/TVEpisodes/TVEpisodeService.swift +++ b/Sources/TMDb/TVEpisodes 2/TVEpisodeService.swift @@ -7,18 +7,21 @@ import Foundation public final class TVEpisodeService { private let apiClient: APIClient + private let localeProvider: () -> Locale /// /// Creates a TV episode service object. /// public convenience init() { self.init( - apiClient: TMDbFactory.apiClient + apiClient: TMDbFactory.apiClient, + localeProvider: TMDbFactory.localeProvider ) } - init(apiClient: APIClient) { + init(apiClient: APIClient, localeProvider: @escaping () -> Locale) { self.apiClient = apiClient + self.localeProvider = localeProvider } /// @@ -69,13 +72,15 @@ public final class TVEpisodeService { /// public func images(forEpisode episodeNumber: Int, inSeason seasonNumber: Int, inTVSeries tvSeriesID: TVSeries.ID) async throws -> TVEpisodeImageCollection { + let languageCode = localeProvider().languageCode let imageCollection: TVEpisodeImageCollection do { imageCollection = try await apiClient.get( endpoint: TVEpisodesEndpoint.images( tvSeriesID: tvSeriesID, seasonNumber: seasonNumber, - episodeNumber: episodeNumber + episodeNumber: episodeNumber, + languageCode: languageCode ) ) } catch let error { @@ -101,13 +106,15 @@ public final class TVEpisodeService { /// public func videos(forEpisode episodeNumber: Int, inSeason seasonNumber: Int, inTVSeries tvSeriesID: TVSeries.ID) async throws -> VideoCollection { + let languageCode = localeProvider().languageCode let videoCollection: VideoCollection do { videoCollection = try await apiClient.get( endpoint: TVEpisodesEndpoint.videos( tvSeriesID: tvSeriesID, seasonNumber: seasonNumber, - episodeNumber: episodeNumber + episodeNumber: episodeNumber, + languageCode: languageCode ) ) } catch let error { diff --git a/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift b/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift index 9b7939f8..3fec5ffd 100644 --- a/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift +++ b/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift @@ -12,17 +12,23 @@ final class TVEpisodesEndpointTests: XCTestCase { } func testTVEpisodeImagesEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/season/2/episode/3/images")) + let languageCode = "en" + let expectedURL = try XCTUnwrap(URL( + string: "/tv/1/season/2/episode/3/images?include_image_language=\(languageCode),null" + )) - let url = TVEpisodesEndpoint.images(tvSeriesID: 1, seasonNumber: 2, episodeNumber: 3).path + let url = TVEpisodesEndpoint.images(tvSeriesID: 1, seasonNumber: 2, episodeNumber: 3, languageCode: languageCode).path XCTAssertEqual(url, expectedURL) } func testTVSeasonVideosEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/season/2/episode/3/videos")) + let languageCode = "en" + let expectedURL = try XCTUnwrap(URL( + string: "/tv/1/season/2/episode/3/videos?include_video_language=\(languageCode),null" + )) - let url = TVEpisodesEndpoint.videos(tvSeriesID: 1, seasonNumber: 2, episodeNumber: 3).path + let url = TVEpisodesEndpoint.videos(tvSeriesID: 1, seasonNumber: 2, episodeNumber: 3, languageCode: languageCode).path XCTAssertEqual(url, expectedURL) } diff --git a/Tests/TMDbTests/TVEpisodes/TVEpisodeServiceTests.swift b/Tests/TMDbTests/TVEpisodes/TVEpisodeServiceTests.swift index 1c3d72e7..45918168 100644 --- a/Tests/TMDbTests/TVEpisodes/TVEpisodeServiceTests.swift +++ b/Tests/TMDbTests/TVEpisodes/TVEpisodeServiceTests.swift @@ -5,15 +5,18 @@ final class TVEpisodeServiceTests: XCTestCase { var service: TVEpisodeService! var apiClient: MockAPIClient! + var locale: Locale! override func setUp() { super.setUp() apiClient = MockAPIClient() - service = TVEpisodeService(apiClient: apiClient) + locale = Locale(identifier: "en_GB") + service = TVEpisodeService(apiClient: apiClient, localeProvider: { [unowned self] in locale }) } override func tearDown() { apiClient = nil + locale = nil service = nil super.tearDown() } @@ -51,7 +54,8 @@ final class TVEpisodeServiceTests: XCTestCase { XCTAssertEqual(apiClient.lastPath, TVEpisodesEndpoint.images(tvSeriesID: tvSeriesID, seasonNumber: seasonNumber, - episodeNumber: episodeNumber).path) + episodeNumber: episodeNumber, + languageCode: locale.languageCode).path) } func testVideosReturnsVideos() async throws { @@ -69,7 +73,8 @@ final class TVEpisodeServiceTests: XCTestCase { XCTAssertEqual(apiClient.lastPath, TVEpisodesEndpoint.videos(tvSeriesID: tvSeriesID, seasonNumber: seasonNumber, - episodeNumber: episodeNumber).path) + episodeNumber: episodeNumber, + languageCode: locale.languageCode).path) } } From d39e8fb57ec44177967da0d3b1d2f0eb7dd79279 Mon Sep 17 00:00:00 2001 From: dcamenisch Date: Tue, 21 Nov 2023 22:15:37 +0100 Subject: [PATCH 2/3] FIX: SwiftLint complaints --- Sources/TMDb/Extensions/URL+QueryItem.swift | 2 +- .../Endpoints/TVEpisodesEndpoint.swift | 0 .../TVEpisodeService.swift | 0 .../ENdpoints/TVEpisodesEndpointTests.swift | 12 ++++++++++-- 4 files changed, 11 insertions(+), 3 deletions(-) rename Sources/TMDb/{TVEpisodes 2 => TVEpisodes}/Endpoints/TVEpisodesEndpoint.swift (100%) rename Sources/TMDb/{TVEpisodes 2 => TVEpisodes}/TVEpisodeService.swift (100%) diff --git a/Sources/TMDb/Extensions/URL+QueryItem.swift b/Sources/TMDb/Extensions/URL+QueryItem.swift index 977233ad..8e118a86 100644 --- a/Sources/TMDb/Extensions/URL+QueryItem.swift +++ b/Sources/TMDb/Extensions/URL+QueryItem.swift @@ -37,7 +37,7 @@ extension URL { guard let languageCode else { return self } - + return appendingQueryItem(name: QueryItemName.language, value: languageCode) } diff --git a/Sources/TMDb/TVEpisodes 2/Endpoints/TVEpisodesEndpoint.swift b/Sources/TMDb/TVEpisodes/Endpoints/TVEpisodesEndpoint.swift similarity index 100% rename from Sources/TMDb/TVEpisodes 2/Endpoints/TVEpisodesEndpoint.swift rename to Sources/TMDb/TVEpisodes/Endpoints/TVEpisodesEndpoint.swift diff --git a/Sources/TMDb/TVEpisodes 2/TVEpisodeService.swift b/Sources/TMDb/TVEpisodes/TVEpisodeService.swift similarity index 100% rename from Sources/TMDb/TVEpisodes 2/TVEpisodeService.swift rename to Sources/TMDb/TVEpisodes/TVEpisodeService.swift diff --git a/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift b/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift index 3fec5ffd..7c006eef 100644 --- a/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift +++ b/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift @@ -17,7 +17,11 @@ final class TVEpisodesEndpointTests: XCTestCase { string: "/tv/1/season/2/episode/3/images?include_image_language=\(languageCode),null" )) - let url = TVEpisodesEndpoint.images(tvSeriesID: 1, seasonNumber: 2, episodeNumber: 3, languageCode: languageCode).path + let url = TVEpisodesEndpoint.images( + tvSeriesID: 1, + seasonNumber: 2, + episodeNumber: 3, + languageCode: languageCode).path XCTAssertEqual(url, expectedURL) } @@ -28,7 +32,11 @@ final class TVEpisodesEndpointTests: XCTestCase { string: "/tv/1/season/2/episode/3/videos?include_video_language=\(languageCode),null" )) - let url = TVEpisodesEndpoint.videos(tvSeriesID: 1, seasonNumber: 2, episodeNumber: 3, languageCode: languageCode).path + let url = TVEpisodesEndpoint.videos( + tvSeriesID: 1, + seasonNumber: 2, + episodeNumber: 3, + languageCode: languageCode).path XCTAssertEqual(url, expectedURL) } From a516ecb06e1385660b84d6bbf04858afd0f97d90 Mon Sep 17 00:00:00 2001 From: dcamenisch Date: Tue, 21 Nov 2023 22:17:23 +0100 Subject: [PATCH 3/3] FIX: SwiftLint complaints --- .../TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift b/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift index 7c006eef..43096558 100644 --- a/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift +++ b/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift @@ -35,7 +35,7 @@ final class TVEpisodesEndpointTests: XCTestCase { let url = TVEpisodesEndpoint.videos( tvSeriesID: 1, seasonNumber: 2, - episodeNumber: 3, + episodeNumber: 3, languageCode: languageCode).path XCTAssertEqual(url, expectedURL)