├── .gitignore ├── DDModel.podspec ├── DDModel.xcodeproj └── project.pbxproj ├── DDModel ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Classes │ ├── AFHTTPSessionManager+DDModel.h │ ├── AFHTTPSessionManager+DDModel.m │ ├── DDCache.h │ ├── DDCache.m │ ├── DDModel+DDAddition.h │ ├── DDModel+DDAddition.m │ ├── DDModel.h │ ├── DDModel.m │ ├── DDModelHttpClient+DDAddition.h │ ├── DDModelHttpClient+DDAddition.m │ ├── DDModelHttpClient.h │ ├── DDModelHttpClient.m │ ├── DDModelKit.h │ ├── NSDictionary+DDModel.h │ ├── NSDictionary+DDModel.m │ ├── NSString+DDModel.h │ ├── NSString+DDModel.m │ ├── NSURLSessionTask+DDModel.h │ └── NSURLSessionTask+DDModel.m ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── Info.plist ├── Post.h ├── Post.m ├── ViewController.h ├── ViewController.m ├── adn.cer ├── main.m └── root_ca.cer ├── DDModelTests ├── DDModelTests.m └── Info.plist ├── LICENSE ├── Podfile └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | Pods/* 2 | Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | *.moved-aside 16 | DerivedData 17 | .idea/ 18 | Podfile.lock 19 | -------------------------------------------------------------------------------- /DDModel.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'DDModel' 3 | s.version = '1.2.2' 4 | s.license = 'MIT' 5 | s.summary = 'a HTTP-JSON-ORM-Persisent Object Kit' 6 | s.homepage = 'https://github.com/openboy2012/DDModel.git' 7 | s.author = { 'DeJohn Dong' => 'dongjia_9251@126.com' } 8 | s.source = { :git => 'https://github.com/openboy2012/DDModel.git',:tag =>s.version.to_s} 9 | s.ios.deployment_target = '7.0' 10 | s.public_header_files = 'DDModel/Classes/DDModelKit.h' 11 | s.source_files = 'DDModel/Classes/DDModelKit.h' 12 | s.requires_arc = true 13 | 14 | s.subspec 'Categories' do |ss| 15 | ss.source_files = 'DDModel/Classes/{NS}*.{h,m}' 16 | end 17 | s.subspec 'Cache' do |ss| 18 | ss.dependency 'DDModel/Categories' 19 | ss.dependency 'XMLDictionary','1.4' 20 | ss.dependency 'SQLitePersistentObject','0.3.2' 21 | 22 | ss.source_files = 'DDModel/Classes/DDCache.{h,m}' 23 | end 24 | s.subspec 'HTTP' do |ss| 25 | ss.dependency 'DDModel/Categories' 26 | ss.dependency 'AFNetworking', '3.1.0' 27 | ss.dependency 'MBProgressHUD','0.9.2' 28 | 29 | ss.source_files = 'DDModel/Classes/DDModelHttpClient.{h,m}', 'DDModel/Classes/DDModelHttpClient+DDAddition.{h,m}', 'DDModel/Classes/AFHTTPSessionManager+DDModel.{h,m}' 30 | 31 | end 32 | s.subspec 'Core' do |ss| 33 | ss.dependency 'DDModel/Cache' 34 | ss.dependency 'DDModel/Categories' 35 | ss.dependency 'DDModel/HTTP' 36 | ss.dependency 'JTObjectMapping','1.1.2' 37 | 38 | ss.source_files = 'DDModel/Classes/DDModel.{h,m}', 'DDModel/Classes/DDModel+DDAddition.{h,m}' 39 | end 40 | end 41 | 42 | 43 | -------------------------------------------------------------------------------- /DDModel.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0D0F57341B9E54CA0003B890 /* DDModel+DDAddition.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D0F57311B9E54CA0003B890 /* DDModel+DDAddition.m */; }; 11 | 0D0F57351B9E54CA0003B890 /* DDModelHttpClient+DDAddition.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D0F57331B9E54CA0003B890 /* DDModelHttpClient+DDAddition.m */; }; 12 | 0D0F57381B9E6F2C0003B890 /* AFHTTPSessionManager+DDModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D0F57371B9E6F2C0003B890 /* AFHTTPSessionManager+DDModel.m */; }; 13 | 2FD44F1A1AEE21F1000A5225 /* NSURLSessionTask+DDModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2FD44F191AEE21F1000A5225 /* NSURLSessionTask+DDModel.m */; }; 14 | 88BCC5117854B98984A508B0 /* libPods-DDModel.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FA76BF80C553BA6B6EB5F51 /* libPods-DDModel.a */; }; 15 | 8E0092D61AAF232C00043C5E /* DDCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E0092D51AAF232C00043C5E /* DDCache.m */; }; 16 | 8E0092D91AAF234600043C5E /* NSString+DDModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E0092D81AAF234600043C5E /* NSString+DDModel.m */; }; 17 | 8E0B67351AAD918D0020FD73 /* NSDictionary+DDModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E0B672C1AAD918D0020FD73 /* NSDictionary+DDModel.m */; }; 18 | 8E0B67361AAD918D0020FD73 /* DDModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E0B672F1AAD918D0020FD73 /* DDModel.m */; }; 19 | 8E0B67371AAD918D0020FD73 /* DDModelHttpClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E0B67311AAD918D0020FD73 /* DDModelHttpClient.m */; }; 20 | 8E183C9A1A834B370005AB69 /* Post.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E183C991A834B370005AB69 /* Post.m */; }; 21 | 8E183C9D1A834CE30005AB69 /* adn.cer in Resources */ = {isa = PBXBuildFile; fileRef = 8E183C9B1A834CE30005AB69 /* adn.cer */; }; 22 | 8E183C9E1A834CE30005AB69 /* adn.cer in Resources */ = {isa = PBXBuildFile; fileRef = 8E183C9B1A834CE30005AB69 /* adn.cer */; }; 23 | 8E183C9F1A834CE30005AB69 /* root_ca.cer in Resources */ = {isa = PBXBuildFile; fileRef = 8E183C9C1A834CE30005AB69 /* root_ca.cer */; }; 24 | 8E183CA01A834CE30005AB69 /* root_ca.cer in Resources */ = {isa = PBXBuildFile; fileRef = 8E183C9C1A834CE30005AB69 /* root_ca.cer */; }; 25 | 8E76A7781A81FB4C00352063 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E76A7771A81FB4C00352063 /* main.m */; }; 26 | 8E76A77B1A81FB4C00352063 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E76A77A1A81FB4C00352063 /* AppDelegate.m */; }; 27 | 8E76A77E1A81FB4C00352063 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E76A77D1A81FB4C00352063 /* ViewController.m */; }; 28 | 8E76A7811A81FB4C00352063 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8E76A77F1A81FB4C00352063 /* Main.storyboard */; }; 29 | 8E76A7831A81FB4C00352063 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8E76A7821A81FB4C00352063 /* Images.xcassets */; }; 30 | 8E76A7861A81FB4C00352063 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8E76A7841A81FB4C00352063 /* LaunchScreen.xib */; }; 31 | 8E76A7921A81FB4C00352063 /* DDModelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E76A7911A81FB4C00352063 /* DDModelTests.m */; }; 32 | 8EAEA6C11ACA9B5C00C92584 /* DDModel.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 8EAEA6C01ACA9B5C00C92584 /* DDModel.podspec */; }; 33 | /* End PBXBuildFile section */ 34 | 35 | /* Begin PBXContainerItemProxy section */ 36 | 8E76A78C1A81FB4C00352063 /* PBXContainerItemProxy */ = { 37 | isa = PBXContainerItemProxy; 38 | containerPortal = 8E76A76A1A81FB4C00352063 /* Project object */; 39 | proxyType = 1; 40 | remoteGlobalIDString = 8E76A7711A81FB4C00352063; 41 | remoteInfo = DDModel; 42 | }; 43 | /* End PBXContainerItemProxy section */ 44 | 45 | /* Begin PBXFileReference section */ 46 | 0D0F57301B9E54CA0003B890 /* DDModel+DDAddition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DDModel+DDAddition.h"; sourceTree = ""; }; 47 | 0D0F57311B9E54CA0003B890 /* DDModel+DDAddition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "DDModel+DDAddition.m"; sourceTree = ""; }; 48 | 0D0F57321B9E54CA0003B890 /* DDModelHttpClient+DDAddition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DDModelHttpClient+DDAddition.h"; sourceTree = ""; }; 49 | 0D0F57331B9E54CA0003B890 /* DDModelHttpClient+DDAddition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "DDModelHttpClient+DDAddition.m"; sourceTree = ""; }; 50 | 0D0F57361B9E6F2C0003B890 /* AFHTTPSessionManager+DDModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AFHTTPSessionManager+DDModel.h"; sourceTree = ""; }; 51 | 0D0F57371B9E6F2C0003B890 /* AFHTTPSessionManager+DDModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AFHTTPSessionManager+DDModel.m"; sourceTree = ""; }; 52 | 1E9CD266D0217A7FBCE5396B /* Pods-DDModel.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DDModel.release.xcconfig"; path = "Pods/Target Support Files/Pods-DDModel/Pods-DDModel.release.xcconfig"; sourceTree = ""; }; 53 | 1FA76BF80C553BA6B6EB5F51 /* libPods-DDModel.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-DDModel.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 54 | 2FD44F181AEE21F1000A5225 /* NSURLSessionTask+DDModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLSessionTask+DDModel.h"; sourceTree = ""; }; 55 | 2FD44F191AEE21F1000A5225 /* NSURLSessionTask+DDModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLSessionTask+DDModel.m"; sourceTree = ""; }; 56 | 3A2679FEA013E7DA27406552 /* Pods-DDModel.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DDModel.debug.xcconfig"; path = "Pods/Target Support Files/Pods-DDModel/Pods-DDModel.debug.xcconfig"; sourceTree = ""; }; 57 | 8E0092D41AAF232C00043C5E /* DDCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDCache.h; sourceTree = ""; }; 58 | 8E0092D51AAF232C00043C5E /* DDCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDCache.m; sourceTree = ""; }; 59 | 8E0092D71AAF234600043C5E /* NSString+DDModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+DDModel.h"; sourceTree = ""; }; 60 | 8E0092D81AAF234600043C5E /* NSString+DDModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+DDModel.m"; sourceTree = ""; }; 61 | 8E0B672B1AAD918D0020FD73 /* NSDictionary+DDModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+DDModel.h"; sourceTree = ""; }; 62 | 8E0B672C1AAD918D0020FD73 /* NSDictionary+DDModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+DDModel.m"; sourceTree = ""; }; 63 | 8E0B672E1AAD918D0020FD73 /* DDModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDModel.h; sourceTree = ""; }; 64 | 8E0B672F1AAD918D0020FD73 /* DDModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDModel.m; sourceTree = ""; }; 65 | 8E0B67301AAD918D0020FD73 /* DDModelHttpClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDModelHttpClient.h; sourceTree = ""; }; 66 | 8E0B67311AAD918D0020FD73 /* DDModelHttpClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDModelHttpClient.m; sourceTree = ""; }; 67 | 8E0B67331AAD918D0020FD73 /* DDModelKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDModelKit.h; sourceTree = ""; }; 68 | 8E183C981A834B370005AB69 /* Post.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Post.h; sourceTree = ""; }; 69 | 8E183C991A834B370005AB69 /* Post.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Post.m; sourceTree = ""; }; 70 | 8E183C9B1A834CE30005AB69 /* adn.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = adn.cer; sourceTree = ""; }; 71 | 8E183C9C1A834CE30005AB69 /* root_ca.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = root_ca.cer; sourceTree = ""; }; 72 | 8E76A7721A81FB4C00352063 /* DDModel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DDModel.app; sourceTree = BUILT_PRODUCTS_DIR; }; 73 | 8E76A7761A81FB4C00352063 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 74 | 8E76A7771A81FB4C00352063 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 75 | 8E76A7791A81FB4C00352063 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 76 | 8E76A77A1A81FB4C00352063 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 77 | 8E76A77C1A81FB4C00352063 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 78 | 8E76A77D1A81FB4C00352063 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 79 | 8E76A7801A81FB4C00352063 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 80 | 8E76A7821A81FB4C00352063 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 81 | 8E76A7851A81FB4C00352063 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 82 | 8E76A78B1A81FB4C00352063 /* DDModelTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DDModelTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 83 | 8E76A7901A81FB4C00352063 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 84 | 8E76A7911A81FB4C00352063 /* DDModelTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DDModelTests.m; sourceTree = ""; }; 85 | 8EAEA6C01ACA9B5C00C92584 /* DDModel.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DDModel.podspec; sourceTree = ""; }; 86 | /* End PBXFileReference section */ 87 | 88 | /* Begin PBXFrameworksBuildPhase section */ 89 | 8E76A76F1A81FB4C00352063 /* Frameworks */ = { 90 | isa = PBXFrameworksBuildPhase; 91 | buildActionMask = 2147483647; 92 | files = ( 93 | 88BCC5117854B98984A508B0 /* libPods-DDModel.a in Frameworks */, 94 | ); 95 | runOnlyForDeploymentPostprocessing = 0; 96 | }; 97 | 8E76A7881A81FB4C00352063 /* Frameworks */ = { 98 | isa = PBXFrameworksBuildPhase; 99 | buildActionMask = 2147483647; 100 | files = ( 101 | ); 102 | runOnlyForDeploymentPostprocessing = 0; 103 | }; 104 | /* End PBXFrameworksBuildPhase section */ 105 | 106 | /* Begin PBXGroup section */ 107 | 29F0A2E41C6BB4F20F5C363B /* Frameworks */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 1FA76BF80C553BA6B6EB5F51 /* libPods-DDModel.a */, 111 | ); 112 | name = Frameworks; 113 | sourceTree = ""; 114 | }; 115 | 8E0B672D1AAD918D0020FD73 /* Category */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 0D0F57301B9E54CA0003B890 /* DDModel+DDAddition.h */, 119 | 0D0F57311B9E54CA0003B890 /* DDModel+DDAddition.m */, 120 | 0D0F57321B9E54CA0003B890 /* DDModelHttpClient+DDAddition.h */, 121 | 0D0F57331B9E54CA0003B890 /* DDModelHttpClient+DDAddition.m */, 122 | 8E0B672B1AAD918D0020FD73 /* NSDictionary+DDModel.h */, 123 | 8E0B672C1AAD918D0020FD73 /* NSDictionary+DDModel.m */, 124 | 8E0092D71AAF234600043C5E /* NSString+DDModel.h */, 125 | 8E0092D81AAF234600043C5E /* NSString+DDModel.m */, 126 | 2FD44F181AEE21F1000A5225 /* NSURLSessionTask+DDModel.h */, 127 | 2FD44F191AEE21F1000A5225 /* NSURLSessionTask+DDModel.m */, 128 | 0D0F57361B9E6F2C0003B890 /* AFHTTPSessionManager+DDModel.h */, 129 | 0D0F57371B9E6F2C0003B890 /* AFHTTPSessionManager+DDModel.m */, 130 | ); 131 | name = Category; 132 | sourceTree = ""; 133 | }; 134 | 8E0B67321AAD918D0020FD73 /* Core */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | 8E0092D41AAF232C00043C5E /* DDCache.h */, 138 | 8E0092D51AAF232C00043C5E /* DDCache.m */, 139 | 8E0B672E1AAD918D0020FD73 /* DDModel.h */, 140 | 8E0B672F1AAD918D0020FD73 /* DDModel.m */, 141 | 8E0B67301AAD918D0020FD73 /* DDModelHttpClient.h */, 142 | 8E0B67311AAD918D0020FD73 /* DDModelHttpClient.m */, 143 | ); 144 | name = Core; 145 | sourceTree = ""; 146 | }; 147 | 8E0B67341AAD918D0020FD73 /* Classes */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | 8E0B672D1AAD918D0020FD73 /* Category */, 151 | 8E0B67321AAD918D0020FD73 /* Core */, 152 | 8E0B67331AAD918D0020FD73 /* DDModelKit.h */, 153 | ); 154 | path = Classes; 155 | sourceTree = ""; 156 | }; 157 | 8E76A7691A81FB4C00352063 = { 158 | isa = PBXGroup; 159 | children = ( 160 | 8EAEA6C01ACA9B5C00C92584 /* DDModel.podspec */, 161 | 8E76A7741A81FB4C00352063 /* DDModel */, 162 | 8E76A78E1A81FB4C00352063 /* DDModelTests */, 163 | 8E76A7731A81FB4C00352063 /* Products */, 164 | D38B5A4C56AD3EB6BC697777 /* Pods */, 165 | 29F0A2E41C6BB4F20F5C363B /* Frameworks */, 166 | ); 167 | sourceTree = ""; 168 | }; 169 | 8E76A7731A81FB4C00352063 /* Products */ = { 170 | isa = PBXGroup; 171 | children = ( 172 | 8E76A7721A81FB4C00352063 /* DDModel.app */, 173 | 8E76A78B1A81FB4C00352063 /* DDModelTests.xctest */, 174 | ); 175 | name = Products; 176 | sourceTree = ""; 177 | }; 178 | 8E76A7741A81FB4C00352063 /* DDModel */ = { 179 | isa = PBXGroup; 180 | children = ( 181 | 8E0B67341AAD918D0020FD73 /* Classes */, 182 | 8E76A7791A81FB4C00352063 /* AppDelegate.h */, 183 | 8E76A77A1A81FB4C00352063 /* AppDelegate.m */, 184 | 8E76A77C1A81FB4C00352063 /* ViewController.h */, 185 | 8E76A77D1A81FB4C00352063 /* ViewController.m */, 186 | 8E76A77F1A81FB4C00352063 /* Main.storyboard */, 187 | 8E76A7821A81FB4C00352063 /* Images.xcassets */, 188 | 8E76A7841A81FB4C00352063 /* LaunchScreen.xib */, 189 | 8E76A7751A81FB4C00352063 /* Supporting Files */, 190 | 8E183C981A834B370005AB69 /* Post.h */, 191 | 8E183C991A834B370005AB69 /* Post.m */, 192 | ); 193 | path = DDModel; 194 | sourceTree = ""; 195 | }; 196 | 8E76A7751A81FB4C00352063 /* Supporting Files */ = { 197 | isa = PBXGroup; 198 | children = ( 199 | 8E183C9B1A834CE30005AB69 /* adn.cer */, 200 | 8E183C9C1A834CE30005AB69 /* root_ca.cer */, 201 | 8E76A7761A81FB4C00352063 /* Info.plist */, 202 | 8E76A7771A81FB4C00352063 /* main.m */, 203 | ); 204 | name = "Supporting Files"; 205 | sourceTree = ""; 206 | }; 207 | 8E76A78E1A81FB4C00352063 /* DDModelTests */ = { 208 | isa = PBXGroup; 209 | children = ( 210 | 8E76A7911A81FB4C00352063 /* DDModelTests.m */, 211 | 8E76A78F1A81FB4C00352063 /* Supporting Files */, 212 | ); 213 | path = DDModelTests; 214 | sourceTree = ""; 215 | }; 216 | 8E76A78F1A81FB4C00352063 /* Supporting Files */ = { 217 | isa = PBXGroup; 218 | children = ( 219 | 8E76A7901A81FB4C00352063 /* Info.plist */, 220 | ); 221 | name = "Supporting Files"; 222 | sourceTree = ""; 223 | }; 224 | D38B5A4C56AD3EB6BC697777 /* Pods */ = { 225 | isa = PBXGroup; 226 | children = ( 227 | 3A2679FEA013E7DA27406552 /* Pods-DDModel.debug.xcconfig */, 228 | 1E9CD266D0217A7FBCE5396B /* Pods-DDModel.release.xcconfig */, 229 | ); 230 | name = Pods; 231 | sourceTree = ""; 232 | }; 233 | /* End PBXGroup section */ 234 | 235 | /* Begin PBXNativeTarget section */ 236 | 8E76A7711A81FB4C00352063 /* DDModel */ = { 237 | isa = PBXNativeTarget; 238 | buildConfigurationList = 8E76A7951A81FB4C00352063 /* Build configuration list for PBXNativeTarget "DDModel" */; 239 | buildPhases = ( 240 | 5FDFFB2CF77677D1EC976991 /* [CP] Check Pods Manifest.lock */, 241 | 8E76A76E1A81FB4C00352063 /* Sources */, 242 | 8E76A76F1A81FB4C00352063 /* Frameworks */, 243 | 8E76A7701A81FB4C00352063 /* Resources */, 244 | 175E17671BA65E53D4EDAF8E /* [CP] Embed Pods Frameworks */, 245 | 2B1865C3C4F79BD467F87A49 /* [CP] Copy Pods Resources */, 246 | ); 247 | buildRules = ( 248 | ); 249 | dependencies = ( 250 | ); 251 | name = DDModel; 252 | productName = DDModel; 253 | productReference = 8E76A7721A81FB4C00352063 /* DDModel.app */; 254 | productType = "com.apple.product-type.application"; 255 | }; 256 | 8E76A78A1A81FB4C00352063 /* DDModelTests */ = { 257 | isa = PBXNativeTarget; 258 | buildConfigurationList = 8E76A7981A81FB4C00352063 /* Build configuration list for PBXNativeTarget "DDModelTests" */; 259 | buildPhases = ( 260 | 8E76A7871A81FB4C00352063 /* Sources */, 261 | 8E76A7881A81FB4C00352063 /* Frameworks */, 262 | 8E76A7891A81FB4C00352063 /* Resources */, 263 | ); 264 | buildRules = ( 265 | ); 266 | dependencies = ( 267 | 8E76A78D1A81FB4C00352063 /* PBXTargetDependency */, 268 | ); 269 | name = DDModelTests; 270 | productName = DDModelTests; 271 | productReference = 8E76A78B1A81FB4C00352063 /* DDModelTests.xctest */; 272 | productType = "com.apple.product-type.bundle.unit-test"; 273 | }; 274 | /* End PBXNativeTarget section */ 275 | 276 | /* Begin PBXProject section */ 277 | 8E76A76A1A81FB4C00352063 /* Project object */ = { 278 | isa = PBXProject; 279 | attributes = { 280 | LastUpgradeCheck = 0720; 281 | ORGANIZATIONNAME = DDKit; 282 | TargetAttributes = { 283 | 8E76A7711A81FB4C00352063 = { 284 | CreatedOnToolsVersion = 6.1.1; 285 | }; 286 | 8E76A78A1A81FB4C00352063 = { 287 | CreatedOnToolsVersion = 6.1.1; 288 | TestTargetID = 8E76A7711A81FB4C00352063; 289 | }; 290 | }; 291 | }; 292 | buildConfigurationList = 8E76A76D1A81FB4C00352063 /* Build configuration list for PBXProject "DDModel" */; 293 | compatibilityVersion = "Xcode 3.2"; 294 | developmentRegion = English; 295 | hasScannedForEncodings = 0; 296 | knownRegions = ( 297 | en, 298 | Base, 299 | ); 300 | mainGroup = 8E76A7691A81FB4C00352063; 301 | productRefGroup = 8E76A7731A81FB4C00352063 /* Products */; 302 | projectDirPath = ""; 303 | projectRoot = ""; 304 | targets = ( 305 | 8E76A7711A81FB4C00352063 /* DDModel */, 306 | 8E76A78A1A81FB4C00352063 /* DDModelTests */, 307 | ); 308 | }; 309 | /* End PBXProject section */ 310 | 311 | /* Begin PBXResourcesBuildPhase section */ 312 | 8E76A7701A81FB4C00352063 /* Resources */ = { 313 | isa = PBXResourcesBuildPhase; 314 | buildActionMask = 2147483647; 315 | files = ( 316 | 8EAEA6C11ACA9B5C00C92584 /* DDModel.podspec in Resources */, 317 | 8E76A7811A81FB4C00352063 /* Main.storyboard in Resources */, 318 | 8E76A7861A81FB4C00352063 /* LaunchScreen.xib in Resources */, 319 | 8E183C9F1A834CE30005AB69 /* root_ca.cer in Resources */, 320 | 8E183C9D1A834CE30005AB69 /* adn.cer in Resources */, 321 | 8E76A7831A81FB4C00352063 /* Images.xcassets in Resources */, 322 | ); 323 | runOnlyForDeploymentPostprocessing = 0; 324 | }; 325 | 8E76A7891A81FB4C00352063 /* Resources */ = { 326 | isa = PBXResourcesBuildPhase; 327 | buildActionMask = 2147483647; 328 | files = ( 329 | 8E183CA01A834CE30005AB69 /* root_ca.cer in Resources */, 330 | 8E183C9E1A834CE30005AB69 /* adn.cer in Resources */, 331 | ); 332 | runOnlyForDeploymentPostprocessing = 0; 333 | }; 334 | /* End PBXResourcesBuildPhase section */ 335 | 336 | /* Begin PBXShellScriptBuildPhase section */ 337 | 175E17671BA65E53D4EDAF8E /* [CP] Embed Pods Frameworks */ = { 338 | isa = PBXShellScriptBuildPhase; 339 | buildActionMask = 2147483647; 340 | files = ( 341 | ); 342 | inputPaths = ( 343 | ); 344 | name = "[CP] Embed Pods Frameworks"; 345 | outputPaths = ( 346 | ); 347 | runOnlyForDeploymentPostprocessing = 0; 348 | shellPath = /bin/sh; 349 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-DDModel/Pods-DDModel-frameworks.sh\"\n"; 350 | showEnvVarsInLog = 0; 351 | }; 352 | 2B1865C3C4F79BD467F87A49 /* [CP] Copy Pods Resources */ = { 353 | isa = PBXShellScriptBuildPhase; 354 | buildActionMask = 2147483647; 355 | files = ( 356 | ); 357 | inputPaths = ( 358 | ); 359 | name = "[CP] Copy Pods Resources"; 360 | outputPaths = ( 361 | ); 362 | runOnlyForDeploymentPostprocessing = 0; 363 | shellPath = /bin/sh; 364 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-DDModel/Pods-DDModel-resources.sh\"\n"; 365 | showEnvVarsInLog = 0; 366 | }; 367 | 5FDFFB2CF77677D1EC976991 /* [CP] Check Pods Manifest.lock */ = { 368 | isa = PBXShellScriptBuildPhase; 369 | buildActionMask = 2147483647; 370 | files = ( 371 | ); 372 | inputPaths = ( 373 | ); 374 | name = "[CP] Check Pods Manifest.lock"; 375 | outputPaths = ( 376 | ); 377 | runOnlyForDeploymentPostprocessing = 0; 378 | shellPath = /bin/sh; 379 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 380 | showEnvVarsInLog = 0; 381 | }; 382 | /* End PBXShellScriptBuildPhase section */ 383 | 384 | /* Begin PBXSourcesBuildPhase section */ 385 | 8E76A76E1A81FB4C00352063 /* Sources */ = { 386 | isa = PBXSourcesBuildPhase; 387 | buildActionMask = 2147483647; 388 | files = ( 389 | 2FD44F1A1AEE21F1000A5225 /* NSURLSessionTask+DDModel.m in Sources */, 390 | 8E0092D61AAF232C00043C5E /* DDCache.m in Sources */, 391 | 8E76A77E1A81FB4C00352063 /* ViewController.m in Sources */, 392 | 8E0B67361AAD918D0020FD73 /* DDModel.m in Sources */, 393 | 0D0F57351B9E54CA0003B890 /* DDModelHttpClient+DDAddition.m in Sources */, 394 | 0D0F57341B9E54CA0003B890 /* DDModel+DDAddition.m in Sources */, 395 | 8E76A77B1A81FB4C00352063 /* AppDelegate.m in Sources */, 396 | 8E0B67351AAD918D0020FD73 /* NSDictionary+DDModel.m in Sources */, 397 | 8E76A7781A81FB4C00352063 /* main.m in Sources */, 398 | 0D0F57381B9E6F2C0003B890 /* AFHTTPSessionManager+DDModel.m in Sources */, 399 | 8E0092D91AAF234600043C5E /* NSString+DDModel.m in Sources */, 400 | 8E0B67371AAD918D0020FD73 /* DDModelHttpClient.m in Sources */, 401 | 8E183C9A1A834B370005AB69 /* Post.m in Sources */, 402 | ); 403 | runOnlyForDeploymentPostprocessing = 0; 404 | }; 405 | 8E76A7871A81FB4C00352063 /* Sources */ = { 406 | isa = PBXSourcesBuildPhase; 407 | buildActionMask = 2147483647; 408 | files = ( 409 | 8E76A7921A81FB4C00352063 /* DDModelTests.m in Sources */, 410 | ); 411 | runOnlyForDeploymentPostprocessing = 0; 412 | }; 413 | /* End PBXSourcesBuildPhase section */ 414 | 415 | /* Begin PBXTargetDependency section */ 416 | 8E76A78D1A81FB4C00352063 /* PBXTargetDependency */ = { 417 | isa = PBXTargetDependency; 418 | target = 8E76A7711A81FB4C00352063 /* DDModel */; 419 | targetProxy = 8E76A78C1A81FB4C00352063 /* PBXContainerItemProxy */; 420 | }; 421 | /* End PBXTargetDependency section */ 422 | 423 | /* Begin PBXVariantGroup section */ 424 | 8E76A77F1A81FB4C00352063 /* Main.storyboard */ = { 425 | isa = PBXVariantGroup; 426 | children = ( 427 | 8E76A7801A81FB4C00352063 /* Base */, 428 | ); 429 | name = Main.storyboard; 430 | sourceTree = ""; 431 | }; 432 | 8E76A7841A81FB4C00352063 /* LaunchScreen.xib */ = { 433 | isa = PBXVariantGroup; 434 | children = ( 435 | 8E76A7851A81FB4C00352063 /* Base */, 436 | ); 437 | name = LaunchScreen.xib; 438 | sourceTree = ""; 439 | }; 440 | /* End PBXVariantGroup section */ 441 | 442 | /* Begin XCBuildConfiguration section */ 443 | 8E76A7931A81FB4C00352063 /* Debug */ = { 444 | isa = XCBuildConfiguration; 445 | buildSettings = { 446 | ALWAYS_SEARCH_USER_PATHS = NO; 447 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 448 | CLANG_CXX_LIBRARY = "libc++"; 449 | CLANG_ENABLE_MODULES = YES; 450 | CLANG_ENABLE_OBJC_ARC = YES; 451 | CLANG_WARN_BOOL_CONVERSION = YES; 452 | CLANG_WARN_CONSTANT_CONVERSION = YES; 453 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 454 | CLANG_WARN_EMPTY_BODY = YES; 455 | CLANG_WARN_ENUM_CONVERSION = YES; 456 | CLANG_WARN_INT_CONVERSION = YES; 457 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 458 | CLANG_WARN_UNREACHABLE_CODE = YES; 459 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 460 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 461 | COPY_PHASE_STRIP = NO; 462 | ENABLE_STRICT_OBJC_MSGSEND = YES; 463 | ENABLE_TESTABILITY = YES; 464 | GCC_C_LANGUAGE_STANDARD = gnu99; 465 | GCC_DYNAMIC_NO_PIC = NO; 466 | GCC_OPTIMIZATION_LEVEL = 0; 467 | GCC_PREPROCESSOR_DEFINITIONS = ( 468 | "DEBUG=1", 469 | "$(inherited)", 470 | ); 471 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 472 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 473 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 474 | GCC_WARN_UNDECLARED_SELECTOR = YES; 475 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 476 | GCC_WARN_UNUSED_FUNCTION = YES; 477 | GCC_WARN_UNUSED_VARIABLE = YES; 478 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 479 | MTL_ENABLE_DEBUG_INFO = YES; 480 | ONLY_ACTIVE_ARCH = YES; 481 | SDKROOT = iphoneos; 482 | }; 483 | name = Debug; 484 | }; 485 | 8E76A7941A81FB4C00352063 /* Release */ = { 486 | isa = XCBuildConfiguration; 487 | buildSettings = { 488 | ALWAYS_SEARCH_USER_PATHS = NO; 489 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 490 | CLANG_CXX_LIBRARY = "libc++"; 491 | CLANG_ENABLE_MODULES = YES; 492 | CLANG_ENABLE_OBJC_ARC = YES; 493 | CLANG_WARN_BOOL_CONVERSION = YES; 494 | CLANG_WARN_CONSTANT_CONVERSION = YES; 495 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 496 | CLANG_WARN_EMPTY_BODY = YES; 497 | CLANG_WARN_ENUM_CONVERSION = YES; 498 | CLANG_WARN_INT_CONVERSION = YES; 499 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 500 | CLANG_WARN_UNREACHABLE_CODE = YES; 501 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 502 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 503 | COPY_PHASE_STRIP = YES; 504 | ENABLE_NS_ASSERTIONS = NO; 505 | ENABLE_STRICT_OBJC_MSGSEND = YES; 506 | GCC_C_LANGUAGE_STANDARD = gnu99; 507 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 508 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 509 | GCC_WARN_UNDECLARED_SELECTOR = YES; 510 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 511 | GCC_WARN_UNUSED_FUNCTION = YES; 512 | GCC_WARN_UNUSED_VARIABLE = YES; 513 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 514 | MTL_ENABLE_DEBUG_INFO = NO; 515 | SDKROOT = iphoneos; 516 | VALIDATE_PRODUCT = YES; 517 | }; 518 | name = Release; 519 | }; 520 | 8E76A7961A81FB4C00352063 /* Debug */ = { 521 | isa = XCBuildConfiguration; 522 | baseConfigurationReference = 3A2679FEA013E7DA27406552 /* Pods-DDModel.debug.xcconfig */; 523 | buildSettings = { 524 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 525 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 526 | INFOPLIST_FILE = DDModel/Info.plist; 527 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 528 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 529 | PRODUCT_BUNDLE_IDENTIFIER = "com.ddkit.$(PRODUCT_NAME:rfc1034identifier)"; 530 | PRODUCT_NAME = "$(TARGET_NAME)"; 531 | }; 532 | name = Debug; 533 | }; 534 | 8E76A7971A81FB4C00352063 /* Release */ = { 535 | isa = XCBuildConfiguration; 536 | baseConfigurationReference = 1E9CD266D0217A7FBCE5396B /* Pods-DDModel.release.xcconfig */; 537 | buildSettings = { 538 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 539 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 540 | INFOPLIST_FILE = DDModel/Info.plist; 541 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 542 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 543 | PRODUCT_BUNDLE_IDENTIFIER = "com.ddkit.$(PRODUCT_NAME:rfc1034identifier)"; 544 | PRODUCT_NAME = "$(TARGET_NAME)"; 545 | }; 546 | name = Release; 547 | }; 548 | 8E76A7991A81FB4C00352063 /* Debug */ = { 549 | isa = XCBuildConfiguration; 550 | buildSettings = { 551 | BUNDLE_LOADER = "$(TEST_HOST)"; 552 | FRAMEWORK_SEARCH_PATHS = ( 553 | "$(PLATFORM_DIR)/Developer/Library/Frameworks", 554 | "$(inherited)", 555 | ); 556 | GCC_PREPROCESSOR_DEFINITIONS = ( 557 | "DEBUG=1", 558 | "$(inherited)", 559 | ); 560 | INFOPLIST_FILE = DDModelTests/Info.plist; 561 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 562 | PRODUCT_BUNDLE_IDENTIFIER = "com.ddkit.$(PRODUCT_NAME:rfc1034identifier)"; 563 | PRODUCT_NAME = "$(TARGET_NAME)"; 564 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DDModel.app/DDModel"; 565 | }; 566 | name = Debug; 567 | }; 568 | 8E76A79A1A81FB4C00352063 /* Release */ = { 569 | isa = XCBuildConfiguration; 570 | buildSettings = { 571 | BUNDLE_LOADER = "$(TEST_HOST)"; 572 | FRAMEWORK_SEARCH_PATHS = ( 573 | "$(PLATFORM_DIR)/Developer/Library/Frameworks", 574 | "$(inherited)", 575 | ); 576 | INFOPLIST_FILE = DDModelTests/Info.plist; 577 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 578 | PRODUCT_BUNDLE_IDENTIFIER = "com.ddkit.$(PRODUCT_NAME:rfc1034identifier)"; 579 | PRODUCT_NAME = "$(TARGET_NAME)"; 580 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DDModel.app/DDModel"; 581 | }; 582 | name = Release; 583 | }; 584 | /* End XCBuildConfiguration section */ 585 | 586 | /* Begin XCConfigurationList section */ 587 | 8E76A76D1A81FB4C00352063 /* Build configuration list for PBXProject "DDModel" */ = { 588 | isa = XCConfigurationList; 589 | buildConfigurations = ( 590 | 8E76A7931A81FB4C00352063 /* Debug */, 591 | 8E76A7941A81FB4C00352063 /* Release */, 592 | ); 593 | defaultConfigurationIsVisible = 0; 594 | defaultConfigurationName = Release; 595 | }; 596 | 8E76A7951A81FB4C00352063 /* Build configuration list for PBXNativeTarget "DDModel" */ = { 597 | isa = XCConfigurationList; 598 | buildConfigurations = ( 599 | 8E76A7961A81FB4C00352063 /* Debug */, 600 | 8E76A7971A81FB4C00352063 /* Release */, 601 | ); 602 | defaultConfigurationIsVisible = 0; 603 | defaultConfigurationName = Release; 604 | }; 605 | 8E76A7981A81FB4C00352063 /* Build configuration list for PBXNativeTarget "DDModelTests" */ = { 606 | isa = XCConfigurationList; 607 | buildConfigurations = ( 608 | 8E76A7991A81FB4C00352063 /* Debug */, 609 | 8E76A79A1A81FB4C00352063 /* Release */, 610 | ); 611 | defaultConfigurationIsVisible = 0; 612 | defaultConfigurationName = Release; 613 | }; 614 | /* End XCConfigurationList section */ 615 | }; 616 | rootObject = 8E76A76A1A81FB4C00352063 /* Project object */; 617 | } 618 | -------------------------------------------------------------------------------- /DDModel/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define UseXMLDemo 0 12 | 13 | @interface AppDelegate : UIResponder 14 | 15 | @property (strong, nonatomic) UIWindow *window; 16 | 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /DDModel/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "DDModelKit.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | // Override point for customization after application launch. 21 | 22 | #if UseXMLDemo 23 | [DDModelHttpClient startWithURL:@"http://prov.mobile.arnd.fm" delegate:self]; 24 | [DDModelHttpClient sharedInstance].type = DDResponseXML; 25 | #else 26 | [DDModelHttpClient startWithURL:@"http://mapi.bstapp.cn" delegate:self]; 27 | #endif 28 | 29 | return YES; 30 | } 31 | 32 | - (void)applicationWillResignActive:(UIApplication *)application { 33 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 34 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 35 | } 36 | 37 | - (void)applicationDidEnterBackground:(UIApplication *)application { 38 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 39 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 40 | } 41 | 42 | - (void)applicationWillEnterForeground:(UIApplication *)application { 43 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 44 | } 45 | 46 | - (void)applicationDidBecomeActive:(UIApplication *)application { 47 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 48 | } 49 | 50 | - (void)applicationWillTerminate:(UIApplication *)application { 51 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 52 | } 53 | 54 | #pragma mark - DDClient Delegate Methods 55 | 56 | - (NSDictionary *)encodeParameters:(NSDictionary *)params{ 57 | // handler the encode parameters 58 | //// TODO 59 | return params; 60 | } 61 | 62 | - (NSString *)decodeResponseString:(NSString *)responseString{ 63 | // NSLog(@"responseString = %@",responseString); 64 | return responseString; 65 | } 66 | 67 | 68 | #pragma mark - Custom Methods 69 | 70 | - (NSString *)ddEncode:(NSDictionary *)parameters{ 71 | NSMutableArray *strings = [[NSMutableArray alloc] init]; 72 | for (id key in [parameters.allKeys 73 | sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) 74 | { 75 | return [obj1 compare:obj2 options:NSNumericSearch]; 76 | }] 77 | ) { 78 | [strings addObject:[NSString stringWithFormat:@"%@=%@",key,parameters[key]]]; 79 | } 80 | return [strings componentsJoinedByString:@"&"]; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /DDModel/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /DDModel/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /DDModel/Classes/AFHTTPSessionManager+DDModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // AFHTTPSessionManager+DDModel.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15/9/8. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "AFHTTPSessionManager.h" 10 | 11 | @interface AFHTTPSessionManager (DDModel) 12 | 13 | /** 14 | * Dynomic replace the url 15 | * 16 | * @param url target url 17 | */ 18 | - (void)dd_exchangeURL:(NSString *)url; 19 | 20 | /** 21 | * Add a new url into http client 22 | * 23 | * @param url target url 24 | */ 25 | - (void)dd_addURL:(NSString *)url; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /DDModel/Classes/AFHTTPSessionManager+DDModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // AFHTTPSessionManager+DDModel.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15/9/8. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "AFHTTPSessionManager+DDModel.h" 10 | #import 11 | 12 | @interface AFHTTPSessionManager() 13 | 14 | @property (nonatomic, strong, readwrite) NSMutableArray *urls; 15 | 16 | @end 17 | 18 | @implementation AFHTTPSessionManager (DDModel) 19 | 20 | #pragma mark - replace methods 21 | 22 | + (void)load { 23 | 24 | SEL selectors[] = { 25 | @selector(baseURL) 26 | }; 27 | 28 | for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) { 29 | SEL originalSelector = selectors[index]; 30 | SEL swizzledSelector = NSSelectorFromString([@"dd_" stringByAppendingString:NSStringFromSelector(originalSelector)]); 31 | 32 | Method originalMethod = class_getInstanceMethod(self, originalSelector); 33 | Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector); 34 | 35 | method_exchangeImplementations(originalMethod, swizzledMethod); 36 | } 37 | } 38 | 39 | - (NSURL *)dd_baseURL { 40 | NSString *url = self.urls[0]; 41 | if ([url rangeOfString:@"http"].location == NSNotFound) { 42 | url = [NSString stringWithFormat:@"http://%@",url]; 43 | } 44 | return [NSURL URLWithString:url]; 45 | } 46 | 47 | #pragma mark - runtime methods 48 | 49 | - (NSMutableArray *)urls { 50 | return objc_getAssociatedObject(self, _cmd); 51 | } 52 | 53 | - (void)setUrls:(NSMutableArray *)urls { 54 | objc_setAssociatedObject(self, @selector(urls), urls, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 55 | } 56 | 57 | - (BOOL)hasHttpsPrefix { 58 | return [objc_getAssociatedObject(self, _cmd) boolValue]; 59 | } 60 | 61 | - (void)setHasHttpsPrefix:(BOOL)hasHttpsPrefix { 62 | objc_setAssociatedObject(self, @selector(hasHttpsPrefix), @(hasHttpsPrefix), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 63 | } 64 | 65 | #pragma mark - Private Methods 66 | 67 | - (void)dd_exchangeURL:(NSString *)url { 68 | self.hasHttpsPrefix = NO; 69 | if ([url hasPrefix:@"https"]) { 70 | self.hasHttpsPrefix = YES; 71 | } 72 | if ([self.urls containsObject:url]) { 73 | [self.urls exchangeObjectAtIndex:0 withObjectAtIndex:[self.urls indexOfObject:url]]; 74 | } else { 75 | if (!self.urls) { 76 | self.urls = [NSMutableArray new]; 77 | } 78 | [self.urls insertObject:url atIndex:0]; 79 | } 80 | } 81 | 82 | - (void)dd_addURL:(NSString *)url{ 83 | if (!self.urls) { 84 | self.urls = [NSMutableArray new]; 85 | } 86 | if ([url hasPrefix:@"https"]) { 87 | self.hasHttpsPrefix = YES; 88 | } 89 | if ([self.urls containsObject:url]) { 90 | [self dd_exchangeURL:url]; 91 | return; 92 | } 93 | [self.urls insertObject:url atIndex:0]; 94 | } 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /DDModel/Classes/DDCache.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDCache.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-3-10. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "SQLitePersistentObject.h" 10 | 11 | @interface DDCache : SQLitePersistentObject 12 | 13 | @property (nonatomic, copy) NSString *path; 14 | @property (nonatomic, copy) NSString *content; 15 | @property (nonatomic, copy) NSString *parameter; 16 | 17 | /** 18 | * Query the cache from db 19 | * 20 | * @param path url path 21 | * @param parameter request parameter 22 | * @param result DDCache object 23 | */ 24 | + (void)queryWithPath:(NSString *)path 25 | parameter:(NSDictionary *)parameter 26 | result:(DBQueryResult)result; 27 | 28 | /** 29 | * Initialize a DDCache object 30 | * 31 | * @param path url 32 | * @param parameter request parameter 33 | * @param content should cahced content 34 | * 35 | * @return DDCache object 36 | */ 37 | - (instancetype)initWithPath:(NSString *)path 38 | parameter:(NSDictionary *)parameter 39 | content:(id)content; 40 | 41 | /** 42 | * Save a DDCache Object 43 | * 44 | * @param path url 45 | * @param parameter request parameter 46 | * @param content should cahced content 47 | */ 48 | + (void)cacheWithPath:(NSString *)path 49 | parameter:(NSDictionary *)parameter 50 | content:(id)content; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /DDModel/Classes/DDCache.m: -------------------------------------------------------------------------------- 1 | // 2 | // DDCache.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-3-10. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "DDCache.h" 10 | #import "NSDictionary+DDModel.h" 11 | #import "NSString+DDModel.h" 12 | #import "XMLDictionary.h" 13 | 14 | @implementation DDCache 15 | 16 | + (void)queryWithPath:(NSString *)path 17 | parameter:(NSDictionary *)parameter 18 | result:(DBQueryResult)result { 19 | NSString *queryParameter = [NSString stringWithFormat:@"WHERE parameter = '%@' AND path = '%@';",[[parameter dd_jsonString] dd_cacheMD5], [path dd_cacheMD5]]; 20 | [[self class] queryFirstItemByCriteria:queryParameter 21 | result:result]; 22 | } 23 | 24 | - (instancetype)initWithPath:(NSString *)path 25 | parameter:(NSDictionary *)parameter 26 | content:(id)content { 27 | self = [super init]; 28 | if (self) { 29 | self.path = [path dd_cacheMD5]; 30 | self.content = [[self class] contentHandler:content]; 31 | self.parameter = [[parameter dd_jsonString] dd_cacheMD5]; 32 | } 33 | return self; 34 | } 35 | 36 | + (void)cacheWithPath:(NSString *)path 37 | parameter:(NSDictionary *)parameter 38 | content:(id)content { 39 | [self queryWithPath:path parameter:parameter result:^(id data) { 40 | DDCache *cache = data; 41 | if (!cache) 42 | cache = [[DDCache alloc] initWithPath:path 43 | parameter:parameter 44 | content:content]; 45 | cache.content = [self contentHandler:content]; 46 | [cache save]; 47 | }]; 48 | } 49 | 50 | + (NSString *)contentHandler:(id)content { 51 | if ([content isKindOfClass:[NSString class]]) { 52 | return content; 53 | } else if ([content isKindOfClass:[NSDictionary class]]) { 54 | return [content dd_jsonString]; 55 | } else if([content isKindOfClass:[NSXMLParser class]]) { 56 | NSDictionary *jsonDict = [NSDictionary dictionaryWithXMLParser:content]; 57 | return [jsonDict dd_jsonString]; 58 | } 59 | return @""; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /DDModel/Classes/DDModel+DDAddition.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDModel+DDAddition.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15/6/3. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "DDModel.h" 10 | 11 | @interface DDModel (DDAddition) 12 | 13 | /** 14 | * Get json data first from db cache then from http server by HTTP GET Mehod. 15 | * 16 | * @param path HTTP Path 17 | * @param params GET Paramtters 18 | * @param show is show the HUD on the view 19 | * @param viewController parentViewController 20 | * @param dbResult db cache result block 21 | * @param successBlock success block 22 | * @param failureBlock failre block 23 | */ 24 | + (void)get:(NSString *)path 25 | params:(id)params 26 | showHUD:(BOOL)show 27 | parentViewController:(id)viewController 28 | dbSuccess:(DDSQLiteBlock)dbResult 29 | successBlock:(DDResponseSuccessBlock)success 30 | failureBlock:(DDResponsesFailureBlock)failure; 31 | 32 | /** 33 | * Get json data first from db cache then from http server by HTTP POST Mehod. 34 | * 35 | * @param path HTTP Path 36 | * @param params GET Paramtters 37 | * @param show is show the HUD on the view 38 | * @param viewController parentViewController 39 | * @param dbResult db cache result block 40 | * @param successBlock success block 41 | * @param failureBlock failre block 42 | * 43 | */ 44 | + (void)post:(NSString *)path 45 | params:(id)params 46 | showHUD:(BOOL)show 47 | parentViewController:(id)viewController 48 | dbSuccess:(DDSQLiteBlock)dbResult 49 | successBlock:(DDResponseSuccessBlock)success 50 | failureBlock:(DDResponsesFailureBlock)failure; 51 | 52 | /** 53 | * Get json data from http server by HTTP GET Mehod. 54 | * 55 | * @param path HTTP Path 56 | * @param params GET Paramtters 57 | * @param show is show the HUD on the view 58 | * @param viewController parentViewController 59 | * @param successBlock success block 60 | * @param failureBlock failre block 61 | * 62 | */ 63 | + (void)get:(NSString *)path 64 | params:(id)params 65 | showHUD:(BOOL)show 66 | parentViewController:(id)viewController 67 | successBlock:(DDResponseSuccessBlock)success 68 | failureBlock:(DDResponsesFailureBlock)failure; 69 | 70 | /** 71 | * Get json data from http server by HTTP POST Mehod. 72 | * 73 | * @param path HTTP Path 74 | * @param params GET Paramtters 75 | * @param show is show the HUD on the view 76 | * @param viewController parentViewController 77 | * @param successBlock success block 78 | * @param failureBlock failre block 79 | * 80 | */ 81 | + (void)post:(NSString *)path 82 | params:(id)params 83 | showHUD:(BOOL)show 84 | parentViewController:(id)viewController 85 | successBlock:(DDResponseSuccessBlock)success 86 | failureBlock:(DDResponsesFailureBlock)failure; 87 | 88 | /** 89 | * Upload a data stream to http server by HTTP POST Method. 90 | * 91 | * @param path HTTP Path 92 | * @param stream stream data 93 | * @param params POST Parameters 94 | * @param userInfo userInfo dictionary 95 | * @param show is show the HUD on the view 96 | * @param viewController parentViewController 97 | * @param successBlock success block 98 | * @param failureBlock failure block 99 | */ 100 | + (void)post:(NSString *)path 101 | fileStream:(NSData *)stream 102 | params:(id)params 103 | userInfo:(id)userInfo 104 | showHUD:(BOOL)show 105 | parentViewController:(id)viewController 106 | successBlock:(DDUploadReponseSuccessBlock)success 107 | failureBlock:(DDResponsesFailureBlock)failure; 108 | 109 | /** 110 | * Cancel all the requests in the viewController. 111 | * 112 | * @param viewController viewcontroller 113 | */ 114 | + (void)cancelRequest:(id)viewController; 115 | 116 | @end 117 | 118 | 119 | @interface DDModel (DDDeprecated) 120 | 121 | + (void)get:(NSString *)path 122 | params:(id)params 123 | showHUD:(BOOL)show 124 | parentViewController:(id)viewController 125 | dbSuccess:(DDSQLiteBlock)dbResult 126 | success:(DDResponseSuccessBlock)success 127 | failure:(DDResponseFailureBlock)failure __deprecated_msg("Please use +get:params:showHUD:parentViewController:dbSuccess:successBlock:failureBlock instead."); 128 | 129 | + (void)post:(NSString *)path 130 | params:(id)params 131 | showHUD:(BOOL)show 132 | parentViewController:(id)viewController 133 | dbSuccess:(DDSQLiteBlock)dbResult 134 | success:(DDResponseSuccessBlock)success 135 | failure:(DDResponseFailureBlock)failure __deprecated_msg("Please use +post:params:showHUD:parentViewController:dbSuccess:successBlock:failureBlock instead."); 136 | 137 | + (void)get:(NSString *)path 138 | params:(id)params 139 | showHUD:(BOOL)show 140 | parentViewController:(id)viewController 141 | success:(DDResponseSuccessBlock)success 142 | failure:(DDResponseFailureBlock)failure __deprecated_msg("Please use +get:params:showHUD:parentViewController:successBlock:failureBlock instead."); 143 | 144 | + (void)post:(NSString *)path 145 | params:(id)params 146 | showHUD:(BOOL)show 147 | parentViewController:(id)viewController 148 | success:(DDResponseSuccessBlock)success 149 | failure:(DDResponseFailureBlock)failure __deprecated_msg("Please use +post:params:showHUD:parentViewController:successBlock:failureBlock instead"); 150 | 151 | + (void)post:(NSString *)path 152 | fileStream:(NSData *)stream 153 | params:(id)params 154 | userInfo:(id)userInfo 155 | showHUD:(BOOL)show 156 | parentViewController:(id)viewController 157 | success:(DDUploadReponseSuccessBlock)success 158 | failure:(DDResponseFailureBlock)failure __deprecated_msg("Please use +post:fileStream:params:userInfo:showHUD:parentViewController:successBlock:failureBlock instead."); 159 | 160 | @end 161 | -------------------------------------------------------------------------------- /DDModel/Classes/DDModel+DDAddition.m: -------------------------------------------------------------------------------- 1 | // 2 | // DDModel+DDAddition.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15/6/3. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "DDModel+DDAddition.h" 10 | #import "DDModelHttpClient.h" 11 | #import "NSDictionary+DDModel.h" 12 | #import "DDCache.h" 13 | #import "NSString+DDModel.h" 14 | #import "DDModelHttpClient+DDAddition.h" 15 | #import "NSURLSessionTask+DDModel.h" 16 | 17 | @implementation DDModel (DDAddition) 18 | 19 | + (void)get:(NSString *)path 20 | params:(id)params 21 | showHUD:(BOOL)show 22 | parentViewController:(id)viewController 23 | dbSuccess:(DDSQLiteBlock)dbBlock 24 | successBlock:(DDResponseSuccessBlock)success 25 | failureBlock:(DDResponsesFailureBlock)failure 26 | { 27 | if (dbBlock) { 28 | //query the cache 29 | [DDCache queryWithPath:path 30 | parameter:params 31 | result:^(id data) { 32 | DDCache *cache = data; 33 | if (cache) { 34 | id JSON = [cache.content dd_dictionaryWithJSON]; 35 | dbBlock([[self class] convertToObject:JSON]); 36 | } 37 | }]; 38 | } 39 | 40 | [[DDModelHttpClient sharedInstance] showHud:show]; 41 | 42 | NSDictionary *getParams = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 43 | NSURLSessionDataTask *getTask = 44 | [[DDModelHttpClient sharedInstance] GET:path 45 | parameters:getParams 46 | progress:nil 47 | success:^(NSURLSessionDataTask *task, id responseObject) { 48 | 49 | [[DDModelHttpClient sharedInstance] hideHud:show]; 50 | 51 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 52 | 53 | id JSON = [[self class] getObjectFromReponseObject:responseObject failure:failure]; 54 | 55 | //save the cache 56 | [DDCache cacheWithPath:path parameter:params content:JSON]; 57 | if (success && JSON) 58 | success([[self class] convertToObject:JSON]); 59 | } 60 | failure:^(NSURLSessionDataTask *task, NSError *error) { 61 | [[DDModelHttpClient sharedInstance] hideHud:show]; 62 | 63 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 64 | if (failure) 65 | failure(error, [error description], nil); 66 | 67 | }]; 68 | [[DDModelHttpClient sharedInstance] addTask:getTask withKey:viewController]; 69 | } 70 | 71 | + (void)post:(NSString *)path 72 | params:(id)params 73 | showHUD:(BOOL)show 74 | parentViewController:(id)viewController 75 | dbSuccess:(DDSQLiteBlock)dbBlock 76 | successBlock:(DDResponseSuccessBlock)success 77 | failureBlock:(DDResponsesFailureBlock)failure { 78 | 79 | if (dbBlock) { 80 | //query the cache 81 | [DDCache queryWithPath:path 82 | parameter:params 83 | result:^(id data) { 84 | DDCache *cache = data; 85 | if ([cache.content length] > 1) { 86 | id JSON = [cache.content dd_dictionaryWithJSON]; 87 | dbBlock([[self class] convertToObject:JSON]); 88 | } 89 | }]; 90 | } 91 | 92 | [[DDModelHttpClient sharedInstance] showHud:show]; 93 | 94 | NSDictionary *postParams = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 95 | NSURLSessionDataTask *getTask = 96 | [[DDModelHttpClient sharedInstance] POST:path 97 | parameters:postParams 98 | progress:nil 99 | success:^(NSURLSessionDataTask *task, id responseObject) { 100 | 101 | [[DDModelHttpClient sharedInstance] hideHud:show]; 102 | 103 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 104 | 105 | id JSON = [self getObjectFromReponseObject:responseObject failure:failure]; 106 | 107 | //save the cache 108 | [DDCache cacheWithPath:path parameter:params content:responseObject]; 109 | if (success && JSON) 110 | success([[self class] convertToObject:JSON]); 111 | } 112 | failure:^(NSURLSessionDataTask *task, NSError *error) { 113 | [[DDModelHttpClient sharedInstance] hideHud:show]; 114 | 115 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 116 | if (failure) 117 | failure(error, [error description], nil); 118 | }]; 119 | [[DDModelHttpClient sharedInstance] addTask:getTask withKey:viewController]; 120 | } 121 | 122 | #pragma mark - HTTP Request Handler Methods 123 | 124 | + (void)get:(NSString *)path 125 | params:(id)params 126 | showHUD:(BOOL)show 127 | parentViewController:(id)viewController 128 | successBlock:(DDResponseSuccessBlock)success 129 | failureBlock:(DDResponsesFailureBlock)failure { 130 | 131 | [[DDModelHttpClient sharedInstance] showHud:show]; 132 | 133 | params = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 134 | NSURLSessionDataTask *getTask = 135 | [[DDModelHttpClient sharedInstance] GET:path 136 | parameters:params 137 | progress:nil 138 | success:^(NSURLSessionDataTask *operation, id responseObject) { 139 | 140 | [[DDModelHttpClient sharedInstance] hideHud:show]; 141 | 142 | [[DDModelHttpClient sharedInstance] removeTask:operation withKey:viewController]; 143 | id JSON = [self getObjectFromReponseObject:responseObject failure:failure]; 144 | if (success && JSON) 145 | success([[self class] convertToObject:JSON]); 146 | } 147 | failure:^(NSURLSessionDataTask *operation, NSError *error) { 148 | [[DDModelHttpClient sharedInstance] hideHud:show]; 149 | 150 | [[DDModelHttpClient sharedInstance] removeTask:operation withKey:viewController]; 151 | if (failure) 152 | failure(error, [error description], nil); 153 | }]; 154 | [[DDModelHttpClient sharedInstance] addTask:getTask withKey:viewController]; 155 | } 156 | 157 | + (void)post:(NSString *)path 158 | params:(id)params 159 | showHUD:(BOOL)show 160 | parentViewController:(id)viewController 161 | successBlock:(DDResponseSuccessBlock)success 162 | failureBlock:(DDResponsesFailureBlock)failure{ 163 | /** 164 | * show the hud view 165 | */ 166 | [[DDModelHttpClient sharedInstance] showHud:show]; 167 | 168 | params = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 169 | NSURLSessionDataTask *postTask = 170 | [[DDModelHttpClient sharedInstance] POST:path 171 | parameters:params 172 | progress:nil 173 | success:^(NSURLSessionDataTask *task, id responseObject) { 174 | /** 175 | * hide the hud view 176 | */ 177 | [[DDModelHttpClient sharedInstance] hideHud:show]; 178 | 179 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 180 | 181 | id JSON = [self getObjectFromReponseObject:responseObject failure:failure]; 182 | 183 | if (success && JSON) 184 | success([[self class] convertToObject:JSON]); 185 | } 186 | failure:^(NSURLSessionDataTask *task, NSError *error) { 187 | [[DDModelHttpClient sharedInstance] hideHud:show]; 188 | 189 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 190 | if(failure) 191 | failure(error, [error description], nil); 192 | }]; 193 | [[DDModelHttpClient sharedInstance] addTask:postTask withKey:viewController]; 194 | } 195 | 196 | + (void)post:(NSString *)path 197 | fileStream:(NSData *)stream 198 | params:(id)params 199 | userInfo:(id)userInfo 200 | showHUD:(BOOL)show 201 | parentViewController:(id)viewController 202 | successBlock:(DDUploadReponseSuccessBlock)success 203 | failureBlock:(DDResponsesFailureBlock)failure { 204 | 205 | [[DDModelHttpClient sharedInstance] showHud:show]; 206 | params = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 207 | 208 | NSURLSessionUploadTask *uploadTask = 209 | (NSURLSessionUploadTask *)[[DDModelHttpClient sharedInstance] POST:path 210 | parameters:params 211 | constructingBodyWithBlock:^(id formData) { 212 | NSDictionary *uploadInfo = userInfo[DDFILE]; 213 | if(!uploadInfo) 214 | uploadInfo = [NSDictionary dd_defaultFile]; 215 | [formData appendPartWithFileData:stream name:uploadInfo.name fileName:uploadInfo.fileName mimeType:uploadInfo.mimeType]; 216 | } 217 | progress:nil 218 | success:^(NSURLSessionDataTask *task, id responseObject) { 219 | [[DDModelHttpClient sharedInstance] hideHud:show]; 220 | 221 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 222 | id JSON = [self getObjectFromReponseObject:responseObject failure:failure]; 223 | if (success && JSON) 224 | success(userInfo,[[self class] convertToObject:JSON]); 225 | } 226 | failure:^(NSURLSessionDataTask *task, NSError *error) { 227 | [[DDModelHttpClient sharedInstance] showHud:show]; 228 | 229 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 230 | }]; 231 | uploadTask.userInfo = userInfo; 232 | [[DDModelHttpClient sharedInstance] addTask:uploadTask withKey:viewController]; 233 | } 234 | 235 | + (void)cancelRequest:(id)viewController{ 236 | [[DDModelHttpClient sharedInstance] cancelTasksWithKey:viewController]; 237 | } 238 | 239 | 240 | @end 241 | 242 | @implementation DDModel (DDDeprecated) 243 | 244 | #pragma mark - DB Cache - Http Handler Methods 245 | 246 | + (void)get:(NSString *)path 247 | params:(id)params 248 | showHUD:(BOOL)show 249 | parentViewController:(id)viewController 250 | dbSuccess:(DDSQLiteBlock)dbBlock 251 | success:(DDResponseSuccessBlock)success 252 | failure:(DDResponseFailureBlock)failure 253 | { 254 | if(dbBlock){ 255 | //query the cache 256 | [DDCache queryWithPath:path 257 | parameter:params 258 | result:^(id data) { 259 | DDCache *cache = data; 260 | if (cache) { 261 | id JSON = [cache.content dd_dictionaryWithJSON]; 262 | dbBlock([[self class] convertToObject:JSON]); 263 | } 264 | }]; 265 | } 266 | 267 | [[DDModelHttpClient sharedInstance] showHud:show]; 268 | 269 | NSDictionary *getParams = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 270 | NSURLSessionDataTask *getTask = 271 | [[DDModelHttpClient sharedInstance] GET:path 272 | parameters:getParams 273 | success:^(NSURLSessionDataTask *task, id responseObject) { 274 | 275 | [[DDModelHttpClient sharedInstance] hideHud:show]; 276 | 277 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 278 | 279 | id JSON = [[self class] getObjectFromReponseObject:responseObject failureBlock:failure]; 280 | 281 | //save the cache 282 | [DDCache cacheWithPath:path parameter:params content:JSON]; 283 | if (success && JSON) 284 | success([[self class] convertToObject:JSON]); 285 | } 286 | failure:^(NSURLSessionDataTask *task, NSError *error) { 287 | [[DDModelHttpClient sharedInstance] hideHud:show]; 288 | 289 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 290 | if (failure) 291 | failure(error, [error description]); 292 | }]; 293 | [[DDModelHttpClient sharedInstance] addTask:getTask withKey:viewController]; 294 | } 295 | 296 | + (void)post:(NSString *)path 297 | params:(id)params 298 | showHUD:(BOOL)show 299 | parentViewController:(id)viewController 300 | dbSuccess:(DDSQLiteBlock)dbBlock 301 | success:(DDResponseSuccessBlock)success 302 | failure:(DDResponseFailureBlock)failure 303 | { 304 | 305 | if(dbBlock){ 306 | //query the cache 307 | [DDCache queryWithPath:path 308 | parameter:params 309 | result:^(id data) { 310 | DDCache *cache = data; 311 | if([cache.content length] > 1){ 312 | id JSON = [cache.content dd_dictionaryWithJSON]; 313 | dbBlock([[self class] convertToObject:JSON]); 314 | } 315 | }]; 316 | } 317 | 318 | [[DDModelHttpClient sharedInstance] showHud:show]; 319 | 320 | NSDictionary *postParams = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 321 | NSURLSessionDataTask *getTask = 322 | [[DDModelHttpClient sharedInstance] POST:path 323 | parameters:postParams 324 | success:^(NSURLSessionDataTask *task, id responseObject) { 325 | 326 | [[DDModelHttpClient sharedInstance] hideHud:show]; 327 | 328 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 329 | 330 | id JSON = [self getObjectFromReponseObject:responseObject failureBlock:failure]; 331 | 332 | //save the cache 333 | [DDCache cacheWithPath:path parameter:params content:responseObject]; 334 | if (success && JSON) 335 | success([[self class] convertToObject:JSON]); 336 | } 337 | failure:^(NSURLSessionDataTask *task, NSError *error) { 338 | [[DDModelHttpClient sharedInstance] hideHud:show]; 339 | 340 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 341 | if(failure) 342 | failure(error, [error description]); 343 | }]; 344 | [[DDModelHttpClient sharedInstance] addTask:getTask withKey:viewController]; 345 | } 346 | 347 | #pragma mark - HTTP Request Handler Methods 348 | 349 | + (void)get:(NSString *)path 350 | params:(id)params 351 | showHUD:(BOOL)show 352 | parentViewController:(id)viewController 353 | success:(DDResponseSuccessBlock)success 354 | failure:(DDResponseFailureBlock)failure{ 355 | 356 | [[DDModelHttpClient sharedInstance] showHud:show]; 357 | 358 | params = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 359 | NSURLSessionDataTask *getTask = 360 | [[DDModelHttpClient sharedInstance] GET:path 361 | parameters:params 362 | success:^(NSURLSessionDataTask *operation, id responseObject) { 363 | 364 | [[DDModelHttpClient sharedInstance] hideHud:show]; 365 | 366 | [[DDModelHttpClient sharedInstance] removeTask:operation withKey:viewController]; 367 | id JSON = [self getObjectFromReponseObject:responseObject failureBlock:failure]; 368 | if (success && JSON) 369 | success([[self class] convertToObject:JSON]); 370 | } 371 | failure:^(NSURLSessionDataTask *operation, NSError *error) { 372 | [[DDModelHttpClient sharedInstance] hideHud:show]; 373 | 374 | [[DDModelHttpClient sharedInstance] removeTask:operation withKey:viewController]; 375 | if(failure) 376 | failure(error, [error description]); 377 | }]; 378 | [[DDModelHttpClient sharedInstance] addTask:getTask withKey:viewController]; 379 | } 380 | 381 | + (void)post:(NSString *)path 382 | params:(id)params 383 | showHUD:(BOOL)show 384 | parentViewController:(id)viewController 385 | success:(DDResponseSuccessBlock)success 386 | failure:(DDResponseFailureBlock)failure{ 387 | /** 388 | * show the hud view 389 | */ 390 | [[DDModelHttpClient sharedInstance] showHud:show]; 391 | 392 | params = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 393 | NSURLSessionDataTask *postTask = 394 | [[DDModelHttpClient sharedInstance] POST:path 395 | parameters:params 396 | success:^(NSURLSessionDataTask *task, id responseObject) { 397 | /** 398 | * hide the hud view 399 | */ 400 | [[DDModelHttpClient sharedInstance] hideHud:show]; 401 | 402 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 403 | 404 | id JSON = [self getObjectFromReponseObject:responseObject failureBlock:failure]; 405 | 406 | if (success && JSON) 407 | success([[self class] convertToObject:JSON]); 408 | } 409 | failure:^(NSURLSessionDataTask *task, NSError *error) { 410 | [[DDModelHttpClient sharedInstance] hideHud:show]; 411 | 412 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 413 | if (failure) 414 | failure(error, [error description]); 415 | }]; 416 | [[DDModelHttpClient sharedInstance] addTask:postTask withKey:viewController]; 417 | } 418 | 419 | + (void)post:(NSString *)path 420 | fileStream:(NSData *)stream 421 | params:(id)params 422 | userInfo:(id)userInfo 423 | showHUD:(BOOL)show 424 | parentViewController:(id)viewController 425 | success:(DDUploadReponseSuccessBlock)success 426 | failure:(DDResponseFailureBlock)failure{ 427 | 428 | [[DDModelHttpClient sharedInstance] showHud:show]; 429 | params = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 430 | 431 | NSURLSessionUploadTask *uploadTask = 432 | (NSURLSessionUploadTask *)[[DDModelHttpClient sharedInstance] POST:path 433 | parameters:params 434 | constructingBodyWithBlock:^(id formData) { 435 | NSDictionary *uploadInfo = userInfo[DDFILE]; 436 | if(!uploadInfo) 437 | uploadInfo = [NSDictionary dd_defaultFile]; 438 | [formData appendPartWithFileData:stream name:uploadInfo.name fileName:uploadInfo.fileName mimeType:uploadInfo.mimeType]; 439 | } 440 | success:^(NSURLSessionDataTask *task, id responseObject) { 441 | [[DDModelHttpClient sharedInstance] hideHud:show]; 442 | 443 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 444 | id JSON = [self getObjectFromReponseObject:responseObject failureBlock:failure]; 445 | if (success && JSON) 446 | success(userInfo, [[self class] convertToObject:JSON]); 447 | } 448 | failure:^(NSURLSessionDataTask *task, NSError *error) { 449 | [[DDModelHttpClient sharedInstance] showHud:show]; 450 | 451 | [[DDModelHttpClient sharedInstance] removeTask:task withKey:viewController]; 452 | if (failure) 453 | failure(error, [error description]); 454 | }]; 455 | uploadTask.userInfo = userInfo; 456 | [[DDModelHttpClient sharedInstance] addTask:uploadTask withKey:viewController]; 457 | } 458 | 459 | #pragma clang diagnostic push 460 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 461 | + (id)getObjectFromReponseObject:(id)responseObject failureBlock:(DDResponseFailureBlock)failure { 462 | NSDictionary *value = nil; 463 | if ([responseObject isKindOfClass:[NSDictionary class]] && 464 | [DDModelHttpClient sharedInstance].type == DDResponseJSON) { 465 | value = responseObject; 466 | } else if([responseObject isKindOfClass:[NSXMLParser class]] && 467 | [DDModelHttpClient sharedInstance].type == DDResponseXML) { 468 | value = [NSDictionary dictionaryWithXMLParser:responseObject]; 469 | } else { 470 | NSString *responseString = nil; 471 | if ([responseObject isKindOfClass:[NSData class]]) { 472 | responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; 473 | } else { 474 | responseString = responseObject; 475 | } 476 | /** 477 | * decode if you should decode responseString 478 | */ 479 | responseString = [[DDModelHttpClient sharedInstance] responseStringHandler:responseString]; 480 | 481 | NSError *decodeError = nil; 482 | 483 | NSData *decodeData = [responseString dataUsingEncoding:NSUTF8StringEncoding]; 484 | 485 | 486 | if ([DDModelHttpClient sharedInstance].type == DDResponseXML) 487 | value = [NSDictionary dictionaryWithXMLData:decodeData]; 488 | else 489 | value = [NSJSONSerialization JSONObjectWithData:decodeData 490 | options:NSJSONReadingAllowFragments 491 | error:&decodeError]; 492 | 493 | } 494 | //check the failure response callback status 495 | if (![[DDModelHttpClient sharedInstance] checkResponseValue:value failure:failure]) { 496 | if ([DDModelHttpClient sharedInstance].isFailureResponseCallback && failure) { 497 | NSInteger responseCode = [value[[DDModelHttpClient sharedInstance].resultKey?:@"resultCode"] integerValue]; 498 | NSString *message = value[[DDModelHttpClient sharedInstance].descKey?:@"resultDes"]; 499 | NSError *error = [NSError errorWithDomain:[DDModelHttpClient sharedInstance].baseURL.host 500 | code:responseCode 501 | userInfo:nil]; 502 | failure(error, message); 503 | } 504 | return nil; 505 | } 506 | return value?:@{}; 507 | } 508 | #pragma clang diagnostic pop 509 | @end 510 | -------------------------------------------------------------------------------- /DDModel/Classes/DDModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDModel.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SQLitePersistentObject.h" 11 | #import "NSObject+JTObjectMapping.h" 12 | #import "XMLDictionary.h" 13 | #import "DDModelHttpClient.h" 14 | 15 | #define DDFILE @"fileInfo" 16 | 17 | @protocol DDMappings 18 | 19 | /** 20 | * Set the parse node, every subclass override the method if you want parse any node 21 | * 22 | * @return node 23 | */ 24 | + (NSString *)parseNode; 25 | 26 | /** 27 | * Handle the mappings about the json key-value transform to a model object. 28 | The method support for KeyPathValue. e.g. you have a @property name, you want get value from "{user:{name:'mike',id:10011},picture:'https://xxxx/headerimage/header01.jpg'}", you just set mapping dictionary is @{@"user.name":@"name"}. 29 | * 30 | * @return mappings 31 | */ 32 | + (NSDictionary *)parseMappings; 33 | 34 | @end 35 | 36 | /** 37 | * DB callback an object or an object arrays 38 | * 39 | * @param data an object or an object arrays 40 | */ 41 | typedef void(^DDSQLiteBlock)(id data); 42 | 43 | @interface DDModel : SQLitePersistentObject{ 44 | 45 | } 46 | 47 | /** 48 | * Get json data first from db cache then from http server by HTTP GET Mehod. 49 | * 50 | * @param path HTTP Path 51 | * @param params GET Paramtters 52 | * @param dbResult db cache result block 53 | * @param success success block 54 | * @param failure failre block 55 | * 56 | * @return NSURLSessionDataTask 57 | */ 58 | + (NSURLSessionDataTask *)get:(NSString *)path 59 | params:(id)params 60 | dbSuccess:(DDSQLiteBlock)dbResult 61 | success:(DDResponseSuccessBlock)success 62 | failure:(DDResponsesFailureBlock)failure; 63 | 64 | /** 65 | * Get json data first from db cache then from http server by HTTP POST Mehod. 66 | * 67 | * @param path HTTP Path 68 | * @param params GET Paramtters 69 | * @param dbResult db cache result block 70 | * @param success success block 71 | * @param failure failre block 72 | * 73 | * @return NSURLSessionDataTask 74 | */ 75 | + (NSURLSessionDataTask *)post:(NSString *)path 76 | params:(id)params 77 | dbSuccess:(DDSQLiteBlock)dbResult 78 | success:(DDResponseSuccessBlock)success 79 | failure:(DDResponsesFailureBlock)failure; 80 | 81 | /** 82 | * Get json data from http server by HTTP GET Mehod. 83 | * 84 | * @param path HTTP Path 85 | * @param params GET Paramtters 86 | * @param success success block 87 | * @param failure failre block 88 | * 89 | * @return NSURLSessionDataTask 90 | */ 91 | + (NSURLSessionDataTask *)get:(NSString *)path 92 | params:(id)params 93 | success:(DDResponseSuccessBlock)success 94 | failure:(DDResponsesFailureBlock)failure; 95 | 96 | /** 97 | * Get json data from http server by HTTP POST Mehod. 98 | * 99 | * @param path HTTP Path 100 | * @param params POST Paramtters 101 | * @param success success block 102 | * @param failure failre block 103 | * 104 | * @return NSURLSessionDataTask 105 | */ 106 | + (NSURLSessionDataTask *)post:(NSString *)path 107 | params:(id)params 108 | success:(DDResponseSuccessBlock)success 109 | failure:(DDResponsesFailureBlock)failure; 110 | 111 | /** 112 | * Upload a data stream to http server by HTTP POST Method. 113 | * 114 | * @param path HTTP Path 115 | * @param stream stream data 116 | * @param params POST Parameters 117 | * @param userInfo userInfo dictionary 118 | * @param success success block 119 | * @param failure failure block 120 | * 121 | * @return NSURLSessionDataTask 122 | */ 123 | + (NSURLSessionDataTask *)post:(NSString *)path 124 | fileStream:(NSData *)stream 125 | params:(id)params 126 | userInfo:(id)userInfo 127 | success:(DDUploadReponseSuccessBlock)success 128 | failure:(DDResponsesFailureBlock)failure; 129 | 130 | /** 131 | * Parse self entity into a dictionary 132 | * 133 | * @return a dictionary of self entity 134 | */ 135 | - (NSDictionary *)propertiesOfObject; 136 | 137 | /** 138 | * Get Object(s) from reponse string 139 | * 140 | * @param reponseString reponse string 141 | * @param failure failure handler block 142 | * 143 | * @return Object(s) 144 | */ 145 | + (id)getObjectFromReponseObject:(NSString *)responseObject 146 | failure:(DDResponsesFailureBlock)failure; 147 | 148 | /** 149 | * conver dictionary object to Model 150 | * 151 | * @param dictObject dictionary object 152 | * 153 | * @return modol or model array 154 | */ 155 | + (id)convertToObject:(id)dictObject; 156 | 157 | @end 158 | 159 | -------------------------------------------------------------------------------- /DDModel/Classes/DDModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // DDModel.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "DDModel.h" 10 | #import "DDModelHttpClient.h" 11 | #import "NSDictionary+DDModel.h" 12 | #import "DDCache.h" 13 | #import "NSString+DDModel.h" 14 | #import "NSURLSessionTask+DDModel.h" 15 | 16 | #define DDFILE @"fileInfo" 17 | 18 | @implementation DDModel 19 | 20 | #pragma mark - DB Cache - Http Handler Methods 21 | 22 | + (NSURLSessionDataTask *)get:(NSString *)path 23 | params:(id)params 24 | dbSuccess:(DDSQLiteBlock)dbBlock 25 | success:(DDResponseSuccessBlock)success 26 | failure:(DDResponsesFailureBlock)failure 27 | { 28 | if (dbBlock) { 29 | //query the cache 30 | [DDCache queryWithPath:path 31 | parameter:params 32 | result:^(id data) { 33 | DDCache *cache = data; 34 | if (cache) { 35 | id JSON = [cache.content dd_dictionaryWithJSON]; 36 | dbBlock([[self class] convertToObject:JSON]); 37 | } 38 | }]; 39 | } 40 | 41 | 42 | NSDictionary *getParams = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 43 | NSURLSessionDataTask *getTask = 44 | [[DDModelHttpClient sharedInstance] GET:path 45 | parameters:getParams 46 | progress:nil 47 | success:^(NSURLSessionDataTask *task, id responseObject) { 48 | id JSON = [self getObjectFromReponseObject:responseObject 49 | failure:failure]; 50 | //save the cache 51 | [DDCache cacheWithPath:path 52 | parameter:params 53 | content:JSON]; 54 | if (success && JSON) 55 | success([[self class] convertToObject:JSON]); 56 | } 57 | failure:^(NSURLSessionDataTask *task, NSError *error) { 58 | if (failure) 59 | failure(error, [error description], nil); 60 | }]; 61 | return getTask; 62 | } 63 | 64 | + (NSURLSessionDataTask *)post:(NSString *)path 65 | params:(id)params 66 | dbSuccess:(DDSQLiteBlock)dbBlock 67 | success:(DDResponseSuccessBlock)success 68 | failure:(DDResponsesFailureBlock)failure 69 | { 70 | 71 | if (dbBlock) { 72 | //query the cache 73 | [DDCache queryWithPath:path 74 | parameter:params 75 | result:^(id data) { 76 | DDCache *cache = data; 77 | if ([cache.content length] > 1) { 78 | id JSON = [cache.content dd_dictionaryWithJSON]; 79 | dbBlock([[self class] convertToObject:JSON]); 80 | } 81 | }]; 82 | } 83 | 84 | 85 | NSDictionary *postParams = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 86 | NSURLSessionDataTask *postTask = 87 | [[DDModelHttpClient sharedInstance] POST:path 88 | parameters:postParams 89 | progress:nil 90 | success:^(NSURLSessionDataTask *task, id responseObject) { 91 | 92 | id JSON = [self getObjectFromReponseObject:responseObject failure:failure]; 93 | 94 | //save the cache 95 | [DDCache cacheWithPath:path parameter:params content:JSON]; 96 | if (success && JSON) 97 | success([[self class] convertToObject:JSON]); 98 | } 99 | failure:^(NSURLSessionDataTask *task, NSError *error) { 100 | if (failure) 101 | failure(error, [error description], nil); 102 | }]; 103 | return postTask; 104 | } 105 | 106 | #pragma mark - HTTP Request Handler Methods 107 | 108 | + (NSURLSessionDataTask *)get:(NSString *)path 109 | params:(id)params 110 | success:(DDResponseSuccessBlock)success 111 | failure:(DDResponsesFailureBlock)failure { 112 | 113 | params = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 114 | NSURLSessionDataTask *getTask = 115 | [[DDModelHttpClient sharedInstance] GET:path 116 | parameters:params 117 | progress:nil 118 | success:^(NSURLSessionDataTask *task, id responseObject) { 119 | 120 | id JSON = [self getObjectFromReponseObject:responseObject 121 | failure:failure]; 122 | if (success && JSON) 123 | success([[self class] convertToObject:JSON]); 124 | } 125 | failure:^(NSURLSessionDataTask *task, NSError *error) { 126 | if (failure) 127 | failure(error, [error description], nil); 128 | }]; 129 | return getTask; 130 | } 131 | 132 | + (NSURLSessionDataTask *)post:(NSString *)path 133 | params:(id)params 134 | success:(DDResponseSuccessBlock)success 135 | failure:(DDResponsesFailureBlock)failure { 136 | 137 | params = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 138 | NSURLSessionDataTask *postTask = 139 | [[DDModelHttpClient sharedInstance] POST:path 140 | parameters:params 141 | progress:nil 142 | success:^(NSURLSessionDataTask *task, id responseObject) { 143 | 144 | id JSON = [self getObjectFromReponseObject:responseObject failure:failure]; 145 | if (success && JSON) 146 | success([[self class] convertToObject:JSON]); 147 | } 148 | failure:^(NSURLSessionDataTask *task, NSError *error) { 149 | if (failure) 150 | failure(error, [error description], nil); 151 | }]; 152 | return postTask; 153 | } 154 | 155 | + (NSURLSessionDataTask *)post:(NSString *)path 156 | fileStream:(NSData *)stream 157 | params:(id)params 158 | userInfo:(id)userInfo 159 | success:(DDUploadReponseSuccessBlock)success 160 | failure:(DDResponsesFailureBlock)failure { 161 | 162 | params = [[DDModelHttpClient sharedInstance] parametersHandler:params]; 163 | 164 | NSURLSessionUploadTask *uploadTask = (NSURLSessionUploadTask *) 165 | [[DDModelHttpClient sharedInstance] POST:path 166 | parameters:params 167 | constructingBodyWithBlock:^(id formData) { 168 | NSDictionary *uploadInfo = userInfo[DDFILE]; 169 | if (!uploadInfo) 170 | uploadInfo = [NSDictionary dd_defaultFile]; 171 | [formData appendPartWithFileData:stream 172 | name:uploadInfo.name 173 | fileName:uploadInfo.fileName 174 | mimeType:uploadInfo.mimeType]; 175 | } 176 | progress:nil 177 | success:^(NSURLSessionDataTask *task, id responseObject) { 178 | id JSON = [self getObjectFromReponseObject:responseObject 179 | failure:failure]; 180 | if (success && JSON) 181 | success([task.taskDescription dd_dictionaryWithJSON], [[self class] convertToObject:JSON]); 182 | } 183 | failure:^(NSURLSessionDataTask *task, NSError *error) { 184 | if (failure) 185 | failure(error, [error description], nil); 186 | }]; 187 | if (userInfo) 188 | uploadTask.taskDescription = [userInfo dd_jsonString]; 189 | return uploadTask; 190 | } 191 | 192 | #pragma mark - 193 | 194 | + (id)getObjectFromReponseObject:(id)responseObject failure:(DDResponsesFailureBlock)failure { 195 | NSDictionary *value = nil; 196 | if ([responseObject isKindOfClass:[NSDictionary class]] && [DDModelHttpClient sharedInstance].type == DDResponseJSON) { 197 | value = responseObject; 198 | } else if([responseObject isKindOfClass:[NSXMLParser class]] && [DDModelHttpClient sharedInstance].type == DDResponseXML){ 199 | value = [NSDictionary dictionaryWithXMLParser:responseObject]; 200 | } else { 201 | NSString *responseString = nil; 202 | if([responseObject isKindOfClass:[NSData class]]){ 203 | responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; 204 | }else{ 205 | responseString = responseObject; 206 | } 207 | /** 208 | * decode if you should decode responseString 209 | */ 210 | responseString = [[DDModelHttpClient sharedInstance] responseStringHandler:responseString]; 211 | 212 | NSError *decodeError = nil; 213 | 214 | NSData *decodeData = [responseString dataUsingEncoding:NSUTF8StringEncoding]; 215 | 216 | 217 | if([DDModelHttpClient sharedInstance].type == DDResponseXML){ 218 | value = [NSDictionary dictionaryWithXMLData:decodeData]; 219 | }else 220 | value = [NSJSONSerialization JSONObjectWithData:decodeData 221 | options:NSJSONReadingAllowFragments 222 | error:&decodeError]; 223 | 224 | } 225 | 226 | //check the failure response callback status 227 | if (![[DDModelHttpClient sharedInstance] checkResponseValues:value failure:failure]) { 228 | if ([DDModelHttpClient sharedInstance].isFailureResponseCallback && 229 | failure) { 230 | NSInteger responseCode = [value[[DDModelHttpClient sharedInstance].resultKey?:@"resultCode"] integerValue]; 231 | NSString *message = value[[DDModelHttpClient sharedInstance].descKey?:@"resultDes"]; 232 | NSError *error = [NSError errorWithDomain:[DDModelHttpClient sharedInstance].baseURL.host 233 | code:responseCode 234 | userInfo:nil]; 235 | id data = [[self class] convertToObject:value]; 236 | failure(error, message, data); 237 | } 238 | return nil; 239 | } 240 | return value?:@{}; 241 | } 242 | 243 | #pragma mark - Propery Methods 244 | 245 | - (NSDictionary *)propertiesOfObject { 246 | NSMutableDictionary *props = [NSMutableDictionary dictionary]; 247 | unsigned int outCount, i; 248 | objc_property_t *properties = class_copyPropertyList([self class], &outCount); 249 | for (i = 0; i < outCount; i++) { 250 | objc_property_t property = properties[i]; 251 | NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding]; 252 | id propertyValue = [self valueForKey:propertyName]; 253 | if ([propertyValue isKindOfClass:[NSArray class]]) { 254 | NSMutableArray *list = [NSMutableArray arrayWithCapacity:0]; 255 | for (id propetyItem in propertyValue) { 256 | if ([[propetyItem class] isSubclassOfClass:[DDModel class]]) { 257 | [list addObject:[propetyItem propertiesOfObject]]; 258 | } else { 259 | if(propetyItem) 260 | [list addObject:propetyItem]; 261 | } 262 | } 263 | [props setObject:list forKey:propertyName]; 264 | } else if ([[propertyValue class] isSubclassOfClass:[DDModel class]]) { 265 | [props setObject:[propertyValue propertiesOfObject] forKey:propertyName]; 266 | } else { 267 | if(propertyValue) 268 | [props setObject:propertyValue forKey:propertyName]; 269 | } 270 | } 271 | free(properties); 272 | return props; 273 | } 274 | 275 | #pragma mark - Object Mapping Handle Methods 276 | 277 | + (NSString *)parseNode { 278 | return @"NULL"; 279 | } 280 | 281 | + (NSDictionary *)parseMappings { 282 | return nil; 283 | } 284 | 285 | + (id)convertToObject:(id)jsonObject { 286 | if(jsonObject == nil){ 287 | return nil; 288 | } 289 | id data = nil; 290 | if ([jsonObject isKindOfClass:[NSArray class]]) { 291 | data = jsonObject; 292 | } else { 293 | if ([[[self class] parseNode] isEqualToString:@"NULL"]) { 294 | data = jsonObject; 295 | } else { 296 | data = [jsonObject valueForKeyPath:[[self class] parseNode]]; 297 | } 298 | } 299 | if (data == nil) { 300 | return nil; 301 | } 302 | return [[self class] objectFromJSONObject:data mapping:[[self class] parseMappings]]; 303 | } 304 | 305 | 306 | @end 307 | 308 | 309 | @implementation DDModel (DDKit) 310 | 311 | + (NSArray *)getPropertyNames { 312 | NSMutableArray *propertiesArray = [[NSMutableArray alloc] initWithCapacity:0]; 313 | unsigned int outCount, i; 314 | objc_property_t *properties = class_copyPropertyList([self class], &outCount); 315 | for (i = 0; i < outCount; i++) { 316 | objc_property_t property = properties[i]; 317 | NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) 318 | encoding:NSUTF8StringEncoding]; 319 | [propertiesArray addObject:propertyName]; 320 | } 321 | return propertiesArray; 322 | } 323 | 324 | @end 325 | -------------------------------------------------------------------------------- /DDModel/Classes/DDModelHttpClient+DDAddition.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDModelHttpClient+DDAddition.h 3 | // DDModel 4 | // 5 | // Created by DeJohn on 15/5/25. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "DDModelHttpClient.h" 10 | #import "MBProgressHUD.h" 11 | 12 | @interface DDModelHttpClient (DDAddition) 13 | 14 | @property (nonatomic, strong) MBProgressHUD *hud; 15 | 16 | /** 17 | * show hud if flag is YES 18 | * 19 | * @param flag flag 20 | */ 21 | - (void)showHud:(BOOL)flag; 22 | 23 | /** 24 | * hide hud if flag is YES 25 | * 26 | * @param flag flag 27 | */ 28 | - (void)hideHud:(BOOL)flag; 29 | 30 | @end 31 | 32 | @interface DDModelHttpClient (NSURLSessionTaskHandler) 33 | 34 | @property (nonatomic, strong) NSMutableDictionary *ddHttpQueueDict; 35 | 36 | /** 37 | * Add the requesting task into the tasks queue with the key. the tasks queue may have many keys, so we use the key value to 38 | * 39 | * @param task requesting task 40 | * @param key key 41 | */ 42 | - (void)addTask:(NSURLSessionDataTask *)task withKey:(id)key; 43 | 44 | /** 45 | * Cancel the requesting task in the tasks queue with the key. 46 | * 47 | * @param task requesting task 48 | * @param key key 49 | */ 50 | - (void)removeTask:(NSURLSessionDataTask *)task withKey:(id)key; 51 | 52 | /** 53 | * Cancel the all requesting tasks in tasks queue with the key. 54 | * 55 | * @param key key 56 | */ 57 | - (void)cancelTasksWithKey:(id)key; 58 | 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /DDModel/Classes/DDModelHttpClient+DDAddition.m: -------------------------------------------------------------------------------- 1 | // 2 | // DDModelHttpClient+DDAddition.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15/5/25. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "DDModelHttpClient+DDAddition.h" 10 | #import 11 | 12 | @implementation DDModelHttpClient (DDAddition) 13 | 14 | static int hudCount = 0; 15 | 16 | #pragma mark - runtime methods 17 | 18 | - (MBProgressHUD *)hud { 19 | return objc_getAssociatedObject(self, _cmd); 20 | } 21 | 22 | - (void)setHud:(MBProgressHUD *)hud { 23 | objc_setAssociatedObject(self, @selector(hud), hud, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 24 | } 25 | 26 | #pragma mark - HTTP HUD methods 27 | 28 | - (void)showHud:(BOOL)flag { 29 | if (!flag) 30 | return; 31 | if (hudCount > 0) { 32 | hudCount ++; 33 | return; 34 | } 35 | UIWindow *topWindow = [[[UIApplication sharedApplication] windows] lastObject]; 36 | if (!self.hud) { 37 | self.hud = [[MBProgressHUD alloc] initWithView:topWindow]; 38 | self.hud.labelText = @"请稍候..."; 39 | self.hud.yOffset = -20.0f; 40 | self.hud.userInteractionEnabled = NO; 41 | self.hud.mode = MBProgressHUDModeIndeterminate; 42 | self.hud.color = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.3f]; 43 | } 44 | [topWindow addSubview:self.hud]; 45 | //处理背景颜色 按需更换 46 | hudCount++; 47 | [self.hud show:NO]; 48 | } 49 | 50 | - (void)hideHud:(BOOL)flag { 51 | if (!flag) 52 | return; 53 | if (hudCount == 1 && self.hud) { 54 | [self.hud hide:NO]; 55 | } 56 | hudCount --; 57 | } 58 | 59 | @end 60 | 61 | @implementation DDModelHttpClient (NSURLSessionTaskHandler) 62 | 63 | - (NSMutableDictionary *)ddHttpQueueDict { 64 | return objc_getAssociatedObject(self, _cmd); 65 | } 66 | 67 | - (void)setDdHttpQueueDict:(NSMutableDictionary *)ddHttpQueueDict { 68 | objc_setAssociatedObject(self, @selector(ddHttpQueueDict), ddHttpQueueDict, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 69 | } 70 | 71 | #pragma mark - HTTP Operation Methods 72 | 73 | - (void)addTask:(NSURLSessionTask *)task withKey:(id)key { 74 | __block NSString *keyStr = [self description]; 75 | if (key) 76 | keyStr = [key description]; 77 | dispatch_async(dispatch_get_main_queue(), ^{ 78 | NSMutableArray *tasks = self.ddHttpQueueDict[keyStr]; 79 | if(!tasks) 80 | tasks = [[NSMutableArray alloc] initWithObjects:task, nil]; 81 | else 82 | [tasks addObject:task]; 83 | [self.ddHttpQueueDict setObject:tasks forKey:keyStr]; 84 | }); 85 | } 86 | 87 | - (void)removeTask:(NSURLSessionTask *)task withKey:(id)key { 88 | __block NSString *keyStr = [self description]; 89 | if (key) 90 | keyStr = [key description]; 91 | dispatch_async(dispatch_get_main_queue(), ^{ 92 | NSMutableArray *tasks = self.ddHttpQueueDict[keyStr]; 93 | [tasks removeObject:task]; 94 | }); 95 | } 96 | 97 | - (void)cancelTasksWithKey:(id)key { 98 | __block NSString *keyStr = [self description]; 99 | if (key) 100 | keyStr = [key description]; 101 | dispatch_async(dispatch_get_main_queue(), ^{ 102 | NSMutableArray *tasks = self.ddHttpQueueDict[keyStr]; 103 | if (tasks.count > 0) 104 | [tasks makeObjectsPerformSelector:@selector(cancel)]; 105 | [self.ddHttpQueueDict removeObjectForKey:keyStr]; 106 | }); 107 | } 108 | 109 | @end 110 | -------------------------------------------------------------------------------- /DDModel/Classes/DDModelHttpClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDHttpClient.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AFHTTPSessionManager.h" 11 | 12 | /** 13 | * Http Response Success Block callback an object or an object arrays; 14 | * 15 | * @param data an object or an object arrays 16 | */ 17 | typedef void(^DDResponseSuccessBlock)(id data); 18 | 19 | /** 20 | * Http Response Failure Block callback an error object & a message object & a parased object 21 | * 22 | * @param error error 23 | * @param message message info 24 | * @param data data an object or an object arrays 25 | */ 26 | typedef void(^DDResponsesFailureBlock)(NSError *error, NSString *message, id data); 27 | 28 | /** 29 | * Http Response Failure Block callback an error object & a message object 30 | * 31 | * @param error error 32 | * @param message message info 33 | */ 34 | typedef void(^DDResponseFailureBlock)(NSError *error, NSString *message) __deprecated_msg("Please use 'DDResponsesFailureBlock' instead."); 35 | 36 | 37 | /** 38 | * Http Upload file response success block callback with userinfo & response object 39 | * 40 | * @param userInfo userInfo 41 | * @param data response object 42 | */ 43 | typedef void(^DDUploadReponseSuccessBlock)(NSDictionary *userInfo, id data); 44 | 45 | typedef enum : NSUInteger { 46 | DDResponseXML, 47 | DDResponseJSON, 48 | DDResponseOhter, 49 | } DDResponseType; 50 | 51 | @protocol DDHttpClientDelegate; 52 | 53 | @interface DDModelHttpClient : AFHTTPSessionManager 54 | 55 | @property (nonatomic) DDResponseType type; //reponse type 56 | 57 | /** 58 | * Check failure response callback flag status 59 | */ 60 | @property (nonatomic, readonly) BOOL isFailureResponseCallback; 61 | 62 | @property (nonatomic, copy) NSString *descKey; //error description key 63 | 64 | /** 65 | * Error code key, .eg. your response json is {'resultCode':0,'resultDesc':'success',list:[{'xxx':xxx},...]} 66 | * so you should set the resultKey is 'resultCode' hook the result code info and set the descKey is 'resultDesc' hook the 67 | * result description 68 | */ 69 | @property (nonatomic, copy) NSString *resultKey; 70 | 71 | 72 | /** 73 | * Set if the response callback when it's failure request 74 | * 75 | * @param flag YES/NO, default is NO. 76 | */ 77 | - (void)setFailureCallbackResponse:(BOOL)flag; 78 | 79 | #pragma mark - initlize methods 80 | /** 81 | * Start a singleton HTTP client with url. 82 | * 83 | * @param url HTTP target url 84 | */ 85 | + (void)startWithURL:(NSString *)url; 86 | 87 | /** 88 | * Start a singleton HTTP client with url & delegate 89 | * 90 | * @param url HTTP target url 91 | * @param delegate DDHttpClientDelegate 92 | */ 93 | + (void)startWithURL:(NSString *)url delegate:(id)delegate; 94 | 95 | /** 96 | * Singleton client 97 | * 98 | * @return instance client 99 | */ 100 | + (instancetype)sharedInstance; 101 | 102 | #pragma mark - 103 | /** 104 | * Set the HTTP header field value 105 | * 106 | * @param keyValue keyValue 107 | */ 108 | + (void)addHTTPHeaderFieldValue:(NSDictionary *)keyValue; 109 | 110 | /** 111 | * Remove the HTTP header field value 112 | * 113 | * @param keyValue keyValue 114 | */ 115 | + (void)removeHTTPHeaderFieldValue:(NSDictionary *)keyValue; 116 | 117 | 118 | #pragma mark - decode & encode methods 119 | /** 120 | * HTTP parameter the handler method 121 | * 122 | * @param params origin parameters 123 | * 124 | * @return new parameters 125 | */ 126 | - (NSDictionary *)parametersHandler:(NSDictionary *)params; 127 | 128 | /** 129 | * HTTP response string handler method 130 | * 131 | * @param responseString origin responseString 132 | * 133 | * @return new responseString 134 | */ 135 | - (NSString *)responseStringHandler:(NSString *)responseString; 136 | 137 | /** 138 | * Check the response values is an available value 139 | * 140 | * @param values origin value 141 | * @param failure failure block 142 | * 143 | * @return true or false 144 | */ 145 | - (BOOL)checkResponseValues:(NSDictionary *)values failure:(DDResponsesFailureBlock)failure; 146 | 147 | @end 148 | 149 | @protocol DDHttpClientDelegate 150 | 151 | @optional 152 | /** 153 | * Parameter encode method if you should encode the parameter in your HTTP client 154 | * 155 | * @param params original parameters 156 | * 157 | * @return endcoded parameters 158 | */ 159 | - (NSDictionary *)encodeParameters:(NSDictionary *)params; 160 | 161 | /** 162 | * Response String decode methods in you HTTP client 163 | * 164 | * @param responseString origin responseString 165 | * 166 | * @return new responseString 167 | */ 168 | - (NSString *)decodeResponseString:(NSString *)responseString; 169 | 170 | /** 171 | * Check the response values is an available value. 172 | e.g. You will sign in an account but you press a wrong username/password, server will response a error for you, you can catch them use this protocol methods and handle this error exception. 173 | * 174 | * @param values should check value 175 | * @param failure failure block 176 | * 177 | * @return true or false 178 | */ 179 | - (BOOL)checkResponseValuesAvailable:(NSDictionary *)values failure:(DDResponsesFailureBlock)failure; 180 | 181 | - (BOOL)checkResponseValueAvaliable:(NSDictionary *)values failure:(DDResponseFailureBlock)failure __deprecated_enum_msg("Please use the `-checkResponseValuesAvailable:failure:` instead."); 182 | 183 | @end 184 | 185 | @interface DDModelHttpClient (DDDeprecated) 186 | 187 | - (BOOL)checkResponseValue:(NSDictionary *)values failure:(DDResponseFailureBlock)failure __deprecated_msg("Please use the `-checkResponseValues:failure:` instead."); 188 | 189 | @end 190 | -------------------------------------------------------------------------------- /DDModel/Classes/DDModelHttpClient.m: -------------------------------------------------------------------------------- 1 | // 2 | // DDHttpClient.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "DDModelHttpClient.h" 10 | #import "AFHTTPSessionManager+DDModel.h" 11 | 12 | static NSString *kAppUrl; 13 | 14 | @interface DDModelHttpClient() 15 | 16 | @property (nonatomic, weak) id delegate; 17 | @property (nonatomic, readwrite) BOOL isFailureResponseCallback; 18 | 19 | @end 20 | 21 | @implementation DDModelHttpClient 22 | 23 | #pragma mark - lifecycle methods 24 | 25 | + (void)startWithURL:(NSString *)url { 26 | kAppUrl = url; 27 | [self sharedInstance]; 28 | } 29 | 30 | + (instancetype)sharedInstance { 31 | static DDModelHttpClient *client = nil; 32 | static dispatch_once_t onceToken; 33 | dispatch_once(&onceToken, ^{ 34 | NSURL *clientURL = [NSURL URLWithString:kAppUrl]; 35 | if ([clientURL.scheme isEqualToString:@"https"]) { 36 | client.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; 37 | } 38 | if (!clientURL.host) { 39 | NSLog(@"you have lost the method 'startWithURL:' or 'startWithURL:delegate:' in lanuching AppDelegate"); 40 | } 41 | client = [[DDModelHttpClient alloc] initWithBaseURL:clientURL]; 42 | [client dd_addURL:kAppUrl]; 43 | client.type = DDResponseOhter; 44 | }); 45 | return client; 46 | } 47 | 48 | + (void)startWithURL:(NSString *)url delegate:(id)delegate { 49 | [self startWithURL:url]; 50 | [DDModelHttpClient sharedInstance].delegate = delegate; 51 | } 52 | 53 | #pragma mark - HTTP Header Field Value Handler Methods 54 | 55 | + (void)addHTTPHeaderFieldValue:(NSDictionary *)keyValue { 56 | for (id key in [keyValue allKeys]) { 57 | [[[self sharedInstance] requestSerializer] setValue:keyValue[key] forHTTPHeaderField:key]; 58 | } 59 | } 60 | 61 | + (void)removeHTTPHeaderFieldValue:(NSDictionary *)keyValue { 62 | for (id key in [keyValue allKeys]) { 63 | [[[self sharedInstance] requestSerializer] setValue:@"" forHTTPHeaderField:key]; 64 | } 65 | } 66 | 67 | #pragma mark - HTTP Decode & Encode Methods 68 | 69 | - (NSDictionary *)parametersHandler:(NSDictionary *)params { 70 | if ([self.delegate respondsToSelector:@selector(encodeParameters:)]) { 71 | params = [self.delegate encodeParameters:params]; 72 | } 73 | return params; 74 | } 75 | 76 | - (NSString *)responseStringHandler:(NSString *)responseString { 77 | if ([self.delegate respondsToSelector:@selector(decodeResponseString:)]) { 78 | responseString = [self.delegate decodeResponseString:responseString]; 79 | } 80 | return responseString; 81 | } 82 | 83 | - (BOOL)checkResponseValues:(NSDictionary *)values failure:(DDResponsesFailureBlock)failure { 84 | //instead methods 85 | if ([self.delegate respondsToSelector:@selector(checkResponseValuesAvailable:failure:)]) { 86 | return [self.delegate checkResponseValuesAvailable:values failure:failure]; 87 | } 88 | return YES; 89 | } 90 | 91 | #pragma mark - Get & set methods 92 | 93 | - (void)setType:(DDResponseType)type { 94 | _type = type; 95 | if (type == DDResponseXML) { 96 | self.responseSerializer = [AFXMLParserResponseSerializer serializer]; 97 | } else if(type == DDResponseJSON) { 98 | self.responseSerializer = [AFJSONResponseSerializer serializer]; 99 | } else { 100 | self.responseSerializer = [AFHTTPResponseSerializer serializer]; 101 | } 102 | } 103 | 104 | - (void)setFailureCallbackResponse:(BOOL)flag { 105 | self.isFailureResponseCallback = flag; 106 | } 107 | 108 | @end 109 | 110 | 111 | 112 | @implementation DDModelHttpClient (DDDeprecated) 113 | 114 | - (BOOL)checkResponseValue:(NSDictionary *)values failure:(DDResponseFailureBlock)failure{ 115 | if([self.delegate respondsToSelector:@selector(checkResponseValueAvaliable:failure:)]){ 116 | return [self.delegate checkResponseValueAvaliable:values failure:failure]; 117 | } 118 | return YES; 119 | } 120 | 121 | @end 122 | 123 | 124 | -------------------------------------------------------------------------------- /DDModel/Classes/DDModelKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDModelKit.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-5. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #ifndef _DDModelKit_ 10 | #define _DDModelKit_ 11 | 12 | #import "DDModel.h" 13 | #import "DDCache.h" 14 | #import "DDModelHttpClient.h" 15 | #import "NSDictionary+DDModel.h" 16 | #import "DDModel+DDAddition.h" 17 | #import "DDModelHttpClient+DDAddition.h" 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /DDModel/Classes/NSDictionary+DDModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+DDModelKit.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-9. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDictionary (DDModel) 12 | 13 | @property (nonatomic, readonly) NSString *name; 14 | @property (nonatomic, readonly) NSString *fileName; 15 | @property (nonatomic, readonly) NSString *mimeType; 16 | 17 | /** 18 | * Initilization with name, fileName & mimeType dictionary object 19 | * 20 | * @param name name 21 | * @param fileName file name 22 | * @param mimeType mime type 23 | * 24 | * @return dictionary 25 | */ 26 | + (instancetype)dd_dictionaryWithName:(NSString *)name 27 | fileName:(NSString *)fileName 28 | mimeType:(NSString *)mimeType; 29 | 30 | /** 31 | * Default initilize 32 | * 33 | * @return dictionary 34 | */ 35 | + (instancetype)dd_defaultFile; 36 | 37 | 38 | /** 39 | * NSDictionary object convert to JSON string 40 | * 41 | * @return json string 42 | */ 43 | - (NSString *)dd_jsonString; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /DDModel/Classes/NSDictionary+DDModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+DDModelKit.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-9. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "NSDictionary+DDModel.h" 10 | 11 | #define ddmime @"mimeType" 12 | #define ddfile @"fileName" 13 | #define ddname @"name" 14 | 15 | @implementation NSDictionary (DDModel) 16 | 17 | + (instancetype)dd_dictionaryWithName:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType { 18 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:0]; 19 | [dictionary setObject:name forKey:ddname]; 20 | [dictionary setObject:fileName forKey:ddfile]; 21 | [dictionary setObject:mimeType forKey:ddmime]; 22 | return dictionary; 23 | } 24 | 25 | + (instancetype)dd_defaultFile { 26 | return [self dd_dictionaryWithName:@"uploadFile" fileName:@"file" mimeType:@"image/jpg"]; 27 | } 28 | 29 | - (NSString *)mimeType { 30 | return [self objectForKey:ddmime]; 31 | } 32 | 33 | - (NSString *)fileName { 34 | return [self objectForKey:ddfile]; 35 | } 36 | 37 | - (NSString *)name { 38 | return [self objectForKey:ddname]; 39 | } 40 | 41 | - (NSString *)dd_jsonString { 42 | NSError *error = nil; 43 | NSData *data = [NSJSONSerialization dataWithJSONObject:self 44 | options:NSJSONWritingPrettyPrinted 45 | error:&error]; 46 | if (error) 47 | NSLog(@"error = %@",error); 48 | return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 49 | } 50 | 51 | @end 52 | 53 | -------------------------------------------------------------------------------- /DDModel/Classes/NSString+DDModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+md5.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-3-10. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (DDModel) 12 | 13 | /** 14 | * Cache string md5 encode 15 | * 16 | * @return md5 string 17 | */ 18 | - (NSString *)dd_cacheMD5; 19 | 20 | /** 21 | * String convert to NSDictionary object 22 | * 23 | * @return dictionary 24 | */ 25 | - (NSDictionary *)dd_dictionaryWithJSON; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /DDModel/Classes/NSString+DDModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+md5.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-3-10. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "NSString+DDModel.h" 10 | #import 11 | 12 | @implementation NSString (DDModel) 13 | 14 | - (NSString *)dd_cacheMD5 { 15 | const char *cStr = [self UTF8String]; 16 | unsigned char result[CC_MD5_DIGEST_LENGTH]; 17 | CC_MD5(cStr, (CC_LONG)strlen(cStr), result); 18 | 19 | return [[NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", 20 | result[0], result[1], result[2], result[3], 21 | result[4], result[5], result[6], result[7], 22 | result[8], result[9], result[10], result[11], 23 | result[12], result[13], result[14], result[15] 24 | ] lowercaseString]; 25 | } 26 | 27 | - (NSDictionary *)dd_dictionaryWithJSON { 28 | NSError *jsonError = nil; 29 | NSData *jsonData = [self dataUsingEncoding:NSUTF8StringEncoding]; 30 | NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:jsonData 31 | options:NSJSONReadingAllowFragments 32 | error:&jsonError]; 33 | return dictionary; 34 | } 35 | 36 | @end 37 | 38 | -------------------------------------------------------------------------------- /DDModel/Classes/NSURLSessionTask+DDModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSURLSessionTask+DDModel.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15/4/27. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSURLSessionTask (DDModel) 12 | 13 | @property (nonatomic, strong) NSDictionary *userInfo; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /DDModel/Classes/NSURLSessionTask+DDModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSURLSessionTask+DDModel.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15/4/27. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "NSURLSessionTask+DDModel.h" 10 | #import 11 | 12 | @implementation NSURLSessionTask (DDModel) 13 | 14 | - (void)setUserInfo:(NSDictionary *)userInfo { 15 | objc_setAssociatedObject(self, @selector(userInfo), userInfo, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 16 | } 17 | 18 | - (NSDictionary *)userInfo { 19 | return objc_getAssociatedObject(self, _cmd); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /DDModel/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /DDModel/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /DDModel/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "8.0", 8 | "subtype" : "736h", 9 | "scale" : "3x" 10 | }, 11 | { 12 | "orientation" : "portrait", 13 | "idiom" : "iphone", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "8.0", 16 | "subtype" : "667h", 17 | "scale" : "2x" 18 | }, 19 | { 20 | "orientation" : "portrait", 21 | "idiom" : "iphone", 22 | "extent" : "full-screen", 23 | "minimum-system-version" : "7.0", 24 | "scale" : "2x" 25 | }, 26 | { 27 | "orientation" : "portrait", 28 | "idiom" : "iphone", 29 | "extent" : "full-screen", 30 | "minimum-system-version" : "7.0", 31 | "subtype" : "retina4", 32 | "scale" : "2x" 33 | } 34 | ], 35 | "info" : { 36 | "version" : 1, 37 | "author" : "xcode" 38 | } 39 | } -------------------------------------------------------------------------------- /DDModel/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Main 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UISupportedInterfaceOrientations 39 | 40 | UIInterfaceOrientationPortrait 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /DDModel/Post.h: -------------------------------------------------------------------------------- 1 | // 2 | // Post.h 3 | // DDKit 4 | // 5 | // Created by DeJohn Dong on 14-12-15. 6 | // Copyright (c) 2014年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "DDModel.h" 10 | 11 | @interface User : DDModel 12 | 13 | @property (nonatomic, strong) NSNumber *id; 14 | @property (nonatomic, copy) NSString *username; 15 | @property (nonatomic, copy) NSString *avatarImageURLString; 16 | 17 | @end 18 | 19 | @interface Post : DDModel 20 | 21 | @property (nonatomic, copy) NSString *text; 22 | @property (nonatomic, strong) NSNumber *id; 23 | @property (nonatomic, strong) User *user; 24 | 25 | 26 | + (void)getPostList:(id)params 27 | parentVC:(id)viewController 28 | showHUD:(BOOL)show 29 | success:(DDResponseSuccessBlock)success 30 | failure:(DDResponsesFailureBlock)failure; 31 | 32 | @end 33 | 34 | @interface Station : DDModel 35 | 36 | @property (nonatomic, strong) NSNumber *id; 37 | @property (nonatomic, copy) NSString *streamURL; 38 | @property (nonatomic, copy) NSString *picture; 39 | @property (nonatomic, copy) NSString *name; 40 | @property (nonatomic, copy) NSString *desc; 41 | 42 | + (void)getStationList:(id)params 43 | parentVC:(id)viewController 44 | showHUD:(BOOL)show 45 | dbSuccess:(DDSQLiteBlock)dbResult 46 | success:(DDResponseSuccessBlock)success 47 | failure:(DDResponsesFailureBlock)failure; 48 | 49 | @end 50 | 51 | @interface BESTItemList : DDModel 52 | 53 | @property (nonatomic, copy) NSString *brandName; 54 | @property (nonatomic, copy) NSString *image; 55 | @property (nonatomic, copy) NSString *style; 56 | @property (nonatomic, copy) NSString *title; 57 | @property (nonatomic, copy) NSString *subTitle; 58 | @property (nonatomic, strong) NSNumber *id; 59 | @property (nonatomic, strong) NSNumber *salePrice; 60 | @property (nonatomic, strong) NSNumber *marketPrice; 61 | 62 | @end 63 | 64 | @interface BESTItemListRoot : DDModel 65 | 66 | @property (nonatomic, strong) NSArray *list; 67 | @property (nonatomic) int count; 68 | 69 | + (void)getItemList:(id)params 70 | showHUD:(BOOL)show 71 | parentViewController:(id)viewController 72 | success:(DDResponseSuccessBlock)success 73 | failure:(DDResponsesFailureBlock)failure; 74 | 75 | @end -------------------------------------------------------------------------------- /DDModel/Post.m: -------------------------------------------------------------------------------- 1 | // 2 | // Post.m 3 | // DDKit 4 | // 5 | // Created by DeJohn Dong on 14-12-15. 6 | // Copyright (c) 2014年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "Post.h" 10 | #import "DDModel+DDAddition.h" 11 | 12 | @implementation Post 13 | 14 | /* 15 | * 对象解析的节点实现 16 | */ 17 | + (NSString *)parseNode{ 18 | return @"data"; 19 | } 20 | 21 | /* jsonMapping 实现 22 | * 使用场景: 23 | * 1.返回数据与数据模型不一致时通过映射对应赋值,举例: @{@"id":@"userId"} 返回数据中的id value 会赋值给数据模型的userId 24 | * 2.对象的嵌套关系,如本例里Post对象嵌套了User对象 25 | */ 26 | + (NSDictionary *)parseMappings{ 27 | /** 28 | * in [mappingWithKey:mappings:] method, key is your defined property key; 29 | * 在'mappingWithKey:mapping:'中的key值是您定义的属性名名称,所以JSON字符串中的Value会映射给该属性字段; 30 | */ 31 | id userHandler = [User mappingWithKey:@"user" mapping:[User parseMappings]]; 32 | /** 33 | * this 'user' key is the JSON String's Key 34 | * 这个字典中的'user' key值就是 JSON 字符串中的 user key; 35 | */ 36 | NSDictionary *jsonMappings = @{@"user":userHandler}; 37 | 38 | /** 39 | * 所以整个JSON的映射关系就是把JSON字符串的User内容映射给我定义属性的user属性里,内部递归的关系按照user的parseMapping执行 40 | */ 41 | return jsonMappings; 42 | } 43 | 44 | + (void)getPostList:(id)params 45 | parentVC:(id)viewController 46 | showHUD:(BOOL)show 47 | success:(DDResponseSuccessBlock)success 48 | failure:(DDResponsesFailureBlock)failure 49 | { 50 | [[self class] get:@"stream/0/posts/stream/global" params:params showHUD:show parentViewController:viewController successBlock:success failureBlock:failure]; 51 | } 52 | 53 | @end 54 | 55 | @implementation User 56 | 57 | + (NSDictionary *)parseMappings{ 58 | //支持keyPath的方式进行映射对象,可以随意重构数据对象 59 | return @{@"avatar_image.url":@"avatarImageURLString"}; 60 | } 61 | 62 | @end 63 | 64 | @implementation Station 65 | 66 | + (NSString *)parseNode{ 67 | return @"Item"; 68 | } 69 | 70 | + (NSDictionary *)parseMappings{ 71 | NSDictionary *mappings = @{@"StationID":@"id", 72 | @"StationName":@"name", 73 | @"StationDescription":@"desc"}; 74 | return mappings; 75 | } 76 | 77 | + (void)getStationList:(id)params 78 | parentVC:(id)viewController 79 | showHUD:(BOOL)show 80 | dbSuccess:(DDSQLiteBlock)dbResult 81 | success:(DDResponseSuccessBlock)success 82 | failure:(DDResponsesFailureBlock)failure{ 83 | [[self class] get:@"index.php" params:params showHUD:show parentViewController:params dbSuccess:dbResult successBlock:success failureBlock:failure]; 84 | } 85 | 86 | @end 87 | 88 | 89 | @implementation BESTItemList 90 | 91 | 92 | @end 93 | 94 | @implementation BESTItemListRoot 95 | 96 | + (NSString *)parseNode{ 97 | return @"data"; 98 | } 99 | 100 | + (NSDictionary *)parseMappings{ 101 | id handlerItemList = [BESTItemList mappingWithKey:@"list" mapping:[BESTItemList parseMappings]]; 102 | NSDictionary *mappings = @{@"list":handlerItemList}; 103 | return mappings; 104 | } 105 | 106 | + (void)getItemList:(id)params 107 | showHUD:(BOOL)show 108 | parentViewController:(id)viewController 109 | success:(DDResponseSuccessBlock)success 110 | failure:(DDResponsesFailureBlock)failure{ 111 | 112 | [[self class] post:@"/v1/search/list" params:params 113 | showHUD:show 114 | parentViewController:viewController 115 | dbSuccess:^(id data) { 116 | 117 | } 118 | successBlock:success 119 | failureBlock:failure]; 120 | 121 | } 122 | 123 | @end -------------------------------------------------------------------------------- /DDModel/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UITableViewController 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /DDModel/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "Post.h" 11 | #import "AppDelegate.h" 12 | #import "AFHTTPSessionManager+DDModel.h" 13 | #import 14 | 15 | @interface PostCell : UITableViewCell 16 | 17 | @property (nonatomic, weak) IBOutlet UILabel *lblTitle; 18 | 19 | - (void)setPost:(Post *)post; 20 | 21 | @end 22 | 23 | @implementation PostCell 24 | 25 | - (void)setPost:(Post *)post{ 26 | self.lblTitle.text = [NSString stringWithFormat:@"%@-%@",post.user.username,post.text]; 27 | } 28 | 29 | @end 30 | 31 | @interface ViewController (){ 32 | NSMutableArray *dataList; 33 | BOOL isChanged; 34 | } 35 | 36 | @end 37 | 38 | @implementation ViewController 39 | 40 | - (void)viewDidLoad { 41 | [super viewDidLoad]; 42 | // Do any additional setup after loading the view, typically from a nib. 43 | if(!dataList) 44 | dataList = [[NSMutableArray alloc] initWithCapacity:0]; 45 | 46 | self.tableView.estimatedRowHeight = 100; 47 | 48 | NSLog(@"url = %@",[DDModelHttpClient sharedInstance].baseURL); 49 | [BESTItemListRoot getItemList:@{@"sortBy":@"recommend",@"keyword":@"coach"} showHUD:YES parentViewController:self 50 | success:^(BESTItemListRoot *data) { 51 | NSLog(@"data.size = %i",(int)data.count); 52 | 53 | NSLog(@"data = %@",data); 54 | [dataList removeAllObjects]; 55 | [dataList addObjectsFromArray:data.list]; 56 | [self.tableView reloadData]; 57 | 58 | 59 | } failure:^(NSError *error, NSString *message, id data) { 60 | NSLog(@"error = %@ message = %@",error, message); 61 | }]; 62 | 63 | #if UseXMLDemo 64 | 65 | 66 | #else 67 | // [Post getPostList:nil 68 | // parentVC:self 69 | // showHUD:YES 70 | // success:^(id data) { 71 | // NSLog(@"data = %@",data); 72 | // [dataList removeAllObjects]; 73 | // [dataList addObjectsFromArray:data]; 74 | // [self.tableView reloadData]; 75 | // } 76 | // failure:^(NSError *error, NSString *message) { 77 | // }]; 78 | #endif 79 | } 80 | 81 | - (void)didReceiveMemoryWarning { 82 | [super didReceiveMemoryWarning]; 83 | // Dispose of any resources that can be recreated. 84 | } 85 | 86 | #pragma mark - UITableView DataSource Methods 87 | 88 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 89 | return dataList.count; 90 | } 91 | 92 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 93 | PostCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PostCell" forIndexPath:indexPath]; 94 | if([[DDModelHttpClient sharedInstance].baseURL.absoluteString hasPrefix:@"http://mapi.bstapp"]){ 95 | // Station *s = dataList[indexPath.row]; 96 | BESTItemList *item = dataList[indexPath.row]; 97 | cell.lblTitle.text = [NSString stringWithFormat:@"%@-%@",item.title,item.image]; 98 | }else{ 99 | Post *p = dataList[indexPath.row]; 100 | [cell setPost:p]; 101 | } 102 | return cell; 103 | } 104 | 105 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 106 | return [tableView fd_heightForCellWithIdentifier:@"PostCell" 107 | cacheByIndexPath:indexPath 108 | configuration:^(PostCell *cell) { 109 | if([[DDModelHttpClient sharedInstance].baseURL.absoluteString hasPrefix:@"http://mapi.bstapp"]){ 110 | BESTItemList *item = dataList[indexPath.row]; 111 | cell.lblTitle.text = [NSString stringWithFormat:@"%@-%@",item.title,item.image]; 112 | }else{ 113 | Post *p = dataList[indexPath.row]; 114 | [cell setPost:p]; 115 | } 116 | }];; 117 | } 118 | 119 | - (IBAction)changeURL:(id)sender{ 120 | // [[DDModelHttpClient sharedInstance] dd_addUrl:@"http://prov.mobile.arnd.fm"]; 121 | // [DDModelHttpClient sharedInstance].type = DDResponseXML; 122 | // NSLog(@"url = %@",[DDModelHttpClient sharedInstance].baseURL); 123 | // NSDictionary *params = @{@"q":@"admin/station/station/bygroupid", 124 | // @"id":@(5)}; 125 | // [Station getStationList:params 126 | // parentVC:self 127 | // showHUD:YES 128 | // dbSuccess:^(id data){ 129 | // NSLog(@"data = %@",data); 130 | // } 131 | // success:^(id data) { 132 | // NSLog(@"data = %@",data); 133 | // [dataList removeAllObjects]; 134 | // [dataList addObjectsFromArray:data]; 135 | // [self.tableView reloadData]; 136 | // } 137 | // failure:^(NSError *error, NSString *message) { 138 | // NSLog(@"error = %@ message = %@",error, message); 139 | // }]; 140 | 141 | if(!isChanged){ 142 | [[DDModelHttpClient sharedInstance] dd_addURL:@"https://api.app.net/"]; 143 | NSLog(@"url = %@",[DDModelHttpClient sharedInstance].baseURL); 144 | [Post getPostList:nil 145 | parentVC:self 146 | showHUD:YES 147 | success:^(id data) { 148 | NSLog(@"data = %@",data); 149 | [dataList removeAllObjects]; 150 | [dataList addObjectsFromArray:data]; 151 | [self.tableView reloadData]; 152 | } 153 | failure:^(NSError *error, NSString *message, id data) { 154 | }]; 155 | }else{ 156 | [[DDModelHttpClient sharedInstance] dd_addURL:@"http://mapi.bstapp.cn"]; 157 | NSLog(@"url = %@",[DDModelHttpClient sharedInstance].baseURL); 158 | [BESTItemListRoot getItemList:@{@"sortBy":@"recommend",@"keyword":@"coach"} 159 | showHUD:YES 160 | parentViewController:self 161 | success:^(BESTItemListRoot *data) { 162 | NSLog(@"data.size = %i",(int)data.count); 163 | 164 | NSLog(@"data = %@",data); 165 | [dataList removeAllObjects]; 166 | [dataList addObjectsFromArray:data.list]; 167 | [self.tableView reloadData]; 168 | 169 | 170 | } failure:^(NSError *error, NSString *message, id data) { 171 | NSLog(@"error = %@ message = %@",error, message); 172 | }]; 173 | } 174 | isChanged = !isChanged; 175 | } 176 | 177 | @end 178 | -------------------------------------------------------------------------------- /DDModel/adn.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openboy2012/DDModel/f9cbf2d1822cddc5440d16ab4bf5fa38b96e29c3/DDModel/adn.cer -------------------------------------------------------------------------------- /DDModel/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DDModel 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DDModel/root_ca.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openboy2012/DDModel/f9cbf2d1822cddc5440d16ab4bf5fa38b96e29c3/DDModel/root_ca.cer -------------------------------------------------------------------------------- /DDModelTests/DDModelTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // DDModelTests.m 3 | // DDModelTests 4 | // 5 | // Created by DeJohn Dong on 15-2-4. 6 | // Copyright (c) 2015年 DDKit. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface DDModelTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation DDModelTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /DDModelTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 DDModel (dongjia_9251@126.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | source 'https://github.com/CocoaPods/Specs.git' 2 | 3 | platform :ios, '7.0' 4 | 5 | target 'DDModel' do 6 | pod 'AFNetworking', '~> 3.1.0' 7 | pod 'SQLitePersistentObject', '~> 0.3.2' 8 | pod 'JTObjectMapping', '1.1.2' 9 | pod 'MBProgressHUD','~> 0.9.2' 10 | pod 'XMLDictionary','1.4' 11 | pod 'UITableView+FDTemplateLayoutCell', '~> 1.3' 12 | end 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DDModel 2 | ps:my English isn't 100% fluent,but I am trying to improve it. 3 | 4 | ##a HTTP-JSON-ORM-Persisent Object Kit. 5 | DDModel inherit SQLitePersisentObject so you can save objects into SQLite immediately. 6 | DDModel package the http request to reduce the UIViewController & http code coupling, you won't worried how to package http request in your project any more when you use the DDModelKit. 7 | Your development will be simple. 8 | 9 | if you should support iOS 6.0, please use the version 0.x, 10 | now, I will have more working on the version 1.x, 1.x version need iOS 7.0 and Later. 11 | 12 | ##Installation 13 | 14 | [![Version](http://cocoapod-badges.herokuapp.com/v/DDModel/badge.png)](http://cocoadocs.org/docsets/DDModel/) [![Platform](http://cocoapod-badges.herokuapp.com/p/DDModel/badge.png)](http://cocoadocs.org/docsets/DDModel/) 15 | DDModel is available through [CocoaPods](http://cocoapods.org), to install 16 | it simply add the following line to your Podfile: 17 | 18 | pod "DDModel" 19 | Alternatively, you can just drag the files from `DDModel / Classes` into your own project. then you should clone the repositories: [AFNetworking](https://github.com/AFNetworking/AFNetworking)、[XMLDictionary](https://github.com/nicklockwood/XMLDictionary)、[JTObjectMapping](https://github.com/jamztang/JTObjectMapping)、[SQLitePersistentObject](https://github.com/openboy2012/DDSQLiteKit)、[MBProgressHUD](https://github.com/jdg/MBProgressHUD) 20 | 21 | ## Usage 22 | 23 | To run the example project; clone the repo, and run `pod install` from the Project directory first. 24 | 25 | 1.import `DDModelKit.h` in your project 26 | 27 | 2.initialize a DDModelHttpClient in your gobal object, such as AppDelegate; 28 | for example: 29 | ```objective-c 30 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 31 | // Override point for customization after application launch. 32 | 33 | [DDModelHttpClient startWithURL:@"https://api.app.net/" delegate:self]; // initialzie a DDModelHttpClient 34 | 35 | return YES; 36 | } 37 | ``` 38 | 39 | You can set response type use the property of DDModelHttpClient like this: `[DDModelHttpClient sharedInstance].type = DDResponseXML`. so httpClient will handle the reponse datatype is XML. 40 | 41 | Please implement the Protocol Methods `- (NSDictionary *)encodeParameters:(NSDictionary *)params;` or `- (NSString *)decodeResponseString:(NSString *)responseString; ` if you want to handle http request parameters or response string. 42 | 43 | you should implement the Protocol Method `- (BOOL)checkResponseValueAvailable:(NSDictionary *)values failure:(DDResponsesFailureBlock)failure` if you have custom business logic in your API. 44 | 45 | for example: 46 | 47 | ```objective-c 48 | #pragma mark - DDHttpClient Delegate Method 49 | 50 | - (NSDictionary *)encodeParameters:(NSDictionary *)params{ 51 | 52 | // encode the the paramters 53 | NSMutableDictionary *finalParams = [NSMutableDictionary dictionaryWithDictionary:params]; 54 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 55 | formatter.dateFormat = @"yyyyMMddHHmmss"; 56 | NSString *times = [formatter stringFromDate:[NSDate date]]; 57 | [finalParams setObject:times forKey:@"time"]; 58 | NSString *parameterString = [self ddEncode:finalParams]; 59 | NSString *beforeSign = [NSString stringWithFormat:@"%@&%@&%@",PLATFORM,APP_KEY,parameterString]; 60 | [finalParams setObject:[beforeSign md5] forKey:@"sign"]; 61 | return finalParams; 62 | } 63 | 64 | - (NSString *)decodeResponseString:(NSString *)responseString{ 65 | NSLog(@"responseString = %@",responseString); 66 | return responseString; 67 | } 68 | 69 | - (BOOL)checkResponseValueAvailable:(NSDictionary *)values 70 | failure:(DDResponseFailureBlock)failure{ 71 | // handler your owner business logic 72 | if([[values objectForKey:@"returnCode"] isEqualToString:@"0000"]) 73 | return YES; 74 | else{ 75 | if(failure){ 76 | failure([NSError errorWithDomain:@"ddmodel.validate.error" code:1001 userInfo:nil],[values objectForKey:@"returnMessage"]); 77 | } 78 | return NO; 79 | } 80 | } 81 | 82 | ``` 83 | 84 | 3.create any entity inherit DDModel Class. 85 | Define the property according the JSON value Property. 86 | for exmale: 87 | JSON: 88 | ```javascript 89 | {"created_at":"2015-03-09T06:45:45Z","num_stars":0,"num_replies":0,"source":{"link":"http://themodernink.com/portfolio/dash-for-app-net/","name":"Dash","client_id":"nxz5USfARxELsYVpfPJc3mYaX42USb2E"},"text":"K\u00f6nnen wir bitte nochmal Sonntag haben? So einen wie gestern - nur mit anderem Spielergebnis der Eintracht? ","num_reposts":0,"id":"54842887","canonical_url":"https://alpha.app.net/berenike/post/54842887","entities":{"mentions":[],"hashtags":[],"links":[]},"html":"Können wir bitte nochmal Sonntag haben? So einen wie gestern - nur mit anderem Spielergebnis der Eintracht? ","machine_only":false,"user":{"username":"berenike","avatar_image":{"url":"https://d1f0fplrc06slp.cloudfront.net/assets/user/68/b6/70/68b6700000000000.gif","width":500,"is_default":false,"height":500},"description":{"text":"irgendwie is hier anders.\r\nhttp://keinnaturtalent.wordpress.com\r\nhttp://franziskanaja.tumblr.com/","html":"irgendwie is hier anders.
http://keinnaturtalent.wordpress.com
http://franziskanaja.tumblr.com/
","entities":{"mentions":[],"hashtags":[],"links":[{"url":"http://keinnaturtalent.wordpress.com","text":"http://keinnaturtalent.wordpress.com","pos":27,"len":36},{"url":"http://franziskanaja.tumblr.com/","text":"http://franziskanaja.tumblr.com/","pos":65,"len":32}]}},"locale":"de_DE","created_at":"2013-05-26T12:20:30Z","canonical_url":"https://alpha.app.net/berenike","cover_image":{"url":"https://d2rfichhc2fb9n.cloudfront.net/image/5/77Bi7kWHejTDAceY-gaw4B0h2SF7InMiOiJzMyIsImIiOiJhZG4tdXNlci1hc3NldHMiLCJrIjoiYXNzZXRzL3VzZXIvZTEvNDcvNDAvZTE0NzQwMDAwMDAwMDAwMC5qcGciLCJvIjoiIn0","width":960,"is_default":false,"height":300},"timezone":"Europe/Berlin","counts":{"following":40,"posts":682,"followers":43,"stars":340},"type":"human","id":"108262","name":"Franziska Naja"},"thread_id":"54842887","pagination_id":"54842887"} 90 | ``` 91 | Model Define: 92 | ```objective-c 93 | @interface User : DDModel 94 | 95 | @property (nonatomic, strong) NSNumber *id; 96 | @property (nonatomic, copy) NSString *username; 97 | @property (nonatomic, copy) NSString *avatarImageURLString; 98 | 99 | @end 100 | 101 | @interface Post : DDModel 102 | 103 | @property (nonatomic, copy) NSString *text; 104 | @property (nonatomic, strong) NSNumber *id; 105 | @property (nonatomic, strong) User *user; 106 | 107 | 108 | + (void)getPostList:(id)params 109 | parentVC:(id)viewController 110 | showHUD:(BOOL)show 111 | success:(DDResponseSuccessBlock)success 112 | failure:(DDResponsesFailureBlock)failure; 113 | 114 | @end 115 | 116 | #import "Post.h" 117 | 118 | @implementation Post 119 | 120 | + (NSString *)parseNode{ 121 | return @"data"; 122 | } 123 | 124 | // ovrride this method if your define propery is not the same key in json string. or the object contain Nested objects 125 | + (NSDictionary *)parseMappings{ 126 | id userHandler = [User mappingWithKey:@"user" mapping:[User parseMappings]]; 127 | NSDictionary *jsonMappings = @{@"user":userHandler}; 128 | return jsonMappings; 129 | } 130 | 131 | // a demo method of get data 132 | + (void)getPostList:(id)params 133 | parentVC:(id)viewController 134 | showHUD:(BOOL)show 135 | success:(DDResponseSuccessBlock)success 136 | failure:(DDResponseFailureBlock)failure 137 | { 138 | [[self class] get:@"stream/0/posts/stream/global" params:params showHUD:show parentViewController:viewController successBlock:success failureBlock:failure]; 139 | } 140 | 141 | @end 142 | 143 | @implementation User 144 | 145 | + (NSDictionary *)parseMappings{ 146 | // support for KeyPath 147 | return @{@"avatar_image.url":@"avatarImageURLString"}; 148 | } 149 | 150 | @end 151 | ``` 152 | 153 | 4.Please see more in demo project,thanks. 154 | 155 | ## Methods 156 | 157 | ##### DDModelHttpClient.h 158 | ```objective-c 159 | /** 160 | * Start a singleton HTTP client with url. 161 | * 162 | * @param url HTTP target url 163 | */ 164 | + (void)startWithURL:(NSString *)url; 165 | 166 | /** 167 | * Start a singleton HTTP client with url & delegate 168 | * 169 | * @param url HTTP target url 170 | * @param delegate DDHttpClientDelegate 171 | */ 172 | + (void)startWithURL:(NSString *)url delegate:(id)delegate; 173 | 174 | /** 175 | * Set the HTTP header field value 176 | * 177 | * @param keyValue keyValue 178 | */ 179 | + (void)addHTTPHeaderFieldValue:(NSDictionary *)keyValue; 180 | 181 | /** 182 | * Remove the HTTP header field value 183 | * 184 | * @param keyValue keyValue 185 | */ 186 | + (void)removeHTTPHeaderFieldValue:(NSDictionary *)keyValue; 187 | 188 | @protocol DDHttpClientDelegate 189 | 190 | @optional 191 | /** 192 | * Parameter encode method if you should encode the parameter in your HTTP client 193 | * 194 | * @param params original parameters 195 | * 196 | * @return endcoded parameters 197 | */ 198 | - (NSDictionary *)encodeParameters:(NSDictionary *)params; 199 | 200 | /** 201 | * Response String decode methods in you HTTP client 202 | * 203 | * @param responseString origin responseString 204 | * 205 | * @return new responseString 206 | */ 207 | - (NSString *)decodeResponseString:(NSString *)responseString; 208 | 209 | /** 210 | * Check the response values is an avaliable value. 211 | e.g. You will sign in an account but you press a wrong username/password, server will response a error for you, you can catch them use this protocol methods and handle this error exception. 212 | * 213 | * @param values should check value 214 | * @param failure failure block 215 | * 216 | * @return true or false 217 | */ 218 | - (BOOL)checkResponseValueAvailable:(NSDictionary *)values failure:(DDResponseFailureBlock)failure; 219 | 220 | @end 221 | 222 | ``` 223 | 224 | ##### DDModel.h 225 | 226 | ```objective-c 227 | @protocol DDMappings 228 | 229 | /** 230 | * Set the parse node, every subclass override the method if you want parse any node 231 | * 232 | * @return node 233 | */ 234 | + (NSString *)parseNode; 235 | 236 | /** 237 | * Handle the mappings about the json key-value transform to a model object. 238 | The method support for KeyPathValue. e.g. you have a @property name, you want get value from "{user:{name:'mike',id:10011},picture:'https://xxxx/headerimage/header01.jpg'}", you just set mapping dictionary is @{@"user.name":@"name"}. 239 | * 240 | * @return mappings 241 | */ 242 | + (NSDictionary *)parseMappings; 243 | 244 | @end 245 | 246 | /** 247 | * Get json data first from db cache then from http server by HTTP GET Mehod. 248 | * 249 | * @param path HTTP Path 250 | * @param params GET Paramtters 251 | * @param dbResult db cache result block 252 | * @param success success block 253 | * @param failure failre block 254 | * 255 | * @return NSURLSessionDataTask 256 | */ 257 | + (NSURLSessionDataTask *)get:(NSString *)path 258 | params:(id)params 259 | dbSuccess:(DDSQLiteBlock)dbResult 260 | success:(DDResponseSuccessBlock)success 261 | failure:(DDResponsesFailureBlock)failure; 262 | 263 | /** 264 | * Get json data first from db cache then from http server by HTTP POST Mehod. 265 | * 266 | * @param path HTTP Path 267 | * @param params GET Paramtters 268 | * @param dbResult db cache result block 269 | * @param success success block 270 | * @param failure failre block 271 | * 272 | * @return NSURLSessionDataTask 273 | */ 274 | + (NSURLSessionDataTask *)post:(NSString *)path 275 | params:(id)params 276 | dbSuccess:(DDSQLiteBlock)dbResult 277 | success:(DDResponseSuccessBlock)success 278 | failure:(DDResponsesFailureBlock)failure; 279 | 280 | /** 281 | * Get json data from http server by HTTP GET Mehod. 282 | * 283 | * @param path HTTP Path 284 | * @param params GET Paramtters 285 | * @param success success block 286 | * @param failure failre block 287 | * 288 | * @return NSURLSessionDataTask 289 | */ 290 | + (NSURLSessionDataTask *)get:(NSString *)path 291 | params:(id)params 292 | success:(DDResponseSuccessBlock)success 293 | failure:(DDResponsesFailureBlock)failure; 294 | 295 | /** 296 | * Get json data from http server by HTTP POST Mehod. 297 | * 298 | * @param path HTTP Path 299 | * @param params POST Paramtters 300 | * @param success success block 301 | * @param failure failre block 302 | * 303 | * @return NSURLSessionDataTask 304 | */ 305 | + (NSURLSessionDataTask *)post:(NSString *)path 306 | params:(id)params 307 | success:(DDResponseSuccessBlock)success 308 | failure:(DDResponsesFailureBlock)failure; 309 | 310 | /** 311 | * Upload a data stream to http server by HTTP POST Method. 312 | * 313 | * @param path HTTP Path 314 | * @param stream stream data 315 | * @param params POST Parameters 316 | * @param userInfo userInfo dictionary 317 | * @param success success block 318 | * @param failure failure block 319 | * 320 | * @return NSURLSessionDataTask 321 | */ 322 | + (NSURLSessionDataTask *)post:(NSString *)path 323 | fileStream:(NSData *)stream 324 | params:(id)params 325 | userInfo:(id)userInfo 326 | success:(DDUploadReponseSuccessBlock)success 327 | failure:(DDResponsesFailureBlock)failure; 328 | 329 | /** 330 | * Parse self entity into a dictionary 331 | * 332 | * @return a dictionary of self entity 333 | */ 334 | - (NSDictionary *)propertiesOfObject; 335 | 336 | ``` 337 | 338 | you can see more method in the project, there are aslo have many categories in the project. 339 | 340 | ## Updates 341 | - 1.1 Code refactoring and add the feature about url change when http client runing. 342 | - 1.0 Use the NSURLSession replace NSURLConnection 343 | 344 | - 0.4 Add the db cache function 345 | - 0.3 Add the xml parser function 346 | - 0.2 Add the function of check api business logic 347 | 348 | ## Requirements 349 | 350 | - Xcode 6 351 | - iOS 5.1.1 or Mac OSX 10.8 (0.x)/ iOS 7.0 and Later or OSX 10.9 (1.x) 352 | 353 | ## Author 354 | 355 | DeJohn Dong, dongjia_9251@126.com 356 | 357 | ## License 358 | 359 | DDModel is available under the MIT license. See the LICENSE file for more info. 360 | --------------------------------------------------------------------------------