Skip to content

Commit

Permalink
FEATURE: Allow the use of language and country codes for certain endp…
Browse files Browse the repository at this point in the history
…oints (#176)

* Add extensions to locale

* Discover service

* Discover and Genres

* Configuration Countries

* People

* Fix linting errors

* Search

* Trending

* TVSeries

* Tidy up

* WIP

* TVSeasonService

* TVEpisodeService

* WatchProviderService

* Remove LocaleProvider

* Remove LocaleProviderTests

* Update Apple device versions for GH actions'

* Update tests
  • Loading branch information
adamayoung authored May 15, 2024
1 parent 3a5246e commit a143068
Show file tree
Hide file tree
Showing 156 changed files with 2,994 additions and 1,483 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ jobs:
matrix:
include:
- name: iOS
destination: platform=iOS Simulator,name=iPhone 15,OS=17.4
destination: platform=iOS Simulator,name=iPhone 15,OS=17.5
- name: watchOS
destination: platform=watchOS Simulator,name=Apple Watch Series 9 (45mm),OS=10.4
destination: platform=watchOS Simulator,name=Apple Watch Series 9 (45mm),OS=10.5
- name: tvOS
destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=17.4
destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=17.5
- name: visionOS
destination: platform=visionOS Simulator,name=Apple Vision Pro,OS=1.1
destination: platform=visionOS Simulator,name=Apple Vision Pro,OS=1.2
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
54 changes: 0 additions & 54 deletions Sources/TMDb/Adapters/LocaleProvider.swift

This file was deleted.

3 changes: 3 additions & 0 deletions Sources/TMDb/Domain/APIClient/APIRequestQueryItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ extension APIRequestQueryItem.Name {
static let watchRegion = APIRequestQueryItem.Name("watch_region")
static let includeImageLanguage = APIRequestQueryItem.Name("include_image_language")
static let includeVideoLanguage = APIRequestQueryItem.Name("include_video_language")
static let includeAdult = APIRequestQueryItem.Name("include_adult")
static let query = APIRequestQueryItem.Name("query")
static let year = APIRequestQueryItem.Name("year")
static let primaryReleaseYear = APIRequestQueryItem.Name("primary_release_year")
static let firstAirDateYear = APIRequestQueryItem.Name("first_air_date_year")
static let sessionID = APIRequestQueryItem.Name("session_id")
static let language = APIRequestQueryItem.Name("language")
static let region = APIRequestQueryItem.Name("region")
static let apiKey = APIRequestQueryItem.Name("api_key")

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ public final class ConfigurationService {
///
/// [TMDb API - Configuration: Countries](https://developer.themoviedb.org/reference/configuration-countries)
///
/// - Parameters:
/// - language: ISO 639-1 language code to display results in. Defaults to `en`.
///
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: Countries used throughout TMDb,
///
public func countries() async throws -> [Country] {
let request = CountriesConfigurationRequest()
public func countries(language: String? = nil) async throws -> [Country] {
let request = CountriesConfigurationRequest(language: language)

let countries: [Country]
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,23 @@ import Foundation

final class CountriesConfigurationRequest: DecodableAPIRequest<[Country]> {

init() {
init(language: String? = nil) {
let path = "/configuration/countries"
let queryItems = APIRequestQueryItems(language: language)

super.init(path: path)
super.init(path: path, queryItems: queryItems)
}

}

private extension APIRequestQueryItems {

init(language: String?) {
self.init()

if let language {
self[.language] = language
}
}

}
20 changes: 16 additions & 4 deletions Sources/TMDb/Domain/Services/Discover/DiscoverService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class DiscoverService {
/// - sortedBy: How results should be sorted.
/// - people: A list of Person identifiers which to return only movies they have appeared in.
/// - page: The page of results to return.
/// - language: ISO 639-1 language code to display results in. Defaults to `en`.
///
/// - Throws: TMDb error ``TMDbError``.
///
Expand All @@ -61,9 +62,15 @@ public final class DiscoverService {
public func movies(
sortedBy: MovieSort? = nil,
withPeople people: [Person.ID]? = nil,
page: Int? = nil
page: Int? = nil,
language: String? = nil
) async throws -> MoviePageableList {
let request = DiscoverMoviesRequest(sortedBy: sortedBy, people: people, page: page)
let request = DiscoverMoviesRequest(
sortedBy: sortedBy,
people: people,
page: page,
language: language
)

let movieList: MoviePageableList
do {
Expand All @@ -85,13 +92,18 @@ public final class DiscoverService {
/// - Parameters:
/// - sortedBy: How results should be sorted.
/// - page: The page of results to return.
/// - language: ISO 639-1 language code to display results in. Defaults to `en`.
///
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: Matching TV series as a pageable list.
///
public func tvSeries(sortedBy: TVSeriesSort? = nil, page: Int? = nil) async throws -> TVSeriesPageableList {
let request = DiscoverTVSeriesRequest(sortedBy: sortedBy, page: page)
public func tvSeries(
sortedBy: TVSeriesSort? = nil,
page: Int? = nil,
language: String? = nil
) async throws -> TVSeriesPageableList {
let request = DiscoverTVSeriesRequest(sortedBy: sortedBy, page: page, language: language)

let tvSeriesList: TVSeriesPageableList
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ import Foundation

final class DiscoverMoviesRequest: DecodableAPIRequest<MoviePageableList> {

init(sortedBy: MovieSort? = nil, people: [Person.ID]? = nil, page: Int? = nil) {
init(
sortedBy: MovieSort? = nil,
people: [Person.ID]? = nil,
page: Int? = nil,
language: String? = nil
) {
let path = "/discover/movie"
let queryItems = APIRequestQueryItems(sortedBy: sortedBy, people: people, page: page)
let queryItems = APIRequestQueryItems(
sortedBy: sortedBy,
people: people,
page: page,
language: language
)

super.init(path: path, queryItems: queryItems)
}
Expand All @@ -32,7 +42,12 @@ final class DiscoverMoviesRequest: DecodableAPIRequest<MoviePageableList> {

private extension APIRequestQueryItems {

init(sortedBy: MovieSort?, people: [Person.ID]?, page: Int?) {
init(
sortedBy: MovieSort?,
people: [Person.ID]?,
page: Int?,
language: String?
) {
self.init()

if let sortedBy {
Expand All @@ -46,6 +61,10 @@ private extension APIRequestQueryItems {
if let page {
self[.page] = page
}

if let language {
self[.language] = language
}
}

private static func peopleQueryItemValue(for people: [Person.ID]) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import Foundation

final class DiscoverTVSeriesRequest: DecodableAPIRequest<TVSeriesPageableList> {

init(sortedBy: TVSeriesSort? = nil, page: Int? = nil) {
init(sortedBy: TVSeriesSort? = nil, page: Int? = nil, language: String? = nil) {
let path = "/discover/tv"
let queryItems = APIRequestQueryItems(sortedBy: sortedBy, page: page)
let queryItems = APIRequestQueryItems(sortedBy: sortedBy, page: page, language: language)

super.init(path: path, queryItems: queryItems)
}
Expand All @@ -32,7 +32,7 @@ final class DiscoverTVSeriesRequest: DecodableAPIRequest<TVSeriesPageableList> {

private extension APIRequestQueryItems {

init(sortedBy: TVSeriesSort?, page: Int?) {
init(sortedBy: TVSeriesSort?, page: Int?, language: String?) {
self.init()

if let sortedBy {
Expand All @@ -42,6 +42,10 @@ private extension APIRequestQueryItems {
if let page {
self[.page] = page
}

if let language {
self[.language] = language
}
}

}
14 changes: 10 additions & 4 deletions Sources/TMDb/Domain/Services/Genres/GenreService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ public final class GenreService {
///
/// [TMDb API - Genres: Movie List](https://developer.themoviedb.org/reference/genre-movie-list)
///
/// - Parameters:
/// - language: ISO 639-1 language code to display results in. Defaults to `en`.
///
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: A list of genres.
///
public func movieGenres() async throws -> [Genre] {
let request = MovieGenresRequests()
public func movieGenres(language: String? = nil) async throws -> [Genre] {
let request = MovieGenresRequest(language: language)

let genreList: GenreList
do {
Expand All @@ -69,12 +72,15 @@ public final class GenreService {
///
/// [TMDb API - Genres: TV List](https://developer.themoviedb.org/reference/genre-tv-list)
///
/// - Parameters:
/// - language: ISO 639-1 language code to display results in. Defaults to `en`.
///
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: A list of genres.
///
public func tvSeriesGenres() async throws -> [Genre] {
let request = TVSeriesGenresRequests()
public func tvSeriesGenres(language: String? = nil) async throws -> [Genre] {
let request = TVSeriesGenresRequest(language: language)

let genreList: GenreList
do {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// MovieGenresRequests.swift
// MovieGenresRequest.swift
// TMDb
//
// Copyright © 2024 Adam Young.
Expand All @@ -19,12 +19,25 @@

import Foundation

final class MovieGenresRequests: DecodableAPIRequest<GenreList> {
final class MovieGenresRequest: DecodableAPIRequest<GenreList> {

init() {
init(language: String? = nil) {
let path = "/genre/movie/list"
let queryItems = APIRequestQueryItems(language: language)

super.init(path: path)
super.init(path: path, queryItems: queryItems)
}

}

private extension APIRequestQueryItems {

init(language: String?) {
self.init()

if let language {
self[.language] = language
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@

import Foundation

final class TVSeriesGenresRequests: DecodableAPIRequest<GenreList> {
final class TVSeriesGenresRequest: DecodableAPIRequest<GenreList> {

init() {
init(language: String? = nil) {
let path = "/genre/tv/list"
let queryItems = APIRequestQueryItems(language: language)

super.init(path: path)
super.init(path: path, queryItems: queryItems)
}

}

private extension APIRequestQueryItems {

init(language: String?) {
self.init()

if let language {
self[.language] = language
}
}

}
Loading

0 comments on commit a143068

Please sign in to comment.