-
Notifications
You must be signed in to change notification settings - Fork 2
/
APIRequestInfo.swift
70 lines (57 loc) · 1.73 KB
/
APIRequestInfo.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
67
68
69
70
//
// APIRequestInfo.swift
// RaAPIWrapper
//
// Created by Rakuyo on 2022/8/25.
// Copyright © 2024 RakuyoKit. All rights reserved.
//
import Foundation
// MARK: - APIRequestInfo
/// Information needed to request the api
public struct APIRequestInfo {
/// The path to the requested api
public let path: String
/// A special api base url.
///
/// Should be a setting item independent of your global configuration.
public let specialBaseURL: URL?
/// Type representing HTTP methods
public let httpMethod: APIHTTPMethod
/// API header
public let header: APIHeaders?
/// Parameters of the requested api
public let parameters: AnyAPIParameter?
/// An additional storage space.
/// You can use this property to store some custom data.
public let userInfo: APIRequestUserInfo
public init<ParamType>(
path: String,
specialBaseURL: URL? = nil,
httpMethod: APIHTTPMethod,
header: APIHeaders? = nil,
parameterBuild: APIParameterBuilder<ParamType>? = nil,
parameterInput: ParamType? = nil,
userInfo: APIRequestUserInfo = [:]
) {
self.path = path
self.specialBaseURL = specialBaseURL
self.httpMethod = httpMethod
self.header = header
self.userInfo = userInfo
parameters = {
guard
let parameter = parameterInput,
let build = parameterBuild
else {
return nil
}
let result = build(parameter)
if let value = result as? AnyAPIParameter {
return value
}
return .init(result)
}()
}
}
// MARK: Hashable
extension APIRequestInfo: Hashable { }