added comments for objc client

This commit is contained in:
geekerzp 2015-06-02 11:50:47 +08:00
parent b5429d9e8e
commit 86971ee752
4 changed files with 133 additions and 30 deletions

View File

@ -20,44 +20,104 @@ extern NSString *const SWGResponseObjectErrorKey;
@property(nonatomic, assign) BOOL logHTTP;
@property(nonatomic, readonly) NSOperationQueue* queue;
/**
* Get the Api Client instance from pool
*/
+(SWGApiClient *)sharedClientFromPool:(NSString *)baseUrl;
/**
* Get the operations queue
*/
+(NSOperationQueue*) sharedQueue;
/**
* Turn on logging
*/
+(void)setLoggingEnabled:(bool) state;
/**
* Clear Cache
*/
+(void)clearCache;
/**
* Turn on cache
*/
+(void)setCacheEnabled:(BOOL) enabled;
/**
* Get the request queue size
*/
+(unsigned long)requestQueueSize;
/**
* Set the client unreachable
*/
+(void) setOfflineState:(BOOL) state;
/**
* Get the client reachability
*/
+(AFNetworkReachabilityStatus) getReachabilityStatus;
/**
* Get the next request id
*/
+(NSNumber*) nextRequestId;
/**
* Generate request id and add it to the queue
*/
+(NSNumber*) queueRequest;
/**
* Remove request id from the queue
*/
+(void) cancelRequest:(NSNumber*)requestId;
/**
* URL encode NSString
*/
+(NSString*) escape:(id)unescaped;
/**
* Set the client reachability
*/
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
/**
* Set the client reachability strategy
*/
+(void) configureCacheReachibilityForHost:(NSString*)host;
/**
* Detect Accept header from accepts NSArray
*/
+(NSString *) selectHeaderAccept:(NSArray *)accepts;
/**
* Detect Content-Type header from contentTypes NSArray
*/
+(NSString *) selectHeaderContentType:(NSArray *)contentTypes;
/**
* Set header for request
*/
-(void)setHeaderValue:(NSString*) value
forKey:(NSString*) forKey;
/**
* Update header parameters and query parameters for authentication
*/
- (void) updateHeaderParams:(NSDictionary **)headers
queryParams:(NSDictionary **)querys
WithAuthSettings:(NSArray *)authSettings;
/**
* Perform request
*
* @discussion Request with non-empty response
*/
-(NSNumber*) dictionary:(NSString*) path
method:(NSString*) method
queryParams:(NSDictionary*) queryParams
@ -68,6 +128,11 @@ extern NSString *const SWGResponseObjectErrorKey;
responseContentType:(NSString*) responseContentType
completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock;
/**
* Perform request
*
* @discussion Request with empty response
*/
-(NSNumber*) stringWithCompletionBlock:(NSString*) path
method:(NSString*) method
queryParams:(NSDictionary*) queryParams
@ -78,13 +143,3 @@ extern NSString *const SWGResponseObjectErrorKey;
responseContentType:(NSString*) responseContentType
completionBlock:(void (^)(NSString*, NSError *))completionBlock;
@end

View File

@ -20,44 +20,104 @@ extern NSString *const SWGResponseObjectErrorKey;
@property(nonatomic, assign) BOOL logHTTP;
@property(nonatomic, readonly) NSOperationQueue* queue;
/**
* Get the Api Client instance from pool
*/
+(SWGApiClient *)sharedClientFromPool:(NSString *)baseUrl;
/**
* Get the operations queue
*/
+(NSOperationQueue*) sharedQueue;
/**
* Turn on logging
*/
+(void)setLoggingEnabled:(bool) state;
/**
* Clear Cache
*/
+(void)clearCache;
/**
* Turn on cache
*/
+(void)setCacheEnabled:(BOOL) enabled;
/**
* Get the request queue size
*/
+(unsigned long)requestQueueSize;
/**
* Set the client unreachable
*/
+(void) setOfflineState:(BOOL) state;
/**
* Get the client reachability
*/
+(AFNetworkReachabilityStatus) getReachabilityStatus;
/**
* Get the next request id
*/
+(NSNumber*) nextRequestId;
/**
* Generate request id and add it to the queue
*/
+(NSNumber*) queueRequest;
/**
* Remove request id from the queue
*/
+(void) cancelRequest:(NSNumber*)requestId;
/**
* URL encode NSString
*/
+(NSString*) escape:(id)unescaped;
/**
* Set the client reachability
*/
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
/**
* Set the client reachability strategy
*/
+(void) configureCacheReachibilityForHost:(NSString*)host;
/**
* Detect Accept header from accepts NSArray
*/
+(NSString *) selectHeaderAccept:(NSArray *)accepts;
/**
* Detect Content-Type header from contentTypes NSArray
*/
+(NSString *) selectHeaderContentType:(NSArray *)contentTypes;
/**
* Set header for request
*/
-(void)setHeaderValue:(NSString*) value
forKey:(NSString*) forKey;
/**
* Update header parameters and query parameters for authentication
*/
- (void) updateHeaderParams:(NSDictionary **)headers
queryParams:(NSDictionary **)querys
WithAuthSettings:(NSArray *)authSettings;
/**
* Perform request
*
* @discussion Request with non-empty response
*/
-(NSNumber*) dictionary:(NSString*) path
method:(NSString*) method
queryParams:(NSDictionary*) queryParams
@ -68,6 +128,11 @@ extern NSString *const SWGResponseObjectErrorKey;
responseContentType:(NSString*) responseContentType
completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock;
/**
* Perform request
*
* @discussion Request with empty response
*/
-(NSNumber*) stringWithCompletionBlock:(NSString*) path
method:(NSString*) method
queryParams:(NSDictionary*) queryParams
@ -78,13 +143,3 @@ extern NSString *const SWGResponseObjectErrorKey;
responseContentType:(NSString*) responseContentType
completionBlock:(void (^)(NSString*, NSError *))completionBlock;
@end

View File

@ -78,13 +78,6 @@
@"value": [self getApiKeyWithPrefix:@"api_key"]
},
@"basic_auth": @{
@"type": @"basic",
@"in": @"header",
@"key": @"Authorization",
@"value": [self getBasicAuthToken]
},
};
}

View File

@ -225,7 +225,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[@"application/json", @"application/xml"]];
// Authentication setting
NSArray *authSettings = @[@"basic_auth"];
NSArray *authSettings = @[@"petstore_auth"];
id bodyDictionary = nil;