-
Notifications
You must be signed in to change notification settings - Fork 0
/
AFXMLRPCClient.h
224 lines (168 loc) · 10 KB
/
AFXMLRPCClient.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//
// AFXMLRPCClient.h
// WordPressApiExample
//
// Created by Jorge Bernal on 12/13/11.
// Copyright (c) 2011 Automattic. All rights reserved.
//
#import <Foundation/Foundation.h>
@class AFHTTPRequestOperation;
typedef void (^AFXMLRPCRequestOperationSuccessBlock)(AFHTTPRequestOperation *operation, id responseObject);
typedef void (^AFXMLRPCRequestOperationFailureBlock)(AFHTTPRequestOperation *operation, NSError *error);
@interface AFXMLRPCRequest : NSObject
@property (nonatomic, retain) NSString *method;
@property (nonatomic, retain) NSArray *parameters;
@end
@interface AFXMLRPCRequestOperation : AFHTTPRequestOperation
@property (nonatomic, retain) AFXMLRPCRequest *XMLRPCRequest;
@property (nonatomic, copy) AFXMLRPCRequestOperationSuccessBlock success;
@property (nonatomic, copy) AFXMLRPCRequestOperationFailureBlock failure;
@end
/**
`AFXMLRPCClient` binds together AFNetworking and eczarny's XML-RPC library to interact with XML-RPC based APIs
*/
@interface AFXMLRPCClient : NSObject
///---------------------------------------
/// @name Accessing HTTP Client Properties
///---------------------------------------
/**
The url used as the XML-RPC endpoint
*/
@property (readonly, nonatomic, retain) NSURL *xmlrpcEndpoint;
/**
The operation queue which manages operations enqueued by the HTTP client.
*/
@property (readonly, nonatomic, retain) NSOperationQueue *operationQueue;
///------------------------------------------------
/// @name Creating and Initializing XML-RPC Clients
///------------------------------------------------
/**
Creates and initializes an `AFXMLRPCClient` object with the specified base URL.
@param xmlrpcEndpoint The XML-RPC endpoint URL for the XML-RPC client. This argument must not be nil.
@return The newly-initialized XML-RPC client
*/
+ (AFXMLRPCClient *)clientWithXMLRPCEndpoint:(NSURL *)xmlrpcEndpoint;
/**
Initializes an `AFXMLRPCClient` object with the specified base URL.
@param xmlrpcEndpoint The XML-RPC endpoint URL for the XML-RPC client. This argument must not be nil.
@return The newly-initialized XML-RPC client
*/
- (id)initWithXMLRPCEndpoint:(NSURL *)xmlrpcEndpoint;
///----------------------------------
/// @name Managing HTTP Header Values
///----------------------------------
/**
Returns the value for the HTTP headers set in request objects created by the HTTP client.
@param header The HTTP header to return the default value for
@return The default value for the HTTP header, or `nil` if unspecified
*/
- (NSString *)defaultValueForHeader:(NSString *)header;
/**
Sets the value for the HTTP headers set in request objects made by the HTTP client. If `nil`, removes the existing value for that header.
@param header The HTTP header to set a default value for
@param value The value set as default for the specified header, or `nil
*/
- (void)setDefaultHeader:(NSString *)header value:(NSString *)value;
/**
Sets the "Authorization" HTTP header set in request objects made by the HTTP client to a basic authentication value with Base64-encoded username and password. This overwrites any existing value for this header.
@param username The HTTP basic auth username
@param password The HTTP basic auth password
*/
- (void)setAuthorizationHeaderWithUsername:(NSString *)username password:(NSString *)password;
/**
Sets the "Authorization" HTTP header set in request objects made by the HTTP client to a token-based authentication value, such as an OAuth access token. This overwrites any existing value for this header.
@param token The authentication token
*/
- (void)setAuthorizationHeaderWithToken:(NSString *)token;
/**
Clears any existing value for the "Authorization" HTTP header.
*/
- (void)clearAuthorizationHeader;
///-------------------------------
/// @name Creating Request Objects
///-------------------------------
/**
Creates a `NSMutableURLRequest` object with the specified XML-RPC method and parameters.
@param method The XML-RPC method for the request.
@param parameters The XML-RPC parameters to be set as the request body.
@return A `NSMutableURLRequest` object
*/
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
parameters:(NSArray *)parameters;
/**
Creates a `NSMutableURLRequest` object with the specified XML-RPC method and parameters, but uses streaming to encode and send the XML-RPC request.
@param method The XML-RPC method for the request.
@param parameters The XML-RPC parameters to be set as the request body.
@return A `NSMutableURLRequest` object
*/
- (NSMutableURLRequest *)streamingRequestWithMethod:(NSString *)method
parameters:(NSArray *)parameters;
/**
Creates an `AFXMLRPCRequest` object with the specified XML-RPC method and parameters.
@param method The XML-RPC method for the request.
@param parameters The XML-RPC parameters to be set as the request body.
@return An `AFXMLRPCRequest` object
*/
- (AFXMLRPCRequest *)XMLRPCRequestWithMethod:(NSString *)method
parameters:(NSArray *)parameters;
///-------------------------------
/// @name Creating HTTP Operations
///-------------------------------
/**
Creates an `AFHTTPRequestOperation`
@param request The request object to be loaded asynchronously during execution of the operation.
@param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
@param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred.
*/
- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request
success:(AFXMLRPCRequestOperationSuccessBlock)success
failure:(AFXMLRPCRequestOperationFailureBlock)failure;
/**
Creates an `AFXMLRPCRequestOperation`
@param request The request object to be loaded asynchronously during execution of the operation.
@param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
@param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred.
*/
- (AFXMLRPCRequestOperation *)XMLRPCRequestOperationWithRequest:(AFXMLRPCRequest *)request
success:(AFXMLRPCRequestOperationSuccessBlock)success
failure:(AFXMLRPCRequestOperationFailureBlock)failure;
/**
Creates an `AFHTTPRequestOperation` combining multiple XML-RPC calls in a single request using `system.multicall`
@param operations An array of `AFXMLRPCRequestOperation` objects
@param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
@param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred.
*/
- (AFHTTPRequestOperation *)combinedHTTPRequestOperationWithOperations:(NSArray *)operations success:(AFXMLRPCRequestOperationSuccessBlock)success failure:(AFXMLRPCRequestOperationFailureBlock)failure;
///----------------------------------------
/// @name Managing Enqueued HTTP Operations
///----------------------------------------
/**
Enqueues an `AFHTTPRequestOperation` to the XML-RPC client's operation queue.
@param operation The XML-RPC request operation to be enqueued.
*/
- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation;
/**
Enqueues an `AFXMLRPCRequestOperation` to the XML-RPC client's operation queue.
@param operation The XML-RPC request operation to be enqueued.
*/
- (void)enqueueXMLRPCRequestOperation:(AFXMLRPCRequestOperation *)operation;
/**
Cancels all operations in the HTTP client's operation queue.
*/
- (void)cancelAllHTTPOperations;
///------------------------------
/// @name Making XML-RPC requests
///------------------------------
/**
Creates an `AFHTTPRequestOperation` with a `XML-RPC` request, and enqueues it to the HTTP client's operation queue.
@param method The XML-RPC method.
@param parameters The XML-RPC parameters to be set as the request body.
@param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
@param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred.
@see HTTPRequestOperationWithRequest:success:failure
*/
- (void)callMethod:(NSString *)method
parameters:(NSArray *)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
@end