diff --git a/samples/client/petstore/objc/NIKCategory.h b/samples/client/petstore/objc/NIKCategory.h new file mode 100644 index 00000000000..7c66bd1aced --- /dev/null +++ b/samples/client/petstore/objc/NIKCategory.h @@ -0,0 +1,25 @@ +#import +#import "NIKSwaggerObject.h" + +@interface NIKCategory : NIKSwaggerObject { +@private + NSDictionary* raw; + NSNumber* __id; //NSNumber + NSString* _name; //NSString + } + +@property(nonatomic) NSDictionary* raw; + + +@property(nonatomic) NSNumber* _id; +@property(nonatomic) NSString* name; +- (id) _id: (NSNumber*) _id + name: (NSString*) name; + +- (id) initWithValues: (NSDictionary*)dict; +- (NSDictionary*) asDictionary; +- (NSDictionary*) asRaw; + + +@end + diff --git a/samples/client/petstore/objc/NIKCategory.m b/samples/client/petstore/objc/NIKCategory.m new file mode 100644 index 00000000000..b0ca3f239a9 --- /dev/null +++ b/samples/client/petstore/objc/NIKCategory.m @@ -0,0 +1,38 @@ +#import "NIKDate.h" +#import "NIKCategory.h" + +@implementation NIKCategory + +@synthesize raw = _raw; + +@synthesize _id = __id; +@synthesize name = _name; +- (id) _id: (NSNumber*) _id + name: (NSString*) name + { + __id = _id; + _name = name; + return self; + } + +- (id) initWithValues: (NSDictionary*)dict +{ + __id = [dict objectForKey:@"id"]; + _name = [dict objectForKey:@"name"]; + self.raw = [[NSDictionary alloc] initWithDictionary:dict]; + return self; +} + +-(NSDictionary*) asDictionary { + NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; + if(__id != nil) [dict setObject:__id forKey:@"id"]; + if(_name != nil) [dict setObject:_name forKey:@"name"]; + NSDictionary* output = [dict copy]; + return output; +} + +-(NSDictionary*) asRaw { + return _raw; +} +@end + diff --git a/samples/client/petstore/objc/NIKOrder.h b/samples/client/petstore/objc/NIKOrder.h new file mode 100644 index 00000000000..d3f9d23fcce --- /dev/null +++ b/samples/client/petstore/objc/NIKOrder.h @@ -0,0 +1,35 @@ +#import +#import "NIKSwaggerObject.h" +#import "NIKDate.h" + +@interface NIKOrder : NIKSwaggerObject { +@private + NSDictionary* raw; + NSNumber* __id; //NSNumber + NSNumber* _petId; //NSNumber + NSString* _status; //NSString + NSNumber* _quantity; //NSNumber + NIKDate* _shipDate; //NIKDate + } + +@property(nonatomic) NSDictionary* raw; + + +@property(nonatomic) NSNumber* _id; +@property(nonatomic) NSNumber* petId; +@property(nonatomic) NSString* status; +@property(nonatomic) NSNumber* quantity; +@property(nonatomic) NIKDate* shipDate; +- (id) _id: (NSNumber*) _id + petId: (NSNumber*) petId + status: (NSString*) status + quantity: (NSNumber*) quantity + shipDate: (NIKDate*) shipDate; + +- (id) initWithValues: (NSDictionary*)dict; +- (NSDictionary*) asDictionary; +- (NSDictionary*) asRaw; + + +@end + diff --git a/samples/client/petstore/objc/NIKOrder.m b/samples/client/petstore/objc/NIKOrder.m new file mode 100644 index 00000000000..be0ff590c50 --- /dev/null +++ b/samples/client/petstore/objc/NIKOrder.m @@ -0,0 +1,71 @@ +#import "NIKDate.h" +#import "NIKOrder.h" + +@implementation NIKOrder + +@synthesize raw = _raw; + +@synthesize _id = __id; +@synthesize petId = _petId; +@synthesize status = _status; +@synthesize quantity = _quantity; +@synthesize shipDate = _shipDate; +- (id) _id: (NSNumber*) _id + petId: (NSNumber*) petId + status: (NSString*) status + quantity: (NSNumber*) quantity + shipDate: (NIKDate*) shipDate + { + __id = _id; + _petId = petId; + _status = status; + _quantity = quantity; + _shipDate = shipDate; + return self; + } + +- (id) initWithValues: (NSDictionary*)dict +{ + __id = [dict objectForKey:@"id"]; + _petId = [dict objectForKey:@"petId"]; + _status = [dict objectForKey:@"status"]; + _quantity = [dict objectForKey:@"quantity"]; + id shipDate_dict = [dict objectForKey:@"shipDate"]; + _shipDate = [[NIKDate alloc]initWithValues:shipDate_dict]; + self.raw = [[NSDictionary alloc] initWithDictionary:dict]; + return self; +} + +-(NSDictionary*) asDictionary { + NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; + if(__id != nil) [dict setObject:__id forKey:@"id"]; + if(_petId != nil) [dict setObject:_petId forKey:@"petId"]; + if(_status != nil) [dict setObject:_status forKey:@"status"]; + if(_quantity != nil) [dict setObject:_quantity forKey:@"quantity"]; + if(_shipDate != nil){ + if([_shipDate isKindOfClass:[NSArray class]]){ + NSMutableArray * array = [[NSMutableArray alloc] init]; + for( NIKDate * shipDate in (NSArray*)_shipDate) { + [array addObject:[(NIKSwaggerObject*)shipDate asDictionary]]; + } + [dict setObject:array forKey:@"shipDate"]; + } + else if(_shipDate && [_shipDate isKindOfClass:[NIKDate class]]) { + NSString * dateString = [(NIKDate*)_shipDate toString]; + if(dateString){ + [dict setObject:dateString forKey:@"shipDate"]; + } + } + } + else { + if(_shipDate != nil) [dict setObject:[(NIKSwaggerObject*)_shipDate asDictionary]forKey:@"shipDate"]; + } + NSDictionary* output = [dict copy]; + return output; +} + +-(NSDictionary*) asRaw { + return _raw; +} +@end + diff --git a/samples/client/petstore/objc/NIKPet.h b/samples/client/petstore/objc/NIKPet.h new file mode 100644 index 00000000000..6d1e649f06e --- /dev/null +++ b/samples/client/petstore/objc/NIKPet.h @@ -0,0 +1,39 @@ +#import +#import "NIKSwaggerObject.h" +#import "NIKCategory.h" +#import "NIKTag.h" + +@interface NIKPet : NIKSwaggerObject { +@private + NSDictionary* raw; + NSNumber* __id; //NSNumber + NSArray* _tags; //Tag + NIKCategory* _category; //Category + NSString* _status; //NSString + NSString* _name; //NSString + NSArray* _photoUrls; //NSString + } + +@property(nonatomic) NSDictionary* raw; + + +@property(nonatomic) NSNumber* _id; +@property(nonatomic) NSArray* tags; +@property(nonatomic) NIKCategory* category; +@property(nonatomic) NSString* status; +@property(nonatomic) NSString* name; +@property(nonatomic) NSArray* photoUrls; +- (id) _id: (NSNumber*) _id + tags: (NSArray*) tags + category: (NIKCategory*) category + status: (NSString*) status + name: (NSString*) name + photoUrls: (NSArray*) photoUrls; + +- (id) initWithValues: (NSDictionary*)dict; +- (NSDictionary*) asDictionary; +- (NSDictionary*) asRaw; + + +@end + diff --git a/samples/client/petstore/objc/NIKPet.m b/samples/client/petstore/objc/NIKPet.m new file mode 100644 index 00000000000..7804df79132 --- /dev/null +++ b/samples/client/petstore/objc/NIKPet.m @@ -0,0 +1,106 @@ +#import "NIKDate.h" +#import "NIKPet.h" + +@implementation NIKPet + +@synthesize raw = _raw; + +@synthesize _id = __id; +@synthesize tags = _tags; +@synthesize category = _category; +@synthesize status = _status; +@synthesize name = _name; +@synthesize photoUrls = _photoUrls; +- (id) _id: (NSNumber*) _id + tags: (NSArray*) tags + category: (NIKCategory*) category + status: (NSString*) status + name: (NSString*) name + photoUrls: (NSArray*) photoUrls + { + __id = _id; + _tags = tags; + _category = category; + _status = status; + _name = name; + _photoUrls = photoUrls; + return self; + } + +- (id) initWithValues: (NSDictionary*)dict +{ + __id = [dict objectForKey:@"id"]; + id tags_dict = [dict objectForKey:@"tags"]; + if([tags_dict isKindOfClass:[NSArray class]]) { + if([(NSArray*)tags_dict count] > 0) { + NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*)tags_dict count]]; + for (NSDictionary* dict in (NSArray*)tags_dict) { + NIKTag* d = [[NIKTag alloc]initWithValues:dict]; + [objs addObject:d]; + } + _tags = [[NSArray alloc] initWithArray:objs]; + } + } + else if([tags_dict isKindOfClass:[NSDictionary class]] && [(NSDictionary*)tags_dict count] > 0) { + _tags = [[NIKTag alloc]initWithValues:(NSDictionary*)tags_dict]; + } + id category_dict = [dict objectForKey:@"category"]; + _category = [[NIKCategory alloc]initWithValues:category_dict]; + _status = [dict objectForKey:@"status"]; + _name = [dict objectForKey:@"name"]; + _photoUrls = [dict objectForKey:@"photoUrls"]; + self.raw = [[NSDictionary alloc] initWithDictionary:dict]; + return self; +} + +-(NSDictionary*) asDictionary { + NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; + if(__id != nil) [dict setObject:__id forKey:@"id"]; + if(_tags != nil){ + if([_tags isKindOfClass:[NSArray class]]){ + NSMutableArray * array = [[NSMutableArray alloc] init]; + for( NIKTag * tags in (NSArray*)_tags) { + [array addObject:[(NIKSwaggerObject*)tags asDictionary]]; + } + [dict setObject:array forKey:@"tags"]; + } + else if(_tags && [_tags isKindOfClass:[NIKDate class]]) { + NSString * dateString = [(NIKDate*)_tags toString]; + if(dateString){ + [dict setObject:dateString forKey:@"tags"]; + } + } + } + else { + if(_tags != nil) [dict setObject:[(NIKSwaggerObject*)_tags asDictionary]forKey:@"tags"]; + } + if(_category != nil){ + if([_category isKindOfClass:[NSArray class]]){ + NSMutableArray * array = [[NSMutableArray alloc] init]; + for( NIKCategory * category in (NSArray*)_category) { + [array addObject:[(NIKSwaggerObject*)category asDictionary]]; + } + [dict setObject:array forKey:@"category"]; + } + else if(_category && [_category isKindOfClass:[NIKDate class]]) { + NSString * dateString = [(NIKDate*)_category toString]; + if(dateString){ + [dict setObject:dateString forKey:@"category"]; + } + } + } + else { + if(_category != nil) [dict setObject:[(NIKSwaggerObject*)_category asDictionary]forKey:@"category"]; + } + if(_status != nil) [dict setObject:_status forKey:@"status"]; + if(_name != nil) [dict setObject:_name forKey:@"name"]; + if(_photoUrls != nil) [dict setObject:_photoUrls forKey:@"photoUrls"]; + NSDictionary* output = [dict copy]; + return output; +} + +-(NSDictionary*) asRaw { + return _raw; +} +@end + diff --git a/samples/client/petstore/objc/NIKPetApi.h b/samples/client/petstore/objc/NIKPetApi.h new file mode 100644 index 00000000000..181f457e134 --- /dev/null +++ b/samples/client/petstore/objc/NIKPetApi.h @@ -0,0 +1,28 @@ +#import +#import "NIKApiInvoker.h" +#import "NIKPet.h" + + +@interface NIKPetApi: NSObject { + +@private + NSOperationQueue *_queue; + NIKApiInvoker * _api; +} +@property(nonatomic, readonly) NSOperationQueue* queue; +@property(nonatomic, readonly) NIKApiInvoker* api; + +-(void) addHeader:(NSString*) value + forKey:(NSString*)key; + +-(void) getPetByIdWithCompletionBlock :(NSString*) petId + completionHandler:(void (^)(NIKPet*, NSError *))completionBlock; +-(void) addPetWithCompletionBlock :(NIKPet*) body + completionHandler:(void (^)(NSError *))completionBlock; +-(void) updatePetWithCompletionBlock :(NIKPet*) body + completionHandler:(void (^)(NSError *))completionBlock; +-(void) findPetsByStatusWithCompletionBlock :(NSString*) status + completionHandler:(void (^)(NSArray*, NSError *))completionBlock; +-(void) findPetsByTagsWithCompletionBlock :(NSString*) tags + completionHandler:(void (^)(NSArray*, NSError *))completionBlock; +@end diff --git a/samples/client/petstore/objc/NIKPetApi.m b/samples/client/petstore/objc/NIKPetApi.m new file mode 100644 index 00000000000..0cf4a4a6d99 --- /dev/null +++ b/samples/client/petstore/objc/NIKPetApi.m @@ -0,0 +1,473 @@ +#import "NIKPetApi.h" +#import "NIKPet.h" + + + +@implementation NIKPetApi +static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; + +@synthesize queue = _queue; +@synthesize api = _api; + +- (id) init { + self = [super init]; + _queue = [[NSOperationQueue alloc] init]; + _api = [[NIKApiInvoker alloc] init]; + + return self; +} + +-(void) addHeader:(NSString*) value + forKey:(NSString*)key { + [_api addHeader:value forKey:key]; +} + +-(void) getPetByIdWithCompletionBlock :(NSString*) petId + completionHandler:(void (^)(NIKPet*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/{petId}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [_api escapeString:petId]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(petId == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + completionBlock( [[NIKPet alloc]initWithValues: data], nil); + }]; + +} + +-(void) addPetWithCompletionBlock :(NIKPet*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) updatePetWithCompletionBlock :(NIKPet*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"PUT" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) findPetsByStatusWithCompletionBlock :(NSString*) status + completionHandler:(void (^)(NSArray*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/findByStatus", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + if(status != nil) + [queryParams setValue:status forKey:@"status"]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(status == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + if([data isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]]; + for (NSDictionary* dict in (NSArray*)data) { + NIKPet* d = [[NIKPet alloc]initWithValues: dict]; + [objs addObject:d]; + } + completionBlock(objs, nil); + } + + }]; + +} + +-(void) findPetsByTagsWithCompletionBlock :(NSString*) tags + completionHandler:(void (^)(NSArray*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/findByTags", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + if(tags != nil) + [queryParams setValue:tags forKey:@"tags"]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(tags == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + if([data isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]]; + for (NSDictionary* dict in (NSArray*)data) { + NIKPet* d = [[NIKPet alloc]initWithValues: dict]; + [objs addObject:d]; + } + completionBlock(objs, nil); + } + + }]; + +} + +-(void) getPetByIdAsJsonWithCompletionBlock :(NSString*) petId + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/{petId}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [_api escapeString:petId]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(petId == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + NSData * responseData = nil; + if([data isKindOfClass:[NSDictionary class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + else if ([data isKindOfClass:[NSArray class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; + completionBlock(json, nil); + + }]; + +} + +-(void) addPetAsJsonWithCompletionBlock :(NIKPet*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) updatePetAsJsonWithCompletionBlock :(NIKPet*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"PUT" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) findPetsByStatusAsJsonWithCompletionBlock :(NSString*) status + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/findByStatus", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + if(status != nil) + [queryParams setValue:status forKey:@"status"]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(status == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + NSData * responseData = nil; + if([data isKindOfClass:[NSDictionary class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + else if ([data isKindOfClass:[NSArray class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; + completionBlock(json, nil); + + }]; + +} + +-(void) findPetsByTagsAsJsonWithCompletionBlock :(NSString*) tags + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet.{format}/findByTags", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + if(tags != nil) + [queryParams setValue:tags forKey:@"tags"]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(tags == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + NSData * responseData = nil; + if([data isKindOfClass:[NSDictionary class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + else if ([data isKindOfClass:[NSArray class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; + completionBlock(json, nil); + + }]; + +} + + +@end diff --git a/samples/client/petstore/objc/NIKStoreApi.h b/samples/client/petstore/objc/NIKStoreApi.h new file mode 100644 index 00000000000..5454798e01e --- /dev/null +++ b/samples/client/petstore/objc/NIKStoreApi.h @@ -0,0 +1,24 @@ +#import +#import "NIKApiInvoker.h" +#import "NIKOrder.h" + + +@interface NIKStoreApi: NSObject { + +@private + NSOperationQueue *_queue; + NIKApiInvoker * _api; +} +@property(nonatomic, readonly) NSOperationQueue* queue; +@property(nonatomic, readonly) NIKApiInvoker* api; + +-(void) addHeader:(NSString*) value + forKey:(NSString*)key; + +-(void) getOrderByIdWithCompletionBlock :(NSString*) orderId + completionHandler:(void (^)(NIKOrder*, NSError *))completionBlock; +-(void) deleteOrderWithCompletionBlock :(NSString*) orderId + completionHandler:(void (^)(NSError *))completionBlock; +-(void) placeOrderWithCompletionBlock :(NIKOrder*) body + completionHandler:(void (^)(NSError *))completionBlock; +@end diff --git a/samples/client/petstore/objc/NIKStoreApi.m b/samples/client/petstore/objc/NIKStoreApi.m new file mode 100644 index 00000000000..c7d640ab12b --- /dev/null +++ b/samples/client/petstore/objc/NIKStoreApi.m @@ -0,0 +1,265 @@ +#import "NIKStoreApi.h" +#import "NIKOrder.h" + + + +@implementation NIKStoreApi +static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; + +@synthesize queue = _queue; +@synthesize api = _api; + +- (id) init { + self = [super init]; + _queue = [[NSOperationQueue alloc] init]; + _api = [[NIKApiInvoker alloc] init]; + + return self; +} + +-(void) addHeader:(NSString*) value + forKey:(NSString*)key { + [_api addHeader:value forKey:key]; +} + +-(void) getOrderByIdWithCompletionBlock :(NSString*) orderId + completionHandler:(void (^)(NIKOrder*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order/{orderId}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(orderId == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + completionBlock( [[NIKOrder alloc]initWithValues: data], nil); + }]; + +} + +-(void) deleteOrderWithCompletionBlock :(NSString*) orderId + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order/{orderId}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(orderId == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"DELETE" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) placeOrderWithCompletionBlock :(NIKOrder*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) getOrderByIdAsJsonWithCompletionBlock :(NSString*) orderId + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order/{orderId}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(orderId == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + NSData * responseData = nil; + if([data isKindOfClass:[NSDictionary class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + else if ([data isKindOfClass:[NSArray class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; + completionBlock(json, nil); + + }]; + +} + +-(void) deleteOrderAsJsonWithCompletionBlock :(NSString*) orderId + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order/{orderId}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(orderId == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"DELETE" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) placeOrderAsJsonWithCompletionBlock :(NIKOrder*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store.{format}/order", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + + +@end diff --git a/samples/client/petstore/objc/NIKTag.h b/samples/client/petstore/objc/NIKTag.h new file mode 100644 index 00000000000..e7043f7a350 --- /dev/null +++ b/samples/client/petstore/objc/NIKTag.h @@ -0,0 +1,25 @@ +#import +#import "NIKSwaggerObject.h" + +@interface NIKTag : NIKSwaggerObject { +@private + NSDictionary* raw; + NSNumber* __id; //NSNumber + NSString* _name; //NSString + } + +@property(nonatomic) NSDictionary* raw; + + +@property(nonatomic) NSNumber* _id; +@property(nonatomic) NSString* name; +- (id) _id: (NSNumber*) _id + name: (NSString*) name; + +- (id) initWithValues: (NSDictionary*)dict; +- (NSDictionary*) asDictionary; +- (NSDictionary*) asRaw; + + +@end + diff --git a/samples/client/petstore/objc/NIKTag.m b/samples/client/petstore/objc/NIKTag.m new file mode 100644 index 00000000000..ba5dfca9849 --- /dev/null +++ b/samples/client/petstore/objc/NIKTag.m @@ -0,0 +1,38 @@ +#import "NIKDate.h" +#import "NIKTag.h" + +@implementation NIKTag + +@synthesize raw = _raw; + +@synthesize _id = __id; +@synthesize name = _name; +- (id) _id: (NSNumber*) _id + name: (NSString*) name + { + __id = _id; + _name = name; + return self; + } + +- (id) initWithValues: (NSDictionary*)dict +{ + __id = [dict objectForKey:@"id"]; + _name = [dict objectForKey:@"name"]; + self.raw = [[NSDictionary alloc] initWithDictionary:dict]; + return self; +} + +-(NSDictionary*) asDictionary { + NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; + if(__id != nil) [dict setObject:__id forKey:@"id"]; + if(_name != nil) [dict setObject:_name forKey:@"name"]; + NSDictionary* output = [dict copy]; + return output; +} + +-(NSDictionary*) asRaw { + return _raw; +} +@end + diff --git a/samples/client/petstore/objc/NIKUser.h b/samples/client/petstore/objc/NIKUser.h new file mode 100644 index 00000000000..d6cd60bb527 --- /dev/null +++ b/samples/client/petstore/objc/NIKUser.h @@ -0,0 +1,43 @@ +#import +#import "NIKSwaggerObject.h" + +@interface NIKUser : NIKSwaggerObject { +@private + NSDictionary* raw; + NSNumber* __id; //NSNumber + NSString* _lastName; //NSString + NSString* _username; //NSString + NSString* _phone; //NSString + NSString* _email; //NSString + NSNumber* _userStatus; //NSNumber + NSString* _firstName; //NSString + NSString* _password; //NSString + } + +@property(nonatomic) NSDictionary* raw; + + +@property(nonatomic) NSNumber* _id; +@property(nonatomic) NSString* lastName; +@property(nonatomic) NSString* username; +@property(nonatomic) NSString* phone; +@property(nonatomic) NSString* email; +@property(nonatomic) NSNumber* userStatus; +@property(nonatomic) NSString* firstName; +@property(nonatomic) NSString* password; +- (id) _id: (NSNumber*) _id + lastName: (NSString*) lastName + username: (NSString*) username + phone: (NSString*) phone + email: (NSString*) email + userStatus: (NSNumber*) userStatus + firstName: (NSString*) firstName + password: (NSString*) password; + +- (id) initWithValues: (NSDictionary*)dict; +- (NSDictionary*) asDictionary; +- (NSDictionary*) asRaw; + + +@end + diff --git a/samples/client/petstore/objc/NIKUser.m b/samples/client/petstore/objc/NIKUser.m new file mode 100644 index 00000000000..cf51906457f --- /dev/null +++ b/samples/client/petstore/objc/NIKUser.m @@ -0,0 +1,68 @@ +#import "NIKDate.h" +#import "NIKUser.h" + +@implementation NIKUser + +@synthesize raw = _raw; + +@synthesize _id = __id; +@synthesize lastName = _lastName; +@synthesize username = _username; +@synthesize phone = _phone; +@synthesize email = _email; +@synthesize userStatus = _userStatus; +@synthesize firstName = _firstName; +@synthesize password = _password; +- (id) _id: (NSNumber*) _id + lastName: (NSString*) lastName + username: (NSString*) username + phone: (NSString*) phone + email: (NSString*) email + userStatus: (NSNumber*) userStatus + firstName: (NSString*) firstName + password: (NSString*) password + { + __id = _id; + _lastName = lastName; + _username = username; + _phone = phone; + _email = email; + _userStatus = userStatus; + _firstName = firstName; + _password = password; + return self; + } + +- (id) initWithValues: (NSDictionary*)dict +{ + __id = [dict objectForKey:@"id"]; + _lastName = [dict objectForKey:@"lastName"]; + _username = [dict objectForKey:@"username"]; + _phone = [dict objectForKey:@"phone"]; + _email = [dict objectForKey:@"email"]; + _userStatus = [dict objectForKey:@"userStatus"]; + _firstName = [dict objectForKey:@"firstName"]; + _password = [dict objectForKey:@"password"]; + self.raw = [[NSDictionary alloc] initWithDictionary:dict]; + return self; +} + +-(NSDictionary*) asDictionary { + NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; + if(__id != nil) [dict setObject:__id forKey:@"id"]; + if(_lastName != nil) [dict setObject:_lastName forKey:@"lastName"]; + if(_username != nil) [dict setObject:_username forKey:@"username"]; + if(_phone != nil) [dict setObject:_phone forKey:@"phone"]; + if(_email != nil) [dict setObject:_email forKey:@"email"]; + if(_userStatus != nil) [dict setObject:_userStatus forKey:@"userStatus"]; + if(_firstName != nil) [dict setObject:_firstName forKey:@"firstName"]; + if(_password != nil) [dict setObject:_password forKey:@"password"]; + NSDictionary* output = [dict copy]; + return output; +} + +-(NSDictionary*) asRaw { + return _raw; +} +@end + diff --git a/samples/client/petstore/objc/NIKUserApi.h b/samples/client/petstore/objc/NIKUserApi.h new file mode 100644 index 00000000000..09c9f9d68d9 --- /dev/null +++ b/samples/client/petstore/objc/NIKUserApi.h @@ -0,0 +1,34 @@ +#import +#import "NIKApiInvoker.h" +#import "NIKUser.h" + + +@interface NIKUserApi: NSObject { + +@private + NSOperationQueue *_queue; + NIKApiInvoker * _api; +} +@property(nonatomic, readonly) NSOperationQueue* queue; +@property(nonatomic, readonly) NIKApiInvoker* api; + +-(void) addHeader:(NSString*) value + forKey:(NSString*)key; + +-(void) createUsersWithArrayInputWithCompletionBlock :(NSArray*) body + completionHandler:(void (^)(NSError *))completionBlock; +-(void) createUserWithCompletionBlock :(NIKUser*) body + completionHandler:(void (^)(NSError *))completionBlock; +-(void) createUsersWithListInputWithCompletionBlock :(NSArray*) body + completionHandler:(void (^)(NSError *))completionBlock; +-(void) updateUserWithCompletionBlock :(NSString*) username body:(NIKUser*) body + completionHandler:(void (^)(NSError *))completionBlock; +-(void) deleteUserWithCompletionBlock :(NSString*) username + completionHandler:(void (^)(NSError *))completionBlock; +-(void) getUserByNameWithCompletionBlock :(NSString*) username + completionHandler:(void (^)(NIKUser*, NSError *))completionBlock; +-(void) loginUserWithCompletionBlock :(NSString*) username password:(NSString*) password + completionHandler:(void (^)(NSString*, NSError *))completionBlock; +-(void) logoutUserWithCompletionBlock : + completionHandler:(void (^)(NSError *))completionBlock; +@end diff --git a/samples/client/petstore/objc/NIKUserApi.m b/samples/client/petstore/objc/NIKUserApi.m new file mode 100644 index 00000000000..12577076c43 --- /dev/null +++ b/samples/client/petstore/objc/NIKUserApi.m @@ -0,0 +1,724 @@ +#import "NIKUserApi.h" +#import "NIKUser.h" + + + +@implementation NIKUserApi +static NSString * basePath = @"http://petstore.swagger.wordnik.com/api"; + +@synthesize queue = _queue; +@synthesize api = _api; + +- (id) init { + self = [super init]; + _queue = [[NSOperationQueue alloc] init]; + _api = [[NIKApiInvoker alloc] init]; + + return self; +} + +-(void) addHeader:(NSString*) value + forKey:(NSString*)key { + [_api addHeader:value forKey:key]; +} + +-(void) createUsersWithArrayInputWithCompletionBlock :(NSArray*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/createWithArray", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) createUserWithCompletionBlock :(NIKUser*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) createUsersWithListInputWithCompletionBlock :(NSArray*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/createWithList", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) updateUserWithCompletionBlock :(NSString*) username body:(NIKUser*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(username == nil) { + // error + } + if(body == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"PUT" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) deleteUserWithCompletionBlock :(NSString*) username + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(username == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"DELETE" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) getUserByNameWithCompletionBlock :(NSString*) username + completionHandler:(void (^)(NIKUser*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(username == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + completionBlock( [[NIKUser alloc]initWithValues: data], nil); + }]; + +} + +-(void) loginUserWithCompletionBlock :(NSString*) username password:(NSString*) password + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/login", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + if(username != nil) + [queryParams setValue:username forKey:@"username"]; + if(password != nil) + [queryParams setValue:password forKey:@"password"]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(username == nil) { + // error + } + if(password == nil) { + // error + } + [_api stringWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + completionBlock( [[NSString alloc]initWithString: data], nil); + }]; + +} + +-(void) logoutUserWithCompletionBlock : + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/logout", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + [_api stringWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSString *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) createUsersWithArrayInputAsJsonWithCompletionBlock :(NSArray*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/createWithArray", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) createUserAsJsonWithCompletionBlock :(NIKUser*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) createUsersWithListInputAsJsonWithCompletionBlock :(NSArray*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/createWithList", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(body == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"POST" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) updateUserAsJsonWithCompletionBlock :(NSString*) username body:(NIKUser*) body + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(body != nil && [body isKindOfClass:[NSArray class]]){ + NSMutableArray * objs = [[NSMutableArray alloc] init]; + for (id dict in (NSArray*)body) { + if([dict respondsToSelector:@selector(asDictionary)]) { + [objs addObject:[(NIKSwaggerObject*)dict asDictionary]]; + } + else{ + [objs addObject:dict]; + } + } + bodyDictionary = objs; + } + else if([body respondsToSelector:@selector(asDictionary)]) { + bodyDictionary = [(NIKSwaggerObject*)body asDictionary]; + } + else if([body isKindOfClass:[NSString class]]) { + bodyDictionary = body; + } + else{ + NSLog(@"don't know what to do with %@", body); + } + + if(username == nil) { + // error + } + if(body == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"PUT" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) deleteUserAsJsonWithCompletionBlock :(NSString*) username + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(username == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"DELETE" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + +-(void) getUserByNameAsJsonWithCompletionBlock :(NSString*) username + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/{username}", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]]; + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(username == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + NSData * responseData = nil; + if([data isKindOfClass:[NSDictionary class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + else if ([data isKindOfClass:[NSArray class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; + completionBlock(json, nil); + + }]; + +} + +-(void) loginUserAsJsonWithCompletionBlock :(NSString*) username password:(NSString*) password + completionHandler:(void (^)(NSString*, NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/login", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + if(username != nil) + [queryParams setValue:username forKey:@"username"]; + if(password != nil) + [queryParams setValue:password forKey:@"password"]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + if(username == nil) { + // error + } + if(password == nil) { + // error + } + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(nil, error);return; + } + + NSData * responseData = nil; + if([data isKindOfClass:[NSDictionary class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + else if ([data isKindOfClass:[NSArray class]]){ + responseData = [NSJSONSerialization dataWithJSONObject:data + options:kNilOptions error:&error]; + } + NSString * json = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; + completionBlock(json, nil); + + }]; + +} + +-(void) logoutUserAsJsonWithCompletionBlock : + completionHandler:(void (^)(NSError *))completionBlock{ + + NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user.{format}/logout", basePath]; + + // remove format in URL if needed + if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound) + [requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""]; + + NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init]; + id bodyDictionary = nil; + [_api dictionaryWithCompletionBlock: requestUrl + method: @"GET" + queryParams: queryParams + body: bodyDictionary + headerParams: headerParams + completionHandler: ^(NSDictionary *data, NSError *error) { + if (error) { + completionBlock(error);return; + } + + completionBlock(nil); + }]; + +} + + +@end