added file upload support

This commit is contained in:
Tony Tam 2013-03-13 23:45:10 -07:00
parent 7659ab5a47
commit c47e553425
12 changed files with 277 additions and 44 deletions

View File

@ -32,6 +32,8 @@ object ObjcPetstoreCodegen extends BasicObjcGenerator {
("NIKSwaggerObject.m", destinationDir, "NIKSwaggerObject.m"),
("NIKApiInvoker.h", destinationDir, "NIKApiInvoker.h"),
("NIKApiInvoker.m", destinationDir, "NIKApiInvoker.m"),
("NIKFile.h", destinationDir, "NIKFile.h"),
("NIKFile.m", destinationDir, "NIKFile.m"),
("NIKDate.h", destinationDir, "NIKDate.h"),
("NIKDate.m", destinationDir, "NIKDate.m"))
}

View File

@ -45,6 +45,9 @@
EA07F54816135916006A2112 /* NIKUser.m in Sources */ = {isa = PBXBuildFile; fileRef = EA07F51F1613569A006A2112 /* NIKUser.m */; };
EA07F54916135916006A2112 /* NIKUserApi.h in Sources */ = {isa = PBXBuildFile; fileRef = EA07F5201613569A006A2112 /* NIKUserApi.h */; };
EA07F54A16135916006A2112 /* NIKUserApi.m in Sources */ = {isa = PBXBuildFile; fileRef = EA07F5211613569A006A2112 /* NIKUserApi.m */; };
EA4F4D3816F1A90A00F24B35 /* NIKFile.m in Sources */ = {isa = PBXBuildFile; fileRef = EA4F4D3716F1A90A00F24B35 /* NIKFile.m */; };
EA4F4D3916F1A92E00F24B35 /* NIKFile.h in Sources */ = {isa = PBXBuildFile; fileRef = EA4F4D3616F1A90A00F24B35 /* NIKFile.h */; };
EA4F4D3A16F1A92E00F24B35 /* NIKFile.m in Sources */ = {isa = PBXBuildFile; fileRef = EA4F4D3716F1A90A00F24B35 /* NIKFile.m */; };
EA5A034416141443003B3E41 /* UserApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA5A034316141443003B3E41 /* UserApiTest.m */; };
EAE96DE616138695004AB97C /* PetApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA81837816137FD500341A6E /* PetApiTest.m */; };
EAE96DE716138695004AB97C /* PetApiTest.h in Sources */ = {isa = PBXBuildFile; fileRef = EA81837916137FD500341A6E /* PetApiTest.h */; };
@ -104,6 +107,8 @@
EA07F5211613569A006A2112 /* NIKUserApi.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NIKUserApi.m; path = ../client/NIKUserApi.m; sourceTree = "<group>"; };
EA07F5301613580E006A2112 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
EA07F53216135819006A2112 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
EA4F4D3616F1A90A00F24B35 /* NIKFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NIKFile.h; path = ../client/NIKFile.h; sourceTree = "<group>"; };
EA4F4D3716F1A90A00F24B35 /* NIKFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NIKFile.m; path = ../client/NIKFile.m; sourceTree = "<group>"; };
EA5A034216141443003B3E41 /* UserApiTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UserApiTest.h; path = ../tests/UserApiTest.h; sourceTree = "<group>"; };
EA5A034316141443003B3E41 /* UserApiTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UserApiTest.m; path = ../tests/UserApiTest.m; sourceTree = "<group>"; };
EA81837816137FD500341A6E /* PetApiTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PetApiTest.m; path = ../tests/PetApiTest.m; sourceTree = "<group>"; };
@ -134,6 +139,8 @@
EA07F4AE16134F27006A2112 = {
isa = PBXGroup;
children = (
EA4F4D3616F1A90A00F24B35 /* NIKFile.h */,
EA4F4D3716F1A90A00F24B35 /* NIKFile.m */,
EA81837C1613809300341A6E /* Tests */,
EA07F52D1613569E006A2112 /* Generated Client */,
EA07F4BF16134F27006A2112 /* PetstoreClient */,
@ -336,6 +343,7 @@
EA07F52A1613569A006A2112 /* NIKTag.m in Sources */,
EA07F52B1613569A006A2112 /* NIKUser.m in Sources */,
EA07F52C1613569A006A2112 /* NIKUserApi.m in Sources */,
EA4F4D3816F1A90A00F24B35 /* NIKFile.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -343,6 +351,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EA4F4D3916F1A92E00F24B35 /* NIKFile.h in Sources */,
EA4F4D3A16F1A92E00F24B35 /* NIKFile.m in Sources */,
EAE96DE616138695004AB97C /* PetApiTest.m in Sources */,
EAE96DE716138695004AB97C /* PetApiTest.h in Sources */,
EA07F53516135916006A2112 /* NIKApiInvoker.h in Sources */,

