mirror of
https://github.com/LukeHagar/plexswift.git
synced 2025-12-09 20:57:45 +00:00
Regeneration
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
import Foundation
|
||||
#if os(Linux)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
|
||||
extension HTTPURLResponse {
|
||||
var contentType: String {
|
||||
return value(forHTTPHeaderField: "Content-Type") ?? "application/octet-stream"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
func matchContentType(pattern: String) -> Bool {
|
||||
// Match wildcard types
|
||||
if pattern == "*" || pattern == "*/*" {
|
||||
return true
|
||||
}
|
||||
|
||||
// Match content type of the format 'application/json; charset=UTF-8'
|
||||
let contentTypeComponents = pattern.components(separatedBy: ";").map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
|
||||
guard let mediaType = contentTypeComponents.first else { return false }
|
||||
if mediaType == pattern {
|
||||
return true
|
||||
}
|
||||
|
||||
// Match wildcard parts on the media type
|
||||
let mediaTypeComponents = mediaType.components(separatedBy: "/")
|
||||
guard mediaTypeComponents.count == 2 else { return false }
|
||||
|
||||
return pattern == "\(mediaTypeComponents[0])/*" || pattern == "*/\(mediaTypeComponents[1])"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
import Foundation
|
||||
|
||||
enum StringSubstitutionError: Swift.Error {
|
||||
case `internal`
|
||||
case missingParameter(named: String, in: String)
|
||||
}
|
||||
|
||||
extension String {
|
||||
typealias SubstitutionHandler = (_ key: String) throws -> String?
|
||||
|
||||
func substituteComponents(using substitutionHandler: SubstitutionHandler) throws -> String {
|
||||
let regex = try NSRegularExpression(pattern: "\\{([^}]+)\\}")
|
||||
let range = NSRange(startIndex..<endIndex, in: self)
|
||||
let matches = regex.matches(in: self, range: range)
|
||||
|
||||
var substitutedPath = self
|
||||
// Reverse matches so that we can replace substrings in place.
|
||||
for match in matches.reversed() {
|
||||
let templateRange = match.range
|
||||
guard let keyRange = Range(match.range(at: 1), in: self) else {
|
||||
throw StringSubstitutionError.internal
|
||||
}
|
||||
|
||||
let key = String(self[keyRange])
|
||||
guard let serializedParameter = try substitutionHandler(key) else {
|
||||
throw StringSubstitutionError.missingParameter(named: key, in: self)
|
||||
}
|
||||
|
||||
let startIndex = substitutedPath.index(substitutedPath.startIndex, offsetBy: templateRange.location)
|
||||
let endIndex = substitutedPath.index(startIndex, offsetBy: templateRange.length)
|
||||
substitutedPath.replaceSubrange(startIndex..<endIndex, with: serializedParameter)
|
||||
}
|
||||
return substitutedPath
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user