re-built sample objc-petstore

This commit is contained in:
Matthew Davis 2015-09-03 12:31:30 -07:00
parent 2822e9ea38
commit f067b86fa0
9 changed files with 58 additions and 6 deletions

View File

@ -12,6 +12,10 @@ To install it, put the API client library in your project and then simply add th
pod "SwaggerClient", :path => "/path/to/lib"
```
## Recommendation
It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issue.
## Author
apiteam@swagger.io

View File

@ -35,6 +35,9 @@ extern NSString *const SWGResponseObjectErrorKey;
@property(nonatomic, assign) NSTimeInterval timeoutInterval;
@property(nonatomic, readonly) NSOperationQueue* queue;
/// In order to ensure the HTTPResponseHeaders are correct, it is recommended to initialize one SWGApiClient instance per thread.
@property(nonatomic, readonly) NSDictionary* HTTPResponseHeaders;
/**
* Clears Cache
*/

View File

@ -9,6 +9,13 @@ static bool cacheEnabled = false;
static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable;
static void (^reachabilityChangeBlock)(int);
@interface SWGApiClient ()
@property (readwrite, nonatomic) NSDictionary *HTTPResponseHeaders;
@end
@implementation SWGApiClient
- (instancetype)init {
@ -385,6 +392,8 @@ static void (^reachabilityChangeBlock)(int);
if([[SWGConfiguration sharedConfig] debug]) {
[self logResponse:operation forRequest:request error:nil];
}
NSDictionary *responseHeaders = [[operation response] allHeaderFields];
self.HTTPResponseHeaders = responseHeaders;
completionBlock(response, nil);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
@ -398,6 +407,10 @@ static void (^reachabilityChangeBlock)(int);
if([[SWGConfiguration sharedConfig] debug])
[self logResponse:nil forRequest:request error:augmentedError];
NSDictionary *responseHeaders = [[operation response] allHeaderFields];
self.HTTPResponseHeaders = responseHeaders;
completionBlock(nil, augmentedError);
}
}];
@ -441,6 +454,7 @@ static void (^reachabilityChangeBlock)(int);
NSURL *file = [NSURL fileURLWithPath:filepath];
[operation.responseData writeToURL:file atomically:YES];
self.HTTPResponseHeaders = headers;
completionBlock(file, nil);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
@ -455,7 +469,8 @@ static void (^reachabilityChangeBlock)(int);
if ([[SWGConfiguration sharedConfig] debug]) {
[self logResponse:nil forRequest:request error:augmentedError];
}
NSDictionary *responseHeaders = [[operation response] allHeaderFields];
self.HTTPResponseHeaders = responseHeaders;
completionBlock(nil, augmentedError);
}
}];

View File

@ -18,6 +18,7 @@
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
-(unsigned long) requestQueueSize;
+(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
+(SWGPetApi*) sharedAPI;
///
///
/// Update an existing pet

View File

@ -9,6 +9,8 @@
@implementation SWGPetApi
static SWGPetApi* singletonAPI = nil;
#pragma mark - Initialize methods
- (id) init {
@ -36,7 +38,6 @@
#pragma mark -
+(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
static SWGPetApi* singletonAPI = nil;
if (singletonAPI == nil) {
singletonAPI = [[SWGPetApi alloc] init];
@ -45,6 +46,14 @@
return singletonAPI;
}
+(SWGPetApi*) sharedAPI {
if (singletonAPI == nil) {
singletonAPI = [[SWGPetApi alloc] init];
}
return singletonAPI;
}
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
[self.defaultHeaders setValue:value forKey:key];
}

View File

@ -18,6 +18,7 @@
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
-(unsigned long) requestQueueSize;
+(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
+(SWGStoreApi*) sharedAPI;
///
///
/// Returns pet inventories by status

View File

@ -9,6 +9,8 @@
@implementation SWGStoreApi
static SWGStoreApi* singletonAPI = nil;
#pragma mark - Initialize methods
- (id) init {
@ -36,7 +38,6 @@
#pragma mark -
+(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
static SWGStoreApi* singletonAPI = nil;
if (singletonAPI == nil) {
singletonAPI = [[SWGStoreApi alloc] init];
@ -45,6 +46,14 @@
return singletonAPI;
}
+(SWGStoreApi*) sharedAPI {
if (singletonAPI == nil) {
singletonAPI = [[SWGStoreApi alloc] init];
}
return singletonAPI;
}
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
[self.defaultHeaders setValue:value forKey:key];
}

View File

@ -18,6 +18,7 @@
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
-(unsigned long) requestQueueSize;
+(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
+(SWGUserApi*) sharedAPI;
///
///
/// Create user
@ -98,7 +99,7 @@
/// Get user by user name
///
///
/// @param username The name that needs to be fetched. Use user1 for testing.
/// @param username The name that needs to be fetched. Use user1 for testing.
///
///
/// @return SWGUser*

View File

@ -9,6 +9,8 @@
@implementation SWGUserApi
static SWGUserApi* singletonAPI = nil;
#pragma mark - Initialize methods
- (id) init {
@ -36,7 +38,6 @@
#pragma mark -
+(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
static SWGUserApi* singletonAPI = nil;
if (singletonAPI == nil) {
singletonAPI = [[SWGUserApi alloc] init];
@ -45,6 +46,14 @@
return singletonAPI;
}
+(SWGUserApi*) sharedAPI {
if (singletonAPI == nil) {
singletonAPI = [[SWGUserApi alloc] init];
}
return singletonAPI;
}
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
[self.defaultHeaders setValue:value forKey:key];
}
@ -461,7 +470,7 @@
///
/// Get user by user name
///
/// @param username The name that needs to be fetched. Use user1 for testing.
/// @param username The name that needs to be fetched. Use user1 for testing.
///
/// @returns SWGUser*
///