updated objc client to support iso8601 datetime format

This commit is contained in:
geekerzp 2015-05-15 17:49:56 +08:00
parent 0248d6fd9f
commit c06cb38d64
14 changed files with 65 additions and 117 deletions

View File

@ -120,8 +120,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("SWGApiClient.m", sourceFolder, "SWGApiClient.m"));
supportingFiles.add(new SupportingFile("SWGFile.h", sourceFolder, "SWGFile.h"));
supportingFiles.add(new SupportingFile("SWGFile.m", sourceFolder, "SWGFile.m"));
supportingFiles.add(new SupportingFile("SWGDate.h", sourceFolder, "SWGDate.h"));
supportingFiles.add(new SupportingFile("SWGDate.m", sourceFolder, "SWGDate.m"));
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", sourceFolder, "JSONValueTransformer+ISO8601.m"));
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.h", sourceFolder, "JSONValueTransformer+ISO8601.h"));
supportingFiles.add(new SupportingFile("Podfile.mustache", "", "Podfile"));
}

View File

@ -0,0 +1,6 @@
#import <Foundation/Foundation.h>
#import <ISO8601/ISO8601.h>
#import <JSONModel/JSONValueTransformer.h>
@interface JSONValueTransformer (ISO8601)
@end

View File

@ -0,0 +1,10 @@
#import "JSONValueTransformer+ISO8601.h"
@implementation JSONValueTransformer (ISO8601)
- (NSDate *) NSDateFromNSString:(NSString *)string
{
return [NSDate dateWithISO8601String:string];
}
@end

View File

@ -2,3 +2,4 @@ platform :ios, '6.0'
xcodeproj '{{projectName}}/{{projectName}}.xcodeproj'
pod 'AFNetworking', '~> 2.1'
pod 'JSONModel', '~> 1.0'
pod 'ISO8601'

View File

@ -1,12 +0,0 @@
#import <Foundation/Foundation.h>
#import "SWGObject.h"
@interface SWGDate : SWGObject {
@private
NSDate *_date;
}
@property(nonatomic, readonly) NSDate* date;
- (id) initWithValues: (NSString*)input;
-(NSString*) toString;
@end

View File

@ -1,34 +0,0 @@
#import "SWGDate.h"
@implementation SWGDate
@synthesize date = _date;
- (id) initWithValues:(NSString*)input {
if([input isKindOfClass:[NSString class]]){
NSDateFormatter* df = [NSDateFormatter new];
NSLocale *locale = [[NSLocale new]
initWithLocaleIdentifier:@"en_US_POSIX"];
[df setLocale:locale];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
_date = [df dateFromString:input];
}
else if([input isKindOfClass:[NSNumber class]]) {
NSTimeInterval interval = [input doubleValue];
_date = [[NSDate alloc] initWithTimeIntervalSince1970:interval];
}
return self;
}
-(NSString*) toString {
NSDateFormatter* df = [NSDateFormatter new];
NSLocale *locale = [[NSLocale new]
initWithLocaleIdentifier:@"en_US_POSIX"];
[df setLocale:locale];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
return [df stringFromDate:_date];
}
@end

View File

