forked from woocommerce/woocommerce-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetwork.swift
More file actions
64 lines (56 loc) · 2.61 KB
/
Network.swift
File metadata and controls
64 lines (56 loc) · 2.61 KB
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
import Combine
import Foundation
import Alamofire
/// Constructs `multipart/form-data` for uploads within an HTTP or HTTPS body.
///
public protocol MultipartFormData {
/// Appends a file with file URL for a name to form data.
///
func append(_ fileURL: URL, withName name: String, fileName: String, mimeType: String)
/// Appends data for a name to form data.
///
func append(_ data: Data, withName name: String)
}
/// Defines all of the Network Operations we'll be performing. This allows us to swap the actual Wrapper in our
/// Unit Testing target, and inject mocked up responses.
///
public protocol Network {
/// Designated Initializer.
///
/// - Parameters:
/// - credentials: WordPress.com Credentials.
///
init(credentials: Credentials)
/// Executes the specified Network Request. Upon completion, the payload will be sent back to the caller as a Data instance.
///
/// - Parameters:
/// - request: Request that should be performed.
/// - completion: Closure to be executed upon completion.
///
func responseData(for request: URLRequestConvertible, completion: @escaping (Data?, Error?) -> Void)
/// Executes the specified Network Request. Upon completion, the payload will be sent back to
/// the caller as a Data instance.
///
/// - Parameters:
/// - request: Request that should be performed.
/// - completion: Closure to be executed upon completion.
///
func responseData(for request: URLRequestConvertible,
completion: @escaping (Swift.Result<Data, Error>) -> Void)
/// Executes the specified Network Request. Upon completion, the payload or error will be emitted to the publisher.
///
/// - Parameters:
/// - request: Request that should be performed.
///
/// - Returns: A publisher that emits the result of the given request.
func responseDataPublisher(for request: URLRequestConvertible) -> AnyPublisher<Swift.Result<Data, Error>, Never>
/// Executes the specified Network Request for file uploads. Upon completion, the payload will be sent back to the caller as a Data instance.
///
/// - Parameters:
/// - multipartFormData: Used for appending data for multipart form data uploads.
/// - request: Request that should be performed.
/// - completion: Closure to be executed upon completion.
func uploadMultipartFormData(multipartFormData: @escaping (MultipartFormData) -> Void,
to request: URLRequestConvertible,
completion: @escaping (Data?, Error?) -> Void)
}