Permalink
Browse files

updated sample

  • Loading branch information...
1 parent 89740f4 commit 06dcd73d8e3e204bc283efe5ae894616fd27db4f @fehguy fehguy committed May 21, 2012
Showing with 276 additions and 127 deletions.
  1. +2 −2 samples/objc/Category.m
  2. +5 −5 samples/objc/Order.m
  3. +6 −6 samples/objc/Pet.m
  4. +76 −33 samples/objc/PetApi.m
  5. +42 −20 samples/objc/StoreApi.m
  6. +2 −2 samples/objc/Tag.m
  7. +8 −8 samples/objc/User.m
  8. +135 −51 samples/objc/UserApi.m
View
@@ -21,8 +21,8 @@ - (id) initWithValues: (NSDictionary*)dict
-(NSDictionary*) asDictionary {
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
- [dict setObject:__id forKey:@"id"];
- [dict setObject:_name forKey:@"name"];
+ if(__id != nil) [dict setObject:__id forKey:@"id"];
+ if(_name != nil) [dict setObject:_name forKey:@"name"];
NSDictionary* output = [[dict copy] autorelease];
return output;
}
View
@@ -49,10 +49,10 @@ - (id) initWithValues: (NSDictionary*)dict
-(NSDictionary*) asDictionary {
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
- [dict setObject:__id forKey:@"id"];
- [dict setObject:_petId forKey:@"petId"];
- [dict setObject:_status forKey:@"status"];
- [dict setObject:_quantity forKey:@"quantity"];
+ 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];
@@ -63,7 +63,7 @@ -(NSDictionary*) asDictionary {
}
}
else {
- [dict setObject:[_shipDate asDictionary]forKey:@"shipDate"];
+ if(_shipDate != nil) [dict setObject:[_shipDate asDictionary]forKey:@"shipDate"];
}
NSDictionary* output = [[dict copy] autorelease];
return output;
View
@@ -69,7 +69,7 @@ - (id) initWithValues: (NSDictionary*)dict
-(NSDictionary*) asDictionary {
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
- [dict setObject:__id forKey:@"id"];
+ if(__id != nil) [dict setObject:__id forKey:@"id"];
if(_tags != nil){
if([_tags isKindOfClass:[NSArray class]]){
NSMutableArray * array = [[NSMutableArray alloc] init];
@@ -80,7 +80,7 @@ -(NSDictionary*) asDictionary {
}
}
else {
- [dict setObject:[_tags asDictionary]forKey:@"tags"];
+ if(_tags != nil) [dict setObject:[_tags asDictionary]forKey:@"tags"];
}
if(_category != nil){
if([_category isKindOfClass:[NSArray class]]){
@@ -92,11 +92,11 @@ -(NSDictionary*) asDictionary {
}
}
else {
- [dict setObject:[_category asDictionary]forKey:@"category"];
+ if(_category != nil) [dict setObject:[_category asDictionary]forKey:@"category"];
}
- [dict setObject:_status forKey:@"status"];
- [dict setObject:_name forKey:@"name"];
- [dict setObject:_photoUrls forKey:@"photoUrls"];
+ 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] autorelease];
return output;
}
View
@@ -32,15 +32,16 @@ -(void) getPetByIdWithCompletionBlock :(NSString*) petId
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [_api escapeString:petId]];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
- if(petId == nil) {
+ NSDictionary* bodyDictionary = nil;
+ if(petId == nil) {
// error
}
- [_api invokeWithCompletionBlock:requestUrl
- method: @"GET"
- queryParams: queryParams
- body: nil
- headerParams: headerParams
- completionHandler: ^(NSDictionary *data, NSError *error) {
+ [_api invokeWithCompletionBlock: requestUrl
+ method: @"GET"
+ queryParams: queryParams
+ body: bodyDictionary
+ headerParams: headerParams
+ completionHandler: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
}
@@ -90,15 +91,35 @@ -(void) addPetWithCompletionBlock :(Pet*) body
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
+ NSDictionary* bodyDictionary = nil;
+ if(body != nil && [body isKindOfClass:[NSArray class]]){
+ NSMutableArray * objs = [[NSMutableArray alloc] init];
+ for (id dict in body) {
+ if([dict respondsToSelector:@selector(asDictionary:)]) {
+ [objs addObject:[dict asDictionary]];
+ }
+ else{
+ [objs addObject:dict];
+ }
+ }
+ bodyDictionary = objs;
+ }
+ else if([body respondsToSelector:@selector(asDictionary)]) {
+ bodyDictionary = [body asDictionary];
+ }
+ else{
+ NSLog(@"don't know what to do with %@", body);
+ }
+
if(body == nil) {
// error
}
- [_api invokeWithCompletionBlock:requestUrl
- method: @"GET"
- queryParams: queryParams
- body: nil
- headerParams: headerParams
- completionHandler: ^(NSDictionary *data, NSError *error) {
+ [_api invokeWithCompletionBlock: requestUrl
+ method: @"POST"
+ queryParams: queryParams
+ body: bodyDictionary
+ headerParams: headerParams
+ completionHandler: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
}
@@ -143,15 +164,35 @@ -(void) updatePetWithCompletionBlock :(Pet*) body
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
+ NSDictionary* bodyDictionary = nil;
+ if(body != nil && [body isKindOfClass:[NSArray class]]){
+ NSMutableArray * objs = [[NSMutableArray alloc] init];
+ for (id dict in body) {
+ if([dict respondsToSelector:@selector(asDictionary:)]) {
+ [objs addObject:[dict asDictionary]];
+ }
+ else{
+ [objs addObject:dict];
+ }
+ }
+ bodyDictionary = objs;
+ }
+ else if([body respondsToSelector:@selector(asDictionary)]) {
+ bodyDictionary = [body asDictionary];
+ }
+ else{
+ NSLog(@"don't know what to do with %@", body);
+ }
+
if(body == nil) {
// error
}
- [_api invokeWithCompletionBlock:requestUrl
- method: @"GET"
- queryParams: queryParams
- body: nil
- headerParams: headerParams
- completionHandler: ^(NSDictionary *data, NSError *error) {
+ [_api invokeWithCompletionBlock: requestUrl
+ method: @"PUT"
+ queryParams: queryParams
+ body: bodyDictionary
+ headerParams: headerParams
+ completionHandler: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
}
@@ -198,15 +239,16 @@ -(void) findPetsByStatusWithCompletionBlock :(NSString*) status
if(status != nil)
[queryParams setValue:status forKey:@"status"];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
- if(status == nil) {
+ NSDictionary* bodyDictionary = nil;
+ if(status == nil) {
// error
}
- [_api invokeWithCompletionBlock:requestUrl
- method: @"GET"
- queryParams: queryParams
- body: nil
- headerParams: headerParams
- completionHandler: ^(NSDictionary *data, NSError *error) {
+ [_api invokeWithCompletionBlock: requestUrl
+ method: @"GET"
+ queryParams: queryParams
+ body: bodyDictionary
+ headerParams: headerParams
+ completionHandler: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
}
@@ -273,15 +315,16 @@ -(void) findPetsByTagsWithCompletionBlock :(NSString*) tags
if(tags != nil)
[queryParams setValue:tags forKey:@"tags"];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
- if(tags == nil) {
+ NSDictionary* bodyDictionary = nil;
+ if(tags == nil) {
// error
}
- [_api invokeWithCompletionBlock:requestUrl
- method: @"GET"
- queryParams: queryParams
- body: nil
- headerParams: headerParams
- completionHandler: ^(NSDictionary *data, NSError *error) {
+ [_api invokeWithCompletionBlock: requestUrl
+ method: @"GET"
+ queryParams: queryParams
+ body: bodyDictionary
+ headerParams: headerParams
+ completionHandler: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
}
View
@@ -32,15 +32,16 @@ -(void) getOrderByIdWithCompletionBlock :(NSString*) orderId
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
- if(orderId == nil) {
+ NSDictionary* bodyDictionary = nil;
+ if(orderId == nil) {
// error
}
- [_api invokeWithCompletionBlock:requestUrl
- method: @"GET"
- queryParams: queryParams
- body: nil
- headerParams: headerParams
- completionHandler: ^(NSDictionary *data, NSError *error) {
+ [_api invokeWithCompletionBlock: requestUrl
+ method: @"GET"
+ queryParams: queryParams
+ body: bodyDictionary
+ headerParams: headerParams
+ completionHandler: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
}
@@ -91,15 +92,16 @@ -(void) deleteOrderWithCompletionBlock :(NSString*) orderId
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
- if(orderId == nil) {
+ NSDictionary* bodyDictionary = nil;
+ if(orderId == nil) {
// error
}
- [_api invokeWithCompletionBlock:requestUrl
- method: @"GET"
- queryParams: queryParams
- body: nil
- headerParams: headerParams
- completionHandler: ^(NSDictionary *data, NSError *error) {
+ [_api invokeWithCompletionBlock: requestUrl
+ method: @"DELETE"
+ queryParams: queryParams
+ body: bodyDictionary
+ headerParams: headerParams
+ completionHandler: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
}
@@ -145,15 +147,35 @@ -(void) placeOrderWithCompletionBlock :(Order*) body
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
+ NSDictionary* bodyDictionary = nil;
+ if(body != nil && [body isKindOfClass:[NSArray class]]){
+ NSMutableArray * objs = [[NSMutableArray alloc] init];
+ for (id dict in body) {
+ if([dict respondsToSelector:@selector(asDictionary:)]) {
+ [objs addObject:[dict asDictionary]];
+ }
+ else{
+ [objs addObject:dict];
+ }
+ }
+ bodyDictionary = objs;
+ }
+ else if([body respondsToSelector:@selector(asDictionary)]) {
+ bodyDictionary = [body asDictionary];
+ }
+ else{
+ NSLog(@"don't know what to do with %@", body);
+ }
+
if(body == nil) {
// error
}
- [_api invokeWithCompletionBlock:requestUrl
- method: @"GET"
- queryParams: queryParams
- body: nil
- headerParams: headerParams
- completionHandler: ^(NSDictionary *data, NSError *error) {
+ [_api invokeWithCompletionBlock: requestUrl
+ method: @"POST"
+ queryParams: queryParams
+ body: bodyDictionary
+ headerParams: headerParams
+ completionHandler: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
}
View
@@ -21,8 +21,8 @@ - (id) initWithValues: (NSDictionary*)dict
-(NSDictionary*) asDictionary {
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
- [dict setObject:__id forKey:@"id"];
- [dict setObject:_name forKey:@"name"];
+ if(__id != nil) [dict setObject:__id forKey:@"id"];
+ if(_name != nil) [dict setObject:_name forKey:@"name"];
NSDictionary* output = [[dict copy] autorelease];
return output;
}
View
@@ -45,14 +45,14 @@ - (id) initWithValues: (NSDictionary*)dict
-(NSDictionary*) asDictionary {
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
- [dict setObject:__id forKey:@"id"];
- [dict setObject:_lastName forKey:@"lastName"];
- [dict setObject:_username forKey:@"username"];
- [dict setObject:_phone forKey:@"phone"];
- [dict setObject:_email forKey:@"email"];
- [dict setObject:_userStatus forKey:@"userStatus"];
- [dict setObject:_firstName forKey:@"firstName"];
- [dict setObject:_password forKey:@"password"];
+ 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] autorelease];
return output;
}
Oops, something went wrong.

0 comments on commit 06dcd73

Please sign in to comment.