@ -8,6 +8,8 @@
/* Begin PBXBuildFile section */
BA525648922D4C0E9F44D4F1 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 73DA4F1067C343C3962F1542 /* libPods.a */; };
CFD1B6701B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; };
CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; };
EA66999A1811D2FA00A70D03 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA6699991811D2FA00A70D03 /* Foundation.framework */; };
EA66999C1811D2FA00A70D03 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA66999B1811D2FA00A70D03 /* CoreGraphics.framework */; };
EA66999E1811D2FA00A70D03 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA66999D1811D2FA00A70D03 /* UIKit.framework */; };
@ -28,7 +30,6 @@
EAB26B0D1AC8DF78002F5C7A /* PetApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA6699C71811D2FB00A70D03 /* PetApiTest.m */; };
EAEA85E41811D3AE00F06E69 /* SWGApiClient.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85CD1811D3AE00F06E69 /* SWGApiClient.m */; };
EAEA85E51811D3AE00F06E69 /* SWGCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85CF1811D3AE00F06E69 /* SWGCategory.m */; };
EAEA85E61811D3AE00F06E69 /* SWGDate.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85D11811D3AE00F06E69 /* SWGDate.m */; };
EAEA85E71811D3AE00F06E69 /* SWGFile.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85D31811D3AE00F06E69 /* SWGFile.m */; };
EAEA85E81811D3AE00F06E69 /* SWGObject.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85D51811D3AE00F06E69 /* SWGObject.m */; };
EAEA85E91811D3AE00F06E69 /* SWGOrder.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85D71811D3AE00F06E69 /* SWGOrder.m */; };
@ -54,6 +55,8 @@
/* Begin PBXFileReference section */
73DA4F1067C343C3962F1542 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
A425648B5C0A4849C7668069 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
CFD1B66E1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSONValueTransformer+ISO8601.h"; sourceTree = "<group>"; };
CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSONValueTransformer+ISO8601.m"; sourceTree = "<group>"; };
E2B6DA00BE52336E23783686 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
EA6699961811D2FA00A70D03 /* PetstoreClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PetstoreClient.app; sourceTree = BUILT_PRODUCTS_DIR; };
EA6699991811D2FA00A70D03 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@ -84,8 +87,6 @@
EAEA85CD1811D3AE00F06E69 /* SWGApiClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGApiClient.m; sourceTree = "<group>"; };
EAEA85CE1811D3AE00F06E69 /* SWGCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGCategory.h; sourceTree = "<group>"; };
EAEA85CF1811D3AE00F06E69 /* SWGCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGCategory.m; sourceTree = "<group>"; };
EAEA85D01811D3AE00F06E69 /* SWGDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGDate.h; sourceTree = "<group>"; };
EAEA85D11811D3AE00F06E69 /* SWGDate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGDate.m; sourceTree = "<group>"; };
EAEA85D21811D3AE00F06E69 /* SWGFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGFile.h; sourceTree = "<group>"; };
EAEA85D31811D3AE00F06E69 /* SWGFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGFile.m; sourceTree = "<group>"; };
EAEA85D41811D3AE00F06E69 /* SWGObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGObject.h; sourceTree = "<group>"; };
@ -224,14 +225,14 @@
EAEA85CB1811D3AE00F06E69 /* client */ = {
isa = PBXGroup;
children = (
CFD1B66E1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.h */,
CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */,
EA8B8AA21AC6683700638FBB /* SWGQueryParamCollection.h */,
EA8B8AA31AC6683700638FBB /* SWGQueryParamCollection.m */,
EAEA85CC1811D3AE00F06E69 /* SWGApiClient.h */,
EAEA85CD1811D3AE00F06E69 /* SWGApiClient.m */,
EAEA85CE1811D3AE00F06E69 /* SWGCategory.h */,
EAEA85CF1811D3AE00F06E69 /* SWGCategory.m */,
EAEA85D01811D3AE00F06E69 /* SWGDate.h */,
EAEA85D11811D3AE00F06E69 /* SWGDate.m */,
EAEA85D21811D3AE00F06E69 /* SWGFile.h */,
EAEA85D31811D3AE00F06E69 /* SWGFile.m */,
EAEA85D41811D3AE00F06E69 /* SWGObject.h */,
@ -397,8 +398,8 @@
EAEA85EE1811D3AE00F06E69 /* SWGUser.m in Sources */,
EAEA85EF1811D3AE00F06E69 /* SWGUserApi.m in Sources */,
EAEA85EB1811D3AE00F06E69 /* SWGPetApi.m in Sources */,
EAEA85E61811D3AE00F06E69 /* SWGDate.m in Sources */,
EA6699A61811D2FA00A70D03 /* main.m in Sources */,
CFD1B6701B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */,
EAEA85EA1811D3AE00F06E69 /* SWGPet.m in Sources */,
EAEA85E41811D3AE00F06E69 /* SWGApiClient.m in Sources */,
EAEA85EC1811D3AE00F06E69 /* SWGStoreApi.m in Sources */,
@ -414,6 +415,7 @@
buildActionMask = 2147483647;
files = (
EAB26B0C1AC8DF78002F5C7A /* PetApiTest.h in Sources */,
CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */,
EAB26B0D1AC8DF78002F5C7A /* PetApiTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -2,3 +2,4 @@ platform :ios, '6.0'
xcodeproj 'PetstoreClient/PetstoreClient.xcodeproj'
pod 'AFNetworking', '~> 2.1'
pod 'JSONModel', '~> 1.0'
pod 'ISO8601'

View File

@ -1,33 +1,36 @@
PODS:
- AFNetworking (2.5.1):
- AFNetworking/NSURLConnection (= 2.5.1)
- AFNetworking/NSURLSession (= 2.5.1)
- AFNetworking/Reachability (= 2.5.1)
- AFNetworking/Security (= 2.5.1)
- AFNetworking/Serialization (= 2.5.1)
- AFNetworking/UIKit (= 2.5.1)
- AFNetworking/NSURLConnection (2.5.1):
- AFNetworking (2.5.3):
- AFNetworking/NSURLConnection (= 2.5.3)
- AFNetworking/NSURLSession (= 2.5.3)
- AFNetworking/Reachability (= 2.5.3)
- AFNetworking/Security (= 2.5.3)
- AFNetworking/Serialization (= 2.5.3)
- AFNetworking/UIKit (= 2.5.3)
- AFNetworking/NSURLConnection (2.5.3):
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/NSURLSession (2.5.1):
- AFNetworking/NSURLSession (2.5.3):
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/Reachability (2.5.1)
- AFNetworking/Security (2.5.1)
- AFNetworking/Serialization (2.5.1)
- AFNetworking/UIKit (2.5.1):
- AFNetworking/Reachability (2.5.3)
- AFNetworking/Security (2.5.3)
- AFNetworking/Serialization (2.5.3)
- AFNetworking/UIKit (2.5.3):
- AFNetworking/NSURLConnection
- AFNetworking/NSURLSession
- JSONModel (1.0.2)
- ISO8601 (0.2.0)
- JSONModel (1.1.0)
DEPENDENCIES:
- AFNetworking (~> 2.1)
- ISO8601
- JSONModel (~> 1.0)
SPEC CHECKSUMS:
AFNetworking: 10e85a00bb0f475124e4ff2677bf15693b2c1523
JSONModel: 6ffcb4ffa3659c9e9a2e5d45d6c7705bab187c03
AFNetworking: e1d86c2a96bb5d2e7408da36149806706ee122fe
ISO8601: 962282de75074c38bbfaa7b133b0e743ed6deb8d
JSONModel: ec77e9865236a7a09d9cf7668df6b4b328d9ec1d
COCOAPODS: 0.36.0
COCOAPODS: 0.37.1

View File

@ -0,0 +1,6 @@
#import <Foundation/Foundation.h>
#import <ISO8601/ISO8601.h>
#import <JSONModel/JSONValueTransformer.h>
@interface JSONValueTransformer (ISO8601)
@end

View File

@ -0,0 +1,10 @@
#import "JSONValueTransformer+ISO8601.h"
@implementation JSONValueTransformer (ISO8601)
- (NSDate *) NSDateFromNSString:(NSString *)string
{
return [NSDate dateWithISO8601String:string];
}
@end

View File

@ -1,12 +0,0 @@
#import <Foundation/Foundation.h>
#import "SWGObject.h"
@interface SWGDate : SWGObject {
@private
NSDate *_date;
}
@property(nonatomic, readonly) NSDate* date;
- (id) initWithValues: (NSString*)input;
-(NSString*) toString;
@end

View File

@ -1,34 +0,0 @@
#import "SWGDate.h"
@implementation SWGDate
@synthesize date = _date;
- (id) initWithValues:(NSString*)input {
if([input isKindOfClass:[NSString class]]){
NSDateFormatter* df = [NSDateFormatter new];
NSLocale *locale = [[NSLocale new]
initWithLocaleIdentifier:@"en_US_POSIX"];
[df setLocale:locale];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
_date = [df dateFromString:input];
}
else if([input isKindOfClass:[NSNumber class]]) {
NSTimeInterval interval = [input doubleValue];
_date = [[NSDate alloc] initWithTimeIntervalSince1970:interval];
}
return self;
}
-(NSString*) toString {
NSDateFormatter* df = [NSDateFormatter new];
NSLocale *locale = [[NSLocale new]
initWithLocaleIdentifier:@"en_US_POSIX"];
[df setLocale:locale];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
return [df stringFromDate:_date];
}
@end

View File

@ -1,5 +1,6 @@
#import <Foundation/Foundation.h>
#import "JSONModel.h"
#import "JSONValueTransformer+ISO8601.h"
@interface SWGObject : JSONModel
@end