宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
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
import Foundation
 
/// A `TargetType` used to enable `MoyaProvider` to process multiple `TargetType`s.
public enum MultiTarget: TargetType {
    /// The embedded `TargetType`.
    case target(TargetType)
 
    /// Initializes a `MultiTarget`.
    public init(_ target: TargetType) {
        self = MultiTarget.target(target)
    }
 
    /// The embedded target's base `URL`.
    public var path: String {
        return target.path
    }
 
    /// The baseURL of the embedded target.
    public var baseURL: URL {
        return target.baseURL
    }
 
    /// The HTTP method of the embedded target.
    public var method: Moya.Method {
        return target.method
    }
 
    /// The sampleData of the embedded target.
    public var sampleData: Data {
        return target.sampleData
    }
 
    /// The `Task` of the embedded target.
    public var task: Task {
        return target.task
    }
 
    /// The `ValidationType` of the embedded target.
    public var validationType: ValidationType {
        return target.validationType
    }
 
    /// The headers of the embedded target.
    public var headers: [String: String]? {
        return target.headers
    }
 
    /// The embedded `TargetType`.
    public var target: TargetType {
        switch self {
        case .target(let target): return target
        }
    }
}
 
extension MultiTarget: AccessTokenAuthorizable {
    public var authorizationType: AuthorizationType? {
        guard let authorizableTarget = target as? AccessTokenAuthorizable else { return nil }
        return authorizableTarget.authorizationType
    }
}