View File

@ -21,18 +21,20 @@
-(NSString*) escapeString:(NSString*) string;
-(void) dictionary:(NSString*) path
method:(NSString*) method
queryParams:(NSDictionary*) queryParams
body:(id)body
headerParams:(NSDictionary*) headerParams
completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock;
-(void) dictionary: (NSString*) path
method: (NSString*) method
queryParams: (NSDictionary*) queryParams
body: (id)body
headerParams: (NSDictionary*) headerParams
contentType: contentType
completionBlock: (void (^)(NSDictionary*, NSError *))completionBlock;
-(void) stringWithCompletionBlock:(NSString*) path
method:(NSString*) method
queryParams:(NSDictionary*) queryParams
body:(id)body
headerParams:(NSDictionary*) headerParams
completionBlock:(void (^)(NSString*, NSError *))completionBlock;
-(void) stringWithCompletionBlock: (NSString*) path
method: (NSString*) method
queryParams: (NSDictionary*) queryParams
body: (id)body
headerParams: (NSDictionary*) headerParams
contentType: contentType
completionBlock: (void (^)(NSString*, NSError *))completionBlock;
@end

View File

@ -1,4 +1,5 @@
#import "NIKApiInvoker.h"
#import "NIKFile.h"
@implementation NIKApiInvoker
@ -58,12 +59,13 @@ static NSInteger __LoadingObjectsCount = 0;
kCFStringEncodingUTF8));
}
-(void) dictionary:(NSString*) path
method:(NSString*) method
queryParams:(NSDictionary*) queryParams
body:(id) body
headerParams:(NSDictionary*) headerParams
completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock
-(void) dictionary: (NSString*) path
method: (NSString*) method
queryParams: (NSDictionary*) queryParams
body: (id) body
headerParams: (NSDictionary*) headerParams
contentType: (NSString*) contentType
completionBlock: (void (^)(NSDictionary*, NSError *))completionBlock
{
NSMutableString * requestUrl = [NSMutableString stringWithFormat:@"%@", path];
NSString * separator = nil;
@ -111,6 +113,21 @@ static NSInteger __LoadingObjectsCount = 0;
data = [NSJSONSerialization dataWithJSONObject:body
options:kNilOptions error:&error];
}
else if ([body isKindOfClass:[NIKFile class]]){
NIKFile * file = (NIKFile*) body;
NSString *boundary = @"Fo0+BAr";
contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
// add the body
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Disposition: form-data; name= \"some_name\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image_file\"; filename=\"%@\"\r\n", file] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", file.mimeType] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData: file.data];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
}
else if ([body isKindOfClass:[NSArray class]]){
data = [NSJSONSerialization dataWithJSONObject:body
options:kNilOptions error:&error];
@ -122,7 +139,7 @@ static NSInteger __LoadingObjectsCount = 0;
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:data];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
}
// Handle caching on GET requests
@ -174,12 +191,13 @@ static NSInteger __LoadingObjectsCount = 0;
}];
}
-(void) stringWithCompletionBlock:(NSString*) path
method:(NSString*) method
queryParams:(NSDictionary*) queryParams
body:(id) body
headerParams:(NSDictionary*) headerParams
completionBlock:(void (^)(NSString*, NSError *))completionBlock
-(void) stringWithCompletionBlock: (NSString*) path
method: (NSString*) method
queryParams: (NSDictionary*) queryParams
body: (id) body
headerParams: (NSDictionary*) headerParams
contentType: (NSString*) contentType
completionBlock: (void (^)(NSString*, NSError *))completionBlock
{
NSMutableString * requestUrl = [NSMutableString stringWithFormat:@"%@", path];
NSString * separator = nil;
@ -227,6 +245,21 @@ static NSInteger __LoadingObjectsCount = 0;
data = [NSJSONSerialization dataWithJSONObject:body
options:kNilOptions error:&error];
}
else if ([body isKindOfClass:[NIKFile class]]){
NIKFile * file = (NIKFile*) body;
NSString *boundary = @"Fo0+BAr";
contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
// add the body
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Disposition: form-data; name= \"some_name\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image_file\"; filename=\"%@\"\r\n", file] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", file.mimeType] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData: file.data];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
}
else if ([body isKindOfClass:[NSArray class]]){
data = [NSJSONSerialization dataWithJSONObject:body
options:kNilOptions error:&error];
@ -238,7 +271,7 @@ static NSInteger __LoadingObjectsCount = 0;
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:data];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
}

View File

@ -9,5 +9,4 @@
- (id) initWithValues: (NSString*)input;
-(NSString*) toString;
@end
@end

View File

@ -0,0 +1,17 @@
#import <Foundation/Foundation.h>
@interface NIKFile : NSObject {
@private
NSString* name;
NSString* mimeType;
NSData* data;
}
@property(nonatomic, readonly) NSString* name;
@property(nonatomic, readonly) NSString* mimeType;
@property(nonatomic, readonly) NSData* data;
- (id) initWithNameData: (NSString*) filename
mimeType: (NSString*) mimeType
data: (NSData*) data;
@end

View File

@ -0,0 +1,26 @@
#import "NIKFile.h"
@implementation NIKFile
@synthesize name = _name;
@synthesize mimeType = _mimeType;
@synthesize data = _data;
- (id) init {
self = [super init];
return self;
}
- (id) initWithNameData: (NSString*) filename
mimeType: (NSString*) fileMimeType
data: (NSData*) data {
self = [super init];
if(self) {
_name = filename;
_mimeType = fileMimeType;
_data = data;
}
return self;
}
@end

View File

@ -1,4 +1,5 @@
#import "NIKPetApi.h"
#import "NIKFile.h"
#import "NIKPet.h"
@ -42,7 +43,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [_api escapeString:petId]];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(petId == nil) {
@ -53,6 +57,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -72,7 +77,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(body != nil && [body isKindOfClass:[NSArray class]]){
@ -93,6 +101,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
else if([body isKindOfClass:[NSString class]]) {
bodyDictionary = body;
}
else if([body isKindOfClass: [NIKFile class]]) {
contentType = @"form-data";
bodyDictionary = body;
}
else{
NSLog(@"don't know what to do with %@", body);
}
@ -105,6 +117,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -125,7 +138,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(body != nil && [body isKindOfClass:[NSArray class]]){
@ -146,6 +162,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
else if([body isKindOfClass:[NSString class]]) {
bodyDictionary = body;
}
else if([body isKindOfClass: [NIKFile class]]) {
contentType = @"form-data";
bodyDictionary = body;
}
else{
NSLog(@"don't know what to do with %@", body);
}
@ -158,6 +178,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -178,7 +199,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
if(status != nil)
queryParams[@"status"] = status;
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
@ -191,6 +215,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams: queryParams
body: bodyDictionary
headerParams: headerParams
contentType: contentType
completionBlock: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -218,7 +243,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
if(tags != nil)
queryParams[@"tags"] = tags;
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
@ -231,6 +259,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams: queryParams
body: bodyDictionary
headerParams: headerParams
contentType: contentType
completionBlock: ^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -260,6 +289,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [_api escapeString:petId]];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -271,6 +302,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -304,6 +336,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -337,6 +371,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
@ -359,6 +394,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -392,6 +429,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
@ -414,6 +452,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
if(status != nil)
queryParams[@"status"] = status;
@ -427,6 +467,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -460,6 +501,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
if(tags != nil)
queryParams[@"tags"] = tags;
@ -473,6 +516,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;

View File

@ -1,4 +1,5 @@
#import "NIKStoreApi.h"
#import "NIKFile.h"
#import "NIKOrder.h"
@ -42,7 +43,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(orderId == nil) {
@ -53,6 +57,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -73,7 +78,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(orderId == nil) {
@ -84,6 +92,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -104,7 +113,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(body != nil && [body isKindOfClass:[NSArray class]]){
@ -125,6 +137,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
else if([body isKindOfClass:[NSString class]]) {
bodyDictionary = body;
}
else if([body isKindOfClass: [NIKFile class]]) {
contentType = @"form-data";
bodyDictionary = body;
}
else{
NSLog(@"don't know what to do with %@", body);
}
@ -137,6 +153,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -159,6 +176,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -170,6 +189,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -204,6 +224,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [_api escapeString:orderId]];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -215,6 +237,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
@ -237,6 +260,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -270,6 +295,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;

View File

@ -1,4 +1,5 @@
#import "NIKUserApi.h"
#import "NIKFile.h"
#import "NIKUser.h"
@ -41,7 +42,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(body != nil && [body isKindOfClass:[NSArray class]]){
@ -62,6 +66,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
else if([body isKindOfClass:[NSString class]]) {
bodyDictionary = body;
}
else if([body isKindOfClass: [NIKFile class]]) {
contentType = @"form-data";
bodyDictionary = body;
}
else{
NSLog(@"don't know what to do with %@", body);
}
@ -74,6 +82,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -94,7 +103,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(body != nil && [body isKindOfClass:[NSArray class]]){
@ -115,6 +127,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
else if([body isKindOfClass:[NSString class]]) {
bodyDictionary = body;
}
else if([body isKindOfClass: [NIKFile class]]) {
contentType = @"form-data";
bodyDictionary = body;
}
else{
NSLog(@"don't know what to do with %@", body);
}
@ -127,6 +143,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -147,7 +164,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(body != nil && [body isKindOfClass:[NSArray class]]){
@ -168,6 +188,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
else if([body isKindOfClass:[NSString class]]) {
bodyDictionary = body;
}
else if([body isKindOfClass: [NIKFile class]]) {
contentType = @"form-data";
bodyDictionary = body;
}
else{
NSLog(@"don't know what to do with %@", body);
}
@ -180,6 +204,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -202,7 +227,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(body != nil && [body isKindOfClass:[NSArray class]]){
@ -223,6 +251,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
else if([body isKindOfClass:[NSString class]]) {
bodyDictionary = body;
}
else if([body isKindOfClass: [NIKFile class]]) {
contentType = @"form-data";
bodyDictionary = body;
}
else{
NSLog(@"don't know what to do with %@", body);
}
@ -238,6 +270,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -259,7 +292,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(username == nil) {
@ -270,6 +306,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -291,7 +328,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
if(username == nil) {
@ -302,6 +342,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -322,7 +363,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
if(username != nil)
queryParams[@"username"] = username;
if(password != nil)
@ -340,6 +384,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(nil, error);
@ -360,7 +405,10 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
[_api stringWithCompletionBlock:requestUrl
@ -368,6 +416,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSString *data, NSError *error) {
if (error) {
completionBlock(error);
@ -389,6 +438,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -422,6 +473,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
@ -444,6 +496,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -477,6 +531,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
@ -499,6 +554,8 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -532,6 +589,7 @@ static NSString * basePath = @"http://petstore.swagger.wordnik.com/api";
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
@ -556,6 +614,8 @@ body:(NIKUser*) body
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -592,6 +652,7 @@ body:(NIKUser*) body
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
@ -615,6 +676,8 @@ body:(NIKUser*) body
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -626,6 +689,7 @@ body:(NIKUser*) body
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;
@ -649,6 +713,8 @@ body:(NIKUser*) body
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [_api escapeString:username]];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -660,6 +726,7 @@ body:(NIKUser*) body
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -694,6 +761,8 @@ password:(NSString*) password
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
if(username != nil)
queryParams[@"username"] = username;
@ -712,6 +781,7 @@ password:(NSString*) password
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(nil, error);return;
@ -745,6 +815,8 @@ password:(NSString*) password
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@""];
NSString* contentType = @"application/json";
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
id bodyDictionary = nil;
@ -753,6 +825,7 @@ password:(NSString*) password
queryParams:queryParams
body:bodyDictionary
headerParams:headerParams
contentType:contentType
completionBlock:^(NSDictionary *data, NSError *error) {
if (error) {
completionBlock(error);return;

View File

@ -1,4 +1,5 @@
#import "PetApiTest.h"
#import "NIKFile.h"
@implementation PetApiTest