8000 FEATURE: TV Season Aggregate Credits (#175) · adamayoung/TMDb@3a5246e · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
FEATURE: TV Season Aggregate Credits (#175)
Browse files Browse the repository at this point in the history
* Model and request

* Update TV Season service

* Add integration tests
  • Loading branch information
adamayoung authored May 7, 2024
1 parent a6cd279 commit 3a5246e
Show file tree
Hide file tree
Showing 10 changed files with 353 additions and 1 deletion.
58 changes: 58 additions & 0 deletions Sources/TMDb/Domain/Models/TVSeasonAggregateCredits.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// TVSeasonAggregateCredits.swift
// TMDb
//
// Copyright © 2024 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

///
/// A model representing a TV series aggregated credits.
///
/// A person can be both a cast member and crew member of the same show.
///
public struct TVSeasonAggregateCredits: Identifiable, Codable, Equatable, Hashable, Sendable {

///
/// TV season identifier.
///
public let id: TVSeason.ID

///
/// Cast members of the TV series.
///
public let cast: [AggregrateCastMember]

///
/// Crew members of the TV series.
///
public let crew: [AggregrateCrewMember]

///
/// Creates a TV season aggregrate credits object.
///
/// - Parameters:
/// - id: TV season identifier.
/// - cast: Cast members of the TV series.
/// - crew: Crew members of the TV series.
///
public init(id: TVSeason.ID, cast: [AggregrateCastMember], crew: [AggregrateCrewMember]) {
self.id = id
self.cast = cast
self.crew = crew
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// TVSeasonAggregateCreditsRequest.swift
// TMDb
//
// Copyright © 2024 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

final class TVSeasonAggregateCreditsRequest: DecodableAPIRequest<TVSeasonAggregateCredits> {

init(seasonNumber: Int, tvSeriesID: TVSeries.ID) {
let path = "/tv/\(tvSeriesID)/season/\(seasonNumber)/aggregate_credits"

super.init(path: path)
}

}
33 changes: 33 additions & 0 deletions Sources/TMDb/Domain/Services/TVSeasons/TVSeasonService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,39 @@ public final class TVSeasonService {
return season
}

///
/// Returns the aggregate cast and crew of a TV season.
///
/// This call differs from the main credits call in that it does not return
/// the newest season. Instead, it is a view of all the entire cast & crew
/// for all episodes belonging to a TV season.
///
/// [TMDb API - TV Season: Aggregate Credits](https://developer.themoviedb.org/reference/tv-season-aggregate-credits)
///
/// - Parameters:
/// - seasonNumber: The season number of a TV series.
/// - tvSeriesID: The identifier of the TV series.
///
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: Show credits for the matching TV season.
///
public func aggregateCredits(
forSeason seasonNumber: Int,
inTVSeries tvSeriesID: TVSeries.ID
) async throws -> TVSeasonAggregateCredits {
let request = TVSeasonAggregateCreditsRequest(seasonNumber: seasonNumber, tvSeriesID: tvSeriesID)

let credits: TVSeasonAggregateCredits
do {
credits = try await apiClient.perform(request)
} catch let error {
throw TMDbError(error: error)
}

return credits
}

///
/// Returns the images that belong to a TV season.
///
Expand Down
4 changes: 4 additions & 0 deletions Sources/TMDb/TMDb.docc/Extensions/TVSeasonService.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

- ``details(forSeason:inTVSeries:)``

### Credits

- ``aggregateCredits(forSeason:inTVSeries:)``

### Media

- ``images(forSeason:inTVSeries:)``
Expand Down
1 change: 0 additions & 1 deletion Tests/TMDbIntegrationTests/AccountIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ final class AccountIntegrationTests: XCTestCase {
}

func testAddingAndRemovingFavouriteMovies() async throws {
print("heloo")
let accountDetails = try await accountService.details(session: session)
let movieID = 550

Expand Down
20 changes: 20 additions & 0 deletions Tests/TMDbIntegrationTests/TVSeasonService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,30 @@ final class TVSeasonServiceTests: XCTestCase {
XCTAssertFalse((season.episodes ?? []).isEmpty)
}

func testAggregateCredits() async throws {
let seasonNumber = 2
let tvSeriesID = 1399

let credits = try await tvSeasonService.aggregateCredits(forSeason: seasonNumber, inTVSeries: tvSeriesID)

XCTAssertEqual(credits.id, 3625)
XCTAssertFalse(credits.cast.isEmpty)
XCTAssertFalse(credits.crew.isEmpty)
}

func testImages() async throws {
let seasonNumber = 1
let tvSeriesID = 1399

let imagesCollection = try await tvSeasonService.images(forSeason: seasonNumber, inTVSeries: tvSeriesID)

XCTAssertFalse(imagesCollection.posters.isEmpty)
}

func testVideos() async throws {
let seasonNumber = 1
let tvSeriesID = 1399

let videoCollection = try await tvSeasonService.videos(forSeason: seasonNumber, inTVSeries: tvSeriesID)

XCTAssertFalse(videoCollection.results.isEmpty)
Expand Down
36 changes: 36 additions & 0 deletions Tests/TMDbTests/Domain/Models/TVSeasonAggregateCreditsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// TVSeasonAggregateCreditsTests.swift
// TMDb
//
// Copyright © 2024 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

@testable import TMDb
import XCTest

final class TVSeasonAggregateCreditsTests: XCTestCase {

func testDecodeReturnsTVSeasonAggregateCredits() throws {
let result = try JSONDecoder.theMovieDatabase.decode(
TVSeriesAggregateCredits.self,
fromResource: "tv-season-aggregate-credits"
)

XCTAssertEqual(result.id, 3625)
XCTAssertEqual(result.cast.count, 3)
XCTAssertEqual(result.crew.count, 2)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// TVSeasonAggregateCreditsRequestTests.swift
// TMDb
//
// Copyright © 2024 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

@testable import TMDb
import XCTest

final class TVSeasonAggregateCreditsRequestTests: XCTestCase {

var request: TVSeasonAggregateCreditsRequest!

override func setUp() {
super.setUp()
request = TVSeasonAggregateCreditsRequest(seasonNumber: 2, tvSeriesID: 1)
}

override func tearDown() {
request = nil
super.tearDown()
}

func testPath() {
XCTAssertEqual(request.path, "/tv/1/season/2/aggregate_credits")
}

func testQueryItemsAreEmpty() {
XCTAssertTrue(request.queryItems.isEmpty)
}

func testMethodIsGet() {
XCTAssertEqual(request.method, .get)
}

func testHeadersIsEmpty() {
XCTAssertTrue(request.headers.isEmpty)
}

func testBodyIsNil() {
XCTAssertNil(request.body)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ final class TVSeasonServiceTests: XCTestCase {
XCTAssertEqual(apiClient.lastRequest as? TVSeasonRequest, expectedRequest)
}

func testAggregateCreditsReturnsTVSeasonCredits() async throws {
let tvSeriesID = Int.randomID
let expectedResult = TVSeasonAggregateCredits(id: 1, cast: [], crew: [])
let seasonNumber = Int.randomID
apiClient.addResponse(.success(expectedResult))
let expectedRequest = TVSeasonAggregateCreditsRequest(seasonNumber: seasonNumber, tvSeriesID: tvSeriesID)

let result = try await service.aggregateCredits(forSeason: seasonNumber, inTVSeries: tvSeriesID)

XCTAssertEqual(result, expectedResult)
XCTAssertEqual(apiClient.lastRequest as? TVSeasonAggregateCreditsRequest, expectedRequest)
}

func testImagesReturnsImages() async throws {
let seasonNumber = Int.randomID
let tvSeriesID = Int.randomID
Expand Down
102 changes: 102 additions & 0 deletions Tests/TMDbTests/Resources/json/tv-season-aggregate-credits.json
BFEC
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"cast": [
{
"adult": false,
"gender": 2,
"id": 22970,
"known_for_department": "Acting",
"name": "Peter Dinklage",
"original_name": "Peter Dinklage",
"popularity": 44.296,
"profile_path": "/9CAd7wr8QZyIN0E7nm8v1B6WkGn.jpg",
"roles": [
{
"credit_id": "5256c8b219c2956ff6047cd8",
"character": "Tyrion 'The Halfman' Lannister",
"episode_count": 10
}
],
"total_episode_count": 10,
"order": 0
},
{
"adult": false,
"gender": 2,
"id": 239019,
"known_for_department": "Acting",
"name": "Kit Harington",
"original_name": "Kit Harington",
"popularity": 32.025,
"profile_path": "/htGBMno71BJAEGF3Y9f62MdA3Yt.jpg",
"roles": [
{
"credit_id": "5256c8af19c2956ff6047af6",
"character": "Jon Snow",
"episode_count": 10
}
],
"total_episode_count": 10,
"order": 1
},
{
"adult": false,
"gender": 2,
"id": 512991,
"known_for_department": "Acting",
"name": "Richard Madden",
"original_name": "Richard Madden",
"popularity": 44.12,
"profile_path": "/kC7X9LgAtJfpxUBRtVwaVTEXomH.jpg",
"roles": [
{
"credit_id": "5256c8af19c2956ff6047b1a",
"character": "Robb Stark",
"episode_count": 10
}
],
"total_episode_count": 10,
"order": 4
}
],
"crew": [
{
"adult": false,
"gender": 0,
"id": 982992,
"known_for_department": "Art",
"name": "Ashleigh Jeffers",
"original_name": "Ashleigh Jeffers",
"popularity": 5.33,
"profile_path": null,
"jobs": [
{
"credit_id": "622da5c312970c007974b75d",
"job": "Art Direction",
"episode_count": 9
}
],
"department": "Art",
"total_episode_count": 9
},
{
"adult": false,
"gender": 2,
"id": 37301,
"known_for_department": "Art",
"name": "Frank Walsh",
"original_name": "Frank Walsh",
"popularity": 5.677,
"profile_path": null,
"jobs": [
{
"credit_id": "622da5b2534661001b7d306f",
"job": "Supervising Art Director",
"episode_count": 9
}
],
"department": "Art",
"total_episode_count": 9
}
],
"id": 3625
}

0 comments on commit 3a5246e

Please sign in to comment.
0