-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: TVShow Content Ratings (#188)
* Add models and reqeust * Add coding key * Finalize * Add id and initializer to Content Rating * Update models * Add mocks and tests * Add json * Add service test * Format * Remove swiftlint disable comment * Request tests * formatting * More mocks and tests --------- Co-authored-by: Adam Young <me@adam-young.co.uk>
- Loading branch information
1 parent
868a1ad
commit 08094ce
Showing
15 changed files
with
693 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// ContentRating.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 the content rating. | ||
/// | ||
public struct ContentRating: Codable, Equatable, Hashable, Sendable { | ||
|
||
/// | ||
/// ? | ||
/// | ||
public let descriptors: [String] | ||
|
||
/// | ||
/// The ISO 3166-1 country code. | ||
/// | ||
public let countryCode: String | ||
|
||
/// | ||
/// The content rating of the tv show | ||
/// | ||
public let rating: String | ||
|
||
/// Creates a content rating object. | ||
/// | ||
/// - Parameters: | ||
/// - descriptors: Array of.... | ||
/// - countryCode: ISO 3166-1 country code. | ||
/// - rating: The content rating of the tv show | ||
/// | ||
public init(descriptors: [String], countryCode: String, rating: String) { | ||
self.descriptors = descriptors | ||
self.countryCode = countryCode | ||
self.rating = rating | ||
} | ||
} | ||
|
||
extension ContentRating { | ||
private enum CodingKeys: String, CodingKey { | ||
case rating | ||
case descriptors | ||
case countryCode = "iso31661" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// ContentRatingResult.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 | ||
|
||
struct ContentRatingResult: Codable, Equatable, Hashable, Sendable { | ||
let results: [ContentRating] | ||
let id: Int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Sources/TMDb/Domain/Services/TVSeries/Requests/ContentRatingRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// ContentRatingRequest.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 ContentRatingRequest: DecodableAPIRequest<ContentRatingResult> { | ||
|
||
init(id: TVSeries.ID) { | ||
let path = "/tv/\(id)/content_ratings" | ||
|
||
super.init(path: path) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// ContentRatingTests.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 ContentRatingTests: XCTestCase { | ||
|
||
func testDecodeReturnsContentRating() throws { | ||
let result = try JSONDecoder.theMovieDatabase.decode(ContentRating.self, fromResource: "content-rating") | ||
|
||
XCTAssertEqual(result.descriptors, contentRating.descriptors) | ||
XCTAssertEqual(result.countryCode, contentRating.countryCode) | ||
XCTAssertEqual(result.rating, contentRating.rating) | ||
} | ||
|
||
private let contentRating = ContentRating( | ||
descriptors: [], | ||
countryCode: "US", | ||
rating: "TV-14" | ||
) | ||
} |
151 changes: 151 additions & 0 deletions
151
Tests/TMDbTests/Domain/Models/ContentRatingsTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// | ||
// ContentRatingsTests.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 ContentRatingsTests: XCTestCase { | ||
|
||
func testDecodeReturnsContentRatingResult() throws { | ||
let result = try JSONDecoder.theMovieDatabase.decode(ContentRatingResult.self, fromResource: "content-ratings") | ||
|
||
XCTAssertEqual(result, contentRatings) | ||
} | ||
|
||
private let contentRatings = ContentRatingResult( | ||
results: [ | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "US", | ||
rating: "TV-14" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "AU", | ||
rating: "M" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "RU", | ||
rating: "12+" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "GB", | ||
rating: "15" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "BR", | ||
rating: "12" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "HU", | ||
rating: "12" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "PH", | ||
rating: "G" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "MX", | ||
rating: "A" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "PT", | ||
rating: "NR" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "ES", | ||
rating: "16" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "FR", | ||
rating: "16" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "CA", | ||
rating: "PG" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "NL", | ||
rating: "6" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "DE", | ||
rating: "12" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "DE", | ||
rating: "16" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "AU", | ||
rating: "PG" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "KR", | ||
rating: "15" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "AT", | ||
rating: "12" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "CH", | ||
rating: "12" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "PL", | ||
rating: "16" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "HU", | ||
rating: "16" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "CZ", | ||
rating: "15+" | ||
), | ||
ContentRating( | ||
descriptors: [], | ||
countryCode: "RO", | ||
rating: "15" | ||
) | ||
], | ||
id: 8592 | ||
) | ||
} |
Oops, something went wrong.