Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: TV Episode images missing language code #126

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Sources/TMDb/TVEpisodes/Endpoints/TVEpisodesEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?)

}

Expand All @@ -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)
}
}

Expand Down
15 changes: 11 additions & 4 deletions Sources/TMDb/TVEpisodes/TVEpisodeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

///
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 8 additions & 3 deletions Tests/TMDbTests/TVEpisodes/TVEpisodeServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}

}
Loading