@@ -23,11 +23,11 @@ #import "MTXRequest.h" @implementation MTXRequest { OFData *_body; - mtx_request_block_t _block; + MTXRequestBlock _block; } + (instancetype)requestWithPath: (OFString *)path accessToken: (OFString *)accessToken homeserver: (OFURL *)homeserver @@ -45,11 +45,11 @@ @try { _accessToken = [accessToken copy]; _homeserver = [homeserver copy]; _path = [path copy]; - _method = OF_HTTP_REQUEST_METHOD_GET; + _method = OFHTTPRequestMethodGet; } @catch (id e) { [self release]; @throw e; } @@ -71,25 +71,23 @@ void *pool = objc_autoreleasePoolPush(); [_body release]; OFString *JSONString = [body JSONRepresentation]; - _body = [[OFData alloc] - initWithItems: JSONString.UTF8String - count: JSONString.UTF8StringLength]; + _body = [[OFData alloc] initWithItems: JSONString.UTF8String + count: JSONString.UTF8StringLength]; objc_autoreleasePoolPop(pool); } - (OFDictionary *)body { return [OFString stringWithUTF8String: _body.items - length: _body.count] - .objectByParsingJSON; + length: _body.count].objectByParsingJSON; } -- (void)performWithBlock: (mtx_request_block_t)block +- (void)performWithBlock: (MTXRequestBlock)block { void *pool = objc_autoreleasePoolPush(); if (_block != nil) /* Not the best exception to indicate it's already in-flight. */ @@ -129,11 +127,11 @@ if (response != nil && [exception isKindOfClass: [OFHTTPRequestFailedException class]]) exception = nil; /* Reset to nil first, so that another one can be performed. */ - mtx_request_block_t block = _block; + MTXRequestBlock block = _block; _block = nil; if (exception == nil) { @try { OFMutableData *responseData = [OFMutableData data]; @@ -140,15 +138,14 @@ while (!response.atEndOfStream) { char buffer[512]; size_t length = [response readIntoBuffer: buffer length: 512]; - [responseData addItems: buffer - count: length]; + [responseData addItems: buffer count: length]; } - mtx_response_t responseJSON = [OFString + MTXResponse responseJSON = [OFString stringWithUTF8String: responseData.items length: responseData.count] .objectByParsingJSON; block(responseJSON, response.statusCode, nil);