diff --git a/Sources/TMDb/TVEpisodes/Endpoints/TVEpisodesEndpoint.swift b/Sources/TMDb/TVEpisodes/Endpoints/TVEpisodesEndpoint.swift index 32eb79ce..c2f0fb8b 100644 --- a/Sources/TMDb/TVEpisodes/Endpoints/TVEpisodesEndpoint.swift +++ b/Sources/TMDb/TVEpisodes/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/TVEpisodeService.swift index 8b5481b7..d39d28a0 100644 --- a/Sources/TMDb/TVEpisodes/TVEpisodeService.swift +++ b/Sources/TMDb/TVEpisodes/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..43096558 100644 --- a/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift +++ b/Tests/TMDbTests/TVEpisodes/ENdpoints/TVEpisodesEndpointTests.swift @@ -12,17 +12,31 @@ 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 url = TVEpisodesEndpoint.videos(tvSeriesID: 1, seasonNumber: 2, episodeNumber: 3).path + 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, + 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) } }