Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 35850de

Browse files
committed
Define multi-part form POST method in WordPressComRESTAPIInterfacing
1 parent 9097eb9 commit 35850de

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

WordPressKit/WordPressComRESTAPIInterfacing.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@import Foundation;
22

3+
@class FilePart;
4+
35
@protocol WordPressComRESTAPIInterfacing
46

57
@property (strong, nonatomic, readonly) NSURL * _Nonnull baseURL;
@@ -14,4 +16,11 @@
1416
success:(void (^ _Nonnull)(id _Nonnull, NSHTTPURLResponse * _Nullable))success
1517
failure:(void (^ _Nonnull)(NSError * _Nonnull, NSHTTPURLResponse * _Nullable))failure;
1618

19+
- (NSProgress * _Nullable)multipartPOST:(NSString * _Nonnull)URLString
20+
parameters:(NSDictionary<NSString *, NSObject *> * _Nullable)parameters
21+
fileParts:(NSArray<FilePart *> * _Nonnull)fileParts
22+
requestEnqueued:(void (^ _Nonnull)(NSNumber * _Nonnull))requestEnqueue
23+
success:(void (^ _Nonnull)(id _Nonnull, NSHTTPURLResponse * _Nullable))success
24+
failure:(void (^ _Nonnull)(NSError * _Nonnull, NSHTTPURLResponse * _Nullable))failure;
25+
1726
@end

WordPressKit/WordPressComRestApi.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,11 @@ open class WordPressComRestApi: NSObject {
268268
- parameter success: callback to be called on successful request
269269
- parameter failure: callback to be called on failed request
270270

271-
- returns: a NSProgress object that can be used to track the progress of the upload and to cancel the upload. If the method
271+
- returns: a `Progerss` object that can be used to track the progress of the upload and to cancel the upload. If the method
272272
returns nil it's because something happened on the request serialization and the network request was not started, but the failure callback
273273
will be invoked with the error specificing the serialization issues.
274274
*/
275-
@objc @discardableResult open func multipartPOST(_ URLString: String,
275+
@discardableResult open func multipartPOST(_ URLString: String,
276276
parameters: [String: AnyObject]?,
277277
fileParts: [FilePart],
278278
requestEnqueued: RequestEnqueuedBlock? = nil,
@@ -605,7 +605,6 @@ extension WordPressAPIError<WordPressComRestApiEndpointError> {
605605
}
606606

607607
extension WordPressComRestApi: WordPressComRESTAPIInterfacing {
608-
609608
// A note on the naming: Even if defined as `GET` in Objective-C, then method gets converted to Swift as `get`.
610609
//
611610
// Also, there is no Objective-C direct equivalent of `AnyObject`, which here is used in `parameters: [String: AnyObject]?`.
@@ -629,4 +628,22 @@ extension WordPressComRestApi: WordPressComRESTAPIInterfacing {
629628
) -> Progress? {
630629
POST(URLString, parameters: parameters, success: success, failure: failure)
631630
}
631+
632+
public func multipartPOST(
633+
_ URLString: String,
634+
parameters: [String: NSObject]?,
635+
fileParts: [FilePart],
636+
requestEnqueued: @escaping (NSNumber) -> Void,
637+
success: @escaping (Any, HTTPURLResponse?) -> Void,
638+
failure: @escaping (any Error, HTTPURLResponse?) -> Void
639+
) -> Progress? {
640+
multipartPOST(
641+
URLString,
642+
parameters: parameters,
643+
fileParts: fileParts,
644+
requestEnqueued: requestEnqueued,
645+
success: success as SuccessResponseBlock,
646+
failure: failure as FailureReponseBlock
647+
)
648+
}
632649
}

0 commit comments

Comments
 (0)