Skip to content

Commit 26124a1

Browse files
authored
DOCS: Added documentation to models (#31)
1 parent 554f36e commit 26124a1

File tree

74 files changed

+854
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+854
-276
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import PackageDescription
2828
let package = Package(
2929
name: "MyProject",
3030
dependencies: [
31-
.package(url: "https://github.com/adamayoung/TMDb.git", upToNextMajor: "4.1.0")
31+
.package(url: "https://github.com/adamayoung/TMDb.git", upToNextMajor: "5.0.0")
3232
],
3333
targets: [
3434
.target(name: "MyProject", dependencies: ["TMDb"])

Sources/TMDb/Client/TMDbAPIClient.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ extension TMDbAPIClient {
111111

112112
return urlComponents.url!
113113
.appendingAPIKey(apiKey)
114+
.appendingCurrentLanguage()
114115
}
115116

116117
}

Sources/TMDb/Extensions/URL+QueryItem.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@ extension URL {
2222
appendingQueryItem(name: "api_key", value: apiKey)
2323
}
2424

25+
func appendingCurrentLanguage() -> Self {
26+
let locale = Locale.current
27+
var parts = [String]()
28+
if let languageCode = locale.languageCode {
29+
parts.append(languageCode)
30+
31+
if let regionCode = locale.regionCode {
32+
parts.append(regionCode)
33+
}
34+
}
35+
36+
guard !parts.isEmpty else {
37+
return self
38+
}
39+
40+
return appendingLanguage(parts.joined(separator: "-"))
41+
}
42+
43+
func appendingLanguage(_ language: String) -> Self {
44+
return appendingQueryItem(name: "language", value: language)
45+
}
46+
2547
func appendingPage(_ page: Int?) -> Self {
2648
guard var page = page else {
2749
return self

Sources/TMDb/Models/APIConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
/// API Configuration.
44
///
5-
/// - Note: Some elements of the API require some knowledge of this configuration data. The purpose of this is to try and keep the actual API responses as light as possible. It is recommended you cache this data within your application and check for updates every few days.
5+
/// Some elements of the API require some knowledge of this configuration data. The purpose of this is to try and keep the actual API responses as light as possible. It is recommended you cache this data within your application and check for updates every few days.
66
public struct APIConfiguration: Decodable, Equatable {
77

88
/// Images configuration.

Sources/TMDb/Models/CastMember.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import Foundation
33
/// A cast member of a movie or TV show.
44
public struct CastMember: Identifiable, Decodable, Equatable, ProfileURLProviding {
55

6-
/// Cast member identifier.
6+
/// Cast member's identifier.
77
public let id: Int
8-
/// Cast member identifier for the particular movie or TV show.
8+
/// Cast member's identifier for the particular movie or TV show.
99
public let castID: Int?
1010
/// Credit identifier for that particular movie or TV show.
1111
public let creditID: String
12-
/// Cast member name.
12+
/// Cast member's real name.
1313
public let name: String
1414
/// Cast member's character name.
1515
public let character: String
@@ -23,10 +23,10 @@ public struct CastMember: Identifiable, Decodable, Equatable, ProfileURLProvidin
2323
/// Creates a new `CastMember`.
2424
///
2525
/// - Parameters:
26-
/// - id: Cast member identifier.
27-
/// - castID: Cast member identifier for the particular movie or TV show.
26+
/// - id: Cast member's identifier.
27+
/// - castID: Cast member's identifier for the particular movie or TV show.
2828
/// - creditID: Credit identifier for that particular movie or TV show.
29-
/// - name: Cast member name.
29+
/// - name: Cast member's name.
3030
/// - character: Cast member's character name.
3131
/// - gender: Cast member's gender.
3232
/// - profilePath: Cast member's profile image.

Sources/TMDb/Models/CrewMember.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,31 @@ import Foundation
33
/// A crew member of a movie or TV show.
44
public struct CrewMember: Identifiable, Decodable, Equatable, ProfileURLProviding {
55

6+
/// Crew member's identifier.
67
public let id: Int
8+
/// Crew member's identifier for the particular movie or TV show.
79
public let creditID: String
10+
/// Crew member's name.
811
public let name: String
12+
/// Crew member's job.
913
public let job: String
14+
/// Crew member's department.
1015
public let department: String
16+
/// Crew member's gender.
1117
public let gender: Gender?
18+
/// Crew member's profile image.
1219
public let profilePath: URL?
1320

21+
/// Creates a new `CrewMember`.
22+
///
23+
/// - Parameters:
24+
/// - id: Crew member's identifier.
25+
/// - creditID: Crew member's identifier for the particular movie or TV show.
26+
/// - name: Crew member's name.
27+
/// - job: Crew member's job.
28+
/// - department: Crew member's department.
29+
/// - gender: Crew member's gender.
30+
/// - profilePath: Crew member's profile image.
1431
public init(id: Int, creditID: String, name: String, job: String, department: String, gender: Gender? = nil,
1532
profilePath: URL? = nil) {
1633
self.id = id

Sources/TMDb/Models/Gender.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import Foundation
22

3+
/// Gender of a person.
34
public enum Gender: Int, Decodable, Equatable {
45

6+
/// Unknown.
57
case unknown = 0
8+
/// Female.
69
case female = 1
10+
/// Male.
711
case male = 2
12+
/// Other.
813
case other = 3
914

1015
}

Sources/TMDb/Models/Genre.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import Foundation
22

3+
/// Genre.
34
public struct Genre: Identifiable, Decodable, Equatable {
45

6+
/// Genre Identifier.
57
public let id: Int
8+
/// Genre name.
69
public let name: String
710

11+
/// Creates a new `Genre`.
12+
///
13+
/// - Parameters:
14+
/// - id: Genre Identifier.
15+
/// - name: Genre name.
816
public init(id: Int, name: String) {
917
self.id = id
1018
self.name = name

Sources/TMDb/Models/ImageCollection.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import Foundation
22

3+
/// A collection of poster and backdrop images for a movie or TV show.
34
public struct ImageCollection: Decodable, Equatable {
45

6+
/// Movie or TV show identifier for these images.
57
public let id: Int
8+
/// Poster images.
69
public let posters: [ImageMetadata]
10+
/// Backdrop images.
711
public let backdrops: [ImageMetadata]
812

13+
/// Creates a new `ImageCollection`.
14+
///
15+
/// - Parameters:
16+
/// - id: Movie or TV show identifier for these images.
17+
/// - posters: Poster images.
18+
/// - backdrops: Backdrop images.
919
public init(id: Int, posters: [ImageMetadata], backdrops: [ImageMetadata]) {
1020
self.id = id
1121
self.posters = posters

Sources/TMDb/Models/ImageMetadata.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import Foundation
22

3+
/// Details describing an image.
34
public struct ImageMetadata: Identifiable, Decodable, Equatable {
45

56
public var id: URL { filePath }
7+
/// Path of the image.
68
public let filePath: URL
9+
/// Image width.
710
public let width: Int
11+
/// Image height.
812
public let height: Int
913

14+
/// Creates a new `ImageMetadata`.
15+
///
16+
/// - Parameters:
17+
/// - filePath: Path of the image.
18+
/// - width: Image width.
19+
/// - height: Image height.
1020
public init(filePath: URL, width: Int, height: Int) {
1121
self.filePath = filePath
1222
self.width = width

0 commit comments

Comments
 (0)