Skip to content

Commit

Permalink
FEATURE: Make all models conform to Codable (#140)
Browse files Browse the repository at this point in the history
* FEATURE: Make all models conform to Codable

* Fix lint warnings
  • Loading branch information
adamayoung authored Jan 16, 2024
1 parent 11fcccf commit 98732cc
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM swift:5.9-jammy
FROM swift:5.9.2-jammy

WORKDIR /tmp

Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/Country.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
///
/// A model representing a country.
///
public struct Country: Identifiable, Decodable, Equatable, Hashable {
public struct Country: Identifiable, Codable, Equatable, Hashable {

///
/// Country's identifier (same as `countryCode`).
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/Department.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
///
/// A model representing a department and jobs.
///
public struct Department: Identifiable, Decodable, Equatable, Hashable {
public struct Department: Identifiable, Codable, Equatable, Hashable {

///
/// Departments's identifier (same as `name`).
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/Language.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
///
/// A model representing a language.
///
public struct Language: Identifiable, Decodable, Equatable, Hashable {
public struct Language: Identifiable, Codable, Equatable, Hashable {

///
/// Language code.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/Media.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension Media {
case mediaType
}

private enum MediaType: String, Decodable, Equatable {
private enum MediaType: String, Codable, Equatable {
case movie
case tvSeries = "tv"
case person
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/PersonCombinedCredits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Foundation
///
/// A person can be both a cast member and crew member of the same show.
///
public struct PersonCombinedCredits: Identifiable, Decodable, Equatable, Hashable {
public struct PersonCombinedCredits: Identifiable, Codable, Equatable, Hashable {

///
/// Person identifier.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/PersonImageCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
///
/// A model representing a person image collection.
///
public struct PersonImageCollection: Identifiable, Decodable, Equatable, Hashable {
public struct PersonImageCollection: Identifiable, Codable, Equatable, Hashable {

///
/// Person identifier.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/PersonMovieCredits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Foundation
///
/// A person can be both a cast member and crew member of the same movie.
///
public struct PersonMovieCredits: Identifiable, Decodable, Equatable, Hashable {
public struct PersonMovieCredits: Identifiable, Codable, Equatable, Hashable {

///
/// Person identifier.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/PersonTVSeriesCredits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Foundation
///
/// A person can be both a cast member and crew member of the same TV series.
///
public struct PersonTVSeriesCredits: Identifiable, Decodable, Equatable, Hashable {
public struct PersonTVSeriesCredits: Identifiable, Codable, Equatable, Hashable {

///
/// Person identifier.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/ShowCredits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Foundation
///
/// A person can be both a cast member and crew member of the same show.
///
public struct ShowCredits: Identifiable, Decodable, Equatable, Hashable {
public struct ShowCredits: Identifiable, Codable, Equatable, Hashable {

///
/// Movie or TV series identifier.
Expand Down
88 changes: 88 additions & 0 deletions Sources/TMDb/Models/ShowWatchProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// ShowWatchProvider.swift
// TMDb
//
// Copyright © 2023 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 show's watch provider.
///
public struct ShowWatchProvider: Equatable, Codable {

///
/// A link to the watch provider.
///
public let link: String

///
/// A list of free watch providers.
///
public let free: [WatchProvider]?

///
/// A list of flat rate watch providers.
///
public let flatRate: [WatchProvider]?

///
/// A list of watch providers to buy from.
///
public let buy: [WatchProvider]?

///
/// A list of watch providers to rent from.
///
public let rent: [WatchProvider]?

///
/// Creates a show credits object.
///
/// - Parameters:
/// - link: A link to the watch provider.
/// - free: A list of free watch providers.
/// - flatRate: A list of flat rate watch providers.
/// - buy: A list of watch providers to buy from.
/// - rent: A list of watch providers to rent from.
///
public init(
link: String,
free: [WatchProvider]? = nil,
flatRate: [WatchProvider]? = nil,
buy: [WatchProvider]? = nil,
rent: [WatchProvider]? = nil
) {
self.link = link
self.free = free
self.flatRate = flatRate
self.buy = buy
self.rent = rent
}

}

extension ShowWatchProvider {

private enum CodingKeys: String, CodingKey {
case link
case free
case flatRate = "flatrate"
case buy
case rent
}

}
10 changes: 2 additions & 8 deletions Sources/TMDb/Models/ShowWatchProviderResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@

import Foundation

struct ShowWatchProviderResult: Equatable, Decodable {
struct ShowWatchProviderResult: Equatable, Codable {

let id: Int
let results: [String: ShowWatchProvider]
}

public struct ShowWatchProvider: Equatable, Decodable {
public let link: String
public let free: [WatchProvider]?
public let flatrate: [WatchProvider]?
public let buy: [WatchProvider]?
public let rent: [WatchProvider]?
}
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/TVEpisodeImageCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
///
/// A model representing a TV episode image collection.
///
public struct TVEpisodeImageCollection: Identifiable, Decodable, Equatable, Hashable {
public struct TVEpisodeImageCollection: Identifiable, Codable, Equatable, Hashable {

///
/// Collection identifier.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/TVSeasonImageCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
///
/// A model representing a TV season image collection.
///
public struct TVSeasonImageCollection: Identifiable, Decodable, Equatable, Hashable {
public struct TVSeasonImageCollection: Identifiable, Codable, Equatable, Hashable {

///
/// Collection identifier.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/WatchProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
///
/// A model representing a watch provider.
///
public struct WatchProvider: Identifiable, Decodable, Equatable, Hashable {
public struct WatchProvider: Identifiable, Codable, Equatable, Hashable {

///
/// Watch Provider identifier.
Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/WatchProviderRegions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import Foundation

struct WatchProviderRegions: Decodable {
struct WatchProviderRegions: Codable {

let results: [Country]

Expand Down
2 changes: 1 addition & 1 deletion Sources/TMDb/Models/WatchProviderResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import Foundation

struct WatchProviderResult: Decodable, Equatable {
struct WatchProviderResult: Codable, Equatable {

let results: [WatchProvider]

Expand Down
4 changes: 2 additions & 2 deletions Tests/TMDbTests/Mocks/Models/ShowWatchProvider+Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ extension ShowWatchProvider {
static func mock(
link: String = "",
free: [WatchProvider]? = [.netflix],
flatrate: [WatchProvider]? = [.netflix],
flatRate: [WatchProvider]? = [.netflix],
buy: [WatchProvider]? = [.netflix],
rent: [WatchProvider]? = [.netflix]
) -> Self {
.init(
link: link,
free: free,
flatrate: flatrate,
flatRate: flatRate,
buy: buy,
rent: rent
)
Expand Down

0 comments on commit 98732cc

Please sign in to comment.