/
TargetType.swift
66 lines (47 loc) · 1.46 KB
/
TargetType.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import Foundation
import Alamofire
/// The protocol used to define the specifications necessary for a `MoyaProvider`.
public protocol TargetType {
/// The target's base `URL`.
var baseURL: URL { get }
/// The path to be appended to `baseURL` to form the full `URL`.
var path: String { get }
/// The HTTP method used in the request.
var method: Moya.Method { get }
/// The parameters to be encoded in the request.
var parameters: [String: Any]? { get }
/// The method used for parameter encoding.
var parameterEncoding: ParameterEncoding { get }
/// Provides stub data for use in testing.
var sampleData: Data { get }
/// The type of HTTP task to be performed.
var task: Task { get }
/// Whether or not to perform Alamofire validation. Defaults to `false`.
var validate: Bool { get }
}
public extension TargetType {
var validate: Bool {
return false
}
}
/// Represents a type of upload task.
public enum UploadType {
/// Upload a file.
case file(URL)
/// Upload "multipart/form-data"
case multipart([MultipartFormData])
}
/// Represents a type of download task.
public enum DownloadType {
/// Download a file to a destination.
case request(DownloadDestination)
}
/// Represents an HTTP task.
public enum Task {
/// A basic request task.
case request
/// An upload task.
case upload(UploadType)
/// A download task.
case download(DownloadType)
}