-
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.
- Loading branch information
1 parent
17d8ace
commit c32b6fd
Showing
376 changed files
with
8,307 additions
and
3,729 deletions.
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
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
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,67 @@ | ||
// | ||
// APIRequestQueryItem.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 | ||
|
||
typealias APIRequestQueryItems = [APIRequestQueryItem.Name: CustomStringConvertible] | ||
|
||
struct APIRequestQueryItem { | ||
|
||
private init() {} | ||
|
||
} | ||
|
||
extension APIRequestQueryItem { | ||
|
||
struct Name: ExpressibleByStringLiteral, CustomStringConvertible, Equatable, Hashable { | ||
|
||
private let name: String | ||
|
||
init(_ name: String) { | ||
self.name = name | ||
} | ||
|
||
init(stringLiteral: String) { | ||
self.init(stringLiteral) | ||
} | ||
|
||
var description: String { | ||
name | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
extension APIRequestQueryItem.Name { | ||
|
||
static let page = APIRequestQueryItem.Name("page") | ||
static let sortBy = APIRequestQueryItem.Name("sort_by") | ||
static let withPeople = APIRequestQueryItem.Name("with_people") | ||
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 query = APIRequestQueryItem.Name("query") | ||
static let year = APIRequestQueryItem.Name("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 apiKey = APIRequestQueryItem.Name("api_key") | ||
|
||
} |
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,75 @@ | ||
// | ||
// CodableAPIRequest.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 | ||
|
||
class CodableAPIRequest<Body: Encodable & Equatable, Response: Decodable>: APIRequest, CustomStringConvertible { | ||
|
||
let id: UUID | ||
let path: String | ||
let queryItems: [String: String] | ||
let method: APIRequestMethod | ||
let headers: [String: String] | ||
let body: Body? | ||
|
||
var description: String { | ||
var description = """ | ||
APIRequest: | ||
\tid: \(id.uuidString) | ||
\tpath: \(path) | ||
\tqueryItems: \(queryItems.map { "\($0)=\($1)" }.joined(separator: "&")) | ||
\tmethod: \(method) | ||
\theaders: \(headers.map { "\($0): \(1)" }.joined(separator: " ")) | ||
""" | ||
|
||
if let body { | ||
description += "\nBody:\n\(body)" | ||
} | ||
|
||
return description | ||
} | ||
|
||
init( | ||
id: UUID = UUID(), | ||
path: String, | ||
queryItems: APIRequestQueryItems = [:], | ||
method: APIRequestMethod = .post, | ||
body: Body? = nil, | ||
headers: [String: String] = [:] | ||
) { | ||
self.id = id | ||
self.path = path | ||
let queryItems = queryItems.map { (key: APIRequestQueryItem.Name, value: any CustomStringConvertible) in | ||
(key.description, value.description) | ||
} | ||
self.queryItems = Dictionary(uniqueKeysWithValues: queryItems) | ||
self.method = method | ||
self.body = body | ||
self.headers = headers | ||
} | ||
|
||
static func == (lhs: CodableAPIRequest<Body, Response>, rhs: CodableAPIRequest<Body, Response>) -> Bool { | ||
lhs.path == rhs.path | ||
&& lhs.queryItems == rhs.queryItems | ||
&& lhs.method == rhs.method | ||
&& lhs.headers == rhs.headers | ||
&& lhs.body == rhs.body | ||
} | ||
|
||
} |
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,43 @@ | ||
// | ||
// DecodableAPIRequest.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 | ||
|
||
class DecodableAPIRequest<Response: Decodable>: CodableAPIRequest<EmptyBody, Response> { | ||
|
||
init( | ||
id: UUID = UUID(), | ||
path: String, | ||
queryItems: APIRequestQueryItems = [:], | ||
method: APIRequestMethod = .get, | ||
headers: [String: String] = [:] | ||
) { | ||
super.init( | ||
id: id, | ||
path: path, | ||
queryItems: queryItems, | ||
method: method, | ||
body: nil, | ||
headers: headers | ||
) | ||
} | ||
|
||
} | ||
|
||
struct EmptyBody: Encodable, Equatable {} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.