Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted by registered user namnguyen ( 13 years ago )
+ (XMAPIPostRequest*)object:(id)object
requestWithApiCLient:(XMAPIClient*)apiClient
path:(NSString *)path
authRequired:(BOOL)authRequired
cachingAllowed:(BOOL)cachingAllowed
headers:(NSDictionary *)headers
uploadProgress:(void (^)(int progress))uploadProgress
downloadProgress:(void (^)(int progress))downloadProgress
asyncJSONFromObject:(NSDictionary* (^)(NSOperation *operation, NSError** error))asyncJSONFromObject
asyncUpdateFromData:(bool (^)(id JSON, NSDictionary *responseHeaders, NSOperation *operation, NSError** error))asyncUpdateFromData
success:(void (^)(id object))success
notModified:(void (^)(void))notModified
notFound:(void (^)(void))notFound
notAuthorized:(void (^)(void))notAuthorized
forbidden:(void (^)(void))forbidden
noInternet:(void (^)(void))noInternet
notAvailable:(void (^)(void))notAvailable
internalServerError:(void (^)(void))internalServerError
otherFailure:(void (^)(NSError *error))otherFailure {
XMAPIPostRequest *req = [[XMAPIPostRequest alloc] init];
__block NSDictionary *JSON = nil;
__block NSError *error = nil;
req.parsingOperation = [[NSBlockOperation alloc] init];
__weak NSBlockOperation *weakParsingOperation = req.parsingOperation;
__weak XMAPIClient *weakApiClient = apiClient;
[req.parsingOperation addExecutionBlock:^{
if(asyncJSONFromObject)
JSON = asyncJSONFromObject(weakParsingOperation, &error;);
req.currentOperation = req.afOperation = [weakApiClient postPath:path authRequired:authRequired cachingAllowed:cachingAllowed headers:headers parameters:JSON uploadProgress:uploadProgress downloadProgress:downloadProgress asyncSuccess:^(NSHTTPURLResponse *response, id JSON) {
// async success
req.parsingOperation = [[NSBlockOperation alloc] init];
__weak NSBlockOperation *weakParsingOperation = req.parsingOperation;
[req.parsingOperation addExecutionBlock:^ {
NSError *error = nil;
bool updateSuccess = YES;
if(asyncUpdateFromData)
updateSuccess = asyncUpdateFromData(JSON, response.allHeaderFields, weakParsingOperation, &error;);
if(updateSuccess) {
dispatch_async(dispatch_get_main_queue(), ^{
success(object);
});
return;
}
}];
NSOperationQueue *queue = [NSOperationQueue currentQueue];
[queue addOperation:req.parsingOperation];
req.currentOperation = req.parsingOperation;
[req.currentOperation start];
} notModified:^{
// not modified
if(notModified)
notModified();
} notFound:^{
// not found
if(notFound)
notFound();
} notAuthorized:^{
// not authorized
if(notAuthorized)
notAuthorized();
} forbidden:^{
// forbidden
if(forbidden)
forbidden();
} noInternet:^{
// no internet
if(noInternet)
noInternet();
} notAvailable:^{
// not available
if(notAvailable)
notAvailable();
} internalError:^{
// internal Server error
if(internalServerError)
internalServerError();
} otherFailure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
// other failure
if(otherFailure) {
otherFailure(error);
}
}];
}];
[apiClient.operationQueue addOperation:req.parsingOperation];
return req;
}
Revise this Paste