DownloadRequest

open class DownloadRequest : Request

Undocumented

  • A collection of options to be executed prior to moving a downloaded file from the temporary URL to the destination URL.

    See more

    Declaration

    Swift

    public struct Options : OptionSet
  • A closure executed once a download request has successfully completed in order to determine where to move the temporary file written to during the download process. The closure takes two arguments: the temporary file URL and the URL response, and returns a two arguments: the file URL where the temporary file should be moved and the options defining how the file should be moved.

    Declaration

    Swift

    public typealias Destination = (_ temporaryURL: URL, _ response: HTTPURLResponse) -> (destinationURL: URL, options: Options)
  • Creates a download file destination closure which uses the default file manager to move the temporary file to a file URL in the first available directory with the specified search path directory and search path domain mask.

    Declaration

    Swift

    open class func suggestedDownloadDestination(for directory: FileManager.SearchPathDirectory = .documentDirectory,
                                                 in domain: FileManager.SearchPathDomainMask = .userDomainMask,
                                                 options: Options = []) -> Destination

    Parameters

    directory

    The search path directory. .documentDirectory by default.

    domain

    The search path domain mask. .userDomainMask by default.

    Return Value

    A download file destination closure.

  • Undocumented

    See more

    Declaration

    Swift

    public enum Downloadable
  • Undocumented

    Declaration

    Swift

    public var resumeData: Data? { get }
  • Undocumented

    Declaration

    Swift

    public var fileURL: URL? { get }
  • Undocumented

    Declaration

    Swift

    open func task(forResumeData data: Data, using session: URLSession) -> URLSessionTask
  • Declaration

    Swift

    @discardableResult
    open override func cancel() -> Self
  • Validates the request, using the specified closure.

    If validation fails, subsequent calls to response handlers will have an associated error.

    Declaration

    Swift

    @discardableResult
    public func validate(_ validation: @escaping Validation) -> Self

    Parameters

    validation

    A closure to validate the request.

    Return Value

    The request.

  • Adds a handler to be called once the request has finished.

    Declaration

    Swift

    @discardableResult
    public func response(
        queue: DispatchQueue = .main,
        completionHandler: @escaping (DownloadResponse<URL?>) -> Void)
        -> Self

    Parameters

    queue

    The queue on which the completion handler is dispatched. Defaults to .main.

    completionHandler

    The code to be executed once the request has finished.

    Return Value

    The request.

  • Adds a handler to be called once the request has finished.

    Declaration

    Swift

    @discardableResult
    public func response<T: DownloadResponseSerializerProtocol>(
        queue: DispatchQueue = .main,
        responseSerializer: T,
        completionHandler: @escaping (DownloadResponse<T.SerializedObject>) -> Void)
        -> Self

    Parameters

    queue

    The queue on which the completion handler is dispatched. Defaults to .main.

    responseSerializer

    The response serializer responsible for serializing the request, response, and data contained in the destination url.

    completionHandler

    The code to be executed once the request has finished.

    Return Value

    The request.

  • Adds a handler to be called once the request has finished.

    Declaration

    Swift

    @discardableResult
    public func responseData(
        queue: DispatchQueue = .main,
        completionHandler: @escaping (DownloadResponse<Data>) -> Void)
        -> Self

    Parameters

    queue

    The queue on which the completion handler is dispatched. Defaults to .main.

    completionHandler

    The code to be executed once the request has finished.

    Return Value

    The request.

  • Adds a handler to be called once the request has finished.

    Declaration

    Swift

    @discardableResult
    public func responseString(
        queue: DispatchQueue = .main,
        encoding: String.Encoding? = nil,
        completionHandler: @escaping (DownloadResponse<String>) -> Void)
        -> Self

    Parameters

    queue

    The queue on which the completion handler is dispatched. Defaults to .main.

    encoding

    The string encoding. Defaults to nil, in which case the encoding will be determined from the server response, falling back to the default HTTP character set, ISO-8859-1.

    completionHandler

    A closure to be executed once the request has finished.

    Return Value

    The request.

  • Adds a handler to be called once the request has finished.

    Declaration

    Swift

    @discardableResult
    public func responseJSON(
        queue: DispatchQueue = .main,
        options: JSONSerialization.ReadingOptions = .allowFragments,
        completionHandler: @escaping (DownloadResponse<Any>) -> Void)
        -> Self

    Parameters

    queue

    The queue on which the completion handler is dispatched. Defaults to .main.

    options

    The JSON serialization reading options. Defaults to .allowFragments.

    completionHandler

    A closure to be executed once the request has finished.

    Return Value

    The request.

  • A closure used to validate a request that takes a URL request, a URL response, a temporary URL and a destination URL, and returns whether the request was valid.

    Declaration

    Swift

    public typealias Validation = (_ request: URLRequest?, _ response: HTTPURLResponse, _ fileURL: URL?) -> ValidationResult
  • Validates that the response has a status code in the specified sequence.

    If validation fails, subsequent calls to response handlers will have an associated error.

    Declaration

    Swift

    @discardableResult
    public func validate<S>(statusCode acceptableStatusCodes: S) -> Self where S : Sequence, S.Element == Int

    Parameters

    range

    The range of acceptable status codes.

    Return Value

    The request.

  • Validates that the response has a content type in the specified sequence.

    If validation fails, subsequent calls to response handlers will have an associated error.

    Declaration

    Swift

    @discardableResult
    public func validate<S: Sequence>(contentType acceptableContentTypes: @escaping @autoclosure () -> S) -> Self where S.Iterator.Element == String

    Parameters

    contentType

    The acceptable content types, which may specify wildcard types and/or subtypes.

    Return Value

    The request.

  • Validates that the response has a status code in the default acceptable range of 200…299, and that the content type matches any specified in the Accept HTTP header field.

    If validation fails, subsequent calls to response handlers will have an associated error.

    Declaration

    Swift

    @discardableResult
    public func validate() -> Self

    Return Value

    The request.