├── .gitignore ├── .gitmodules ├── .swift-version ├── .travis.yml ├── Cartfile ├── Cartfile.private ├── Cartfile.resolved ├── Example ├── Example.xcodeproj │ └── project.pbxproj └── Example │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── BatchRequestViewController.swift │ ├── Info.plist │ ├── MathService.swift │ ├── SingleRequestViewController.swift │ └── UIViewController+Error.swift ├── JSONRPCKit.podspec ├── JSONRPCKit.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── JSONRPCKit.xcscheme ├── JSONRPCKit.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── JSONRPCKit.xcscmblueprint ├── LICENSE.md ├── Package.resolved ├── Package.swift ├── README.md ├── Sources └── JSONRPCKit │ ├── Batch.swift │ ├── BatchElement.swift │ ├── BatchFactory.swift │ ├── Id.swift │ ├── IdGenerator.swift │ ├── Info.plist │ ├── JSONRPCError.swift │ ├── JSONRPCKit.h │ ├── NumberIdGenerator.swift │ └── Request.swift └── Tests ├── JSONRPCKitTests ├── BatchElementTests.swift ├── BatchFactoryTests.swift ├── Info.plist └── TestRequest.swift └── LinuxMain.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | 35 | # Swift Package Manager 36 | 37 | .build 38 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Carthage/Checkouts/Result"] 2 | path = Carthage/Checkouts/Result 3 | url = https://github.com/antitypical/Result.git 4 | [submodule "Carthage/Checkouts/APIKit"] 5 | path = Carthage/Checkouts/APIKit 6 | url = https://github.com/ishkawa/APIKit.git 7 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | global: 3 | - LC_CTYPE=en_US.UTF-8 4 | 5 | branches: 6 | only: 7 | - master 8 | 9 | matrix: 10 | include: 11 | - os: osx 12 | osx_image: xcode9 13 | language: objective-c 14 | env: 15 | - JOB=Xcode 16 | script: 17 | - set -o pipefail 18 | - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit | xcpretty -c 19 | - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk iphonesimulator -destination "name=iPhone SE" | xcpretty -c 20 | - xcodebuild build-for-testing test-without-building -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk appletvsimulator -destination "name=Apple TV 1080p" | xcpretty -c 21 | - xcodebuild build -workspace JSONRPCKit.xcworkspace -scheme JSONRPCKit -sdk watchsimulator | xcpretty -c 22 | - pod lib lint 23 | - os: osx 24 | osx_image: xcode9 25 | language: generic 26 | env: 27 | - JOB=SPM 28 | script: 29 | - swift --version 30 | - swift build 31 | - swift test 32 | - os: linux 33 | language: generic 34 | env: 35 | - JOB=Linux 36 | - SWIFT_VERSION=4.0.3 37 | script: 38 | - swift --version 39 | - swift build 40 | - swift test 41 | sudo: required 42 | dist: trusty 43 | install: 44 | - eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)" 45 | 46 | notifications: 47 | email: false 48 | -------------------------------------------------------------------------------- /Cartfile: -------------------------------------------------------------------------------- 1 | github "antitypical/Result" ~> 3.2.0 2 | -------------------------------------------------------------------------------- /Cartfile.private: -------------------------------------------------------------------------------- 1 | github "ishkawa/APIKit" ~> 3.2.0 2 | -------------------------------------------------------------------------------- /Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "antitypical/Result" "3.2.4" 2 | github "ishkawa/APIKit" "3.2.0" 3 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7FD0A33F1D4B5926007C9EAB /* APIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7FD0A33E1D4B5926007C9EAB /* APIKit.framework */; }; 11 | 7FD0A3431D4B5E80007C9EAB /* UIViewController+Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FD0A3421D4B5E80007C9EAB /* UIViewController+Error.swift */; }; 12 | CB31EFB11CF6E88100DD13DD /* JSONRPCKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB31EFB01CF6E88100DD13DD /* JSONRPCKit.framework */; }; 13 | CB31EFB21CF6E88100DD13DD /* JSONRPCKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = CB31EFB01CF6E88100DD13DD /* JSONRPCKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 14 | CB31EFB41CF6E88800DD13DD /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB31EFB31CF6E88800DD13DD /* Result.framework */; }; 15 | CB31EFB51CF6E88800DD13DD /* Result.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = CB31EFB31CF6E88800DD13DD /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 16 | CB63E2471CE2309100E22B5C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB63E2461CE2309100E22B5C /* AppDelegate.swift */; }; 17 | CB63E24C1CE2309100E22B5C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CB63E24A1CE2309100E22B5C /* Main.storyboard */; }; 18 | CB63E24E1CE2309100E22B5C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CB63E24D1CE2309100E22B5C /* Assets.xcassets */; }; 19 | CB63E2511CE2309100E22B5C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CB63E24F1CE2309100E22B5C /* LaunchScreen.storyboard */; }; 20 | CB63E25B1CE230E300E22B5C /* SingleRequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB63E2581CE230E300E22B5C /* SingleRequestViewController.swift */; }; 21 | CB63E25C1CE230E300E22B5C /* MathService.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB63E2591CE230E300E22B5C /* MathService.swift */; }; 22 | CB63E25D1CE230E300E22B5C /* BatchRequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB63E25A1CE230E300E22B5C /* BatchRequestViewController.swift */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXCopyFilesBuildPhase section */ 26 | CB31EFAF1CF6E84400DD13DD /* Embed Frameworks */ = { 27 | isa = PBXCopyFilesBuildPhase; 28 | buildActionMask = 2147483647; 29 | dstPath = ""; 30 | dstSubfolderSpec = 10; 31 | files = ( 32 | CB31EFB21CF6E88100DD13DD /* JSONRPCKit.framework in Embed Frameworks */, 33 | CB31EFB51CF6E88800DD13DD /* Result.framework in Embed Frameworks */, 34 | ); 35 | name = "Embed Frameworks"; 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXCopyFilesBuildPhase section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 7FD0A33E1D4B5926007C9EAB /* APIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = APIKit.framework; path = ../Carthage/Checkouts/APIKit/build/Debug/APIKit.framework; sourceTree = ""; }; 42 | 7FD0A3421D4B5E80007C9EAB /* UIViewController+Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Error.swift"; sourceTree = ""; }; 43 | CB31EFB01CF6E88100DD13DD /* JSONRPCKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = JSONRPCKit.framework; path = "../Debug-iphonesimulator/JSONRPCKit.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | CB31EFB31CF6E88800DD13DD /* Result.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Result.framework; path = "../Debug-iphonesimulator/Result.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | CB31EFB61CF6E8B400DD13DD /* Alamofire.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Alamofire.framework; path = "../Debug-iphonesimulator/Alamofire.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | CB63E2431CE2309100E22B5C /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | CB63E2461CE2309100E22B5C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 48 | CB63E24B1CE2309100E22B5C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 49 | CB63E24D1CE2309100E22B5C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 50 | CB63E2501CE2309100E22B5C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 51 | CB63E2521CE2309100E22B5C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | CB63E2581CE230E300E22B5C /* SingleRequestViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleRequestViewController.swift; sourceTree = ""; }; 53 | CB63E2591CE230E300E22B5C /* MathService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MathService.swift; sourceTree = ""; }; 54 | CB63E25A1CE230E300E22B5C /* BatchRequestViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchRequestViewController.swift; sourceTree = ""; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | CB63E2401CE2309100E22B5C /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | 7FD0A33F1D4B5926007C9EAB /* APIKit.framework in Frameworks */, 63 | CB31EFB11CF6E88100DD13DD /* JSONRPCKit.framework in Frameworks */, 64 | CB31EFB41CF6E88800DD13DD /* Result.framework in Frameworks */, 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | /* End PBXFrameworksBuildPhase section */ 69 | 70 | /* Begin PBXGroup section */ 71 | CB63E23A1CE2309100E22B5C = { 72 | isa = PBXGroup; 73 | children = ( 74 | CB63E2451CE2309100E22B5C /* Example */, 75 | CB63E2441CE2309100E22B5C /* Products */, 76 | CB63E26E1CE232C700E22B5C /* Frameworks */, 77 | ); 78 | sourceTree = ""; 79 | }; 80 | CB63E2441CE2309100E22B5C /* Products */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | CB63E2431CE2309100E22B5C /* Example.app */, 84 | ); 85 | name = Products; 86 | sourceTree = ""; 87 | }; 88 | CB63E2451CE2309100E22B5C /* Example */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | CB63E24A1CE2309100E22B5C /* Main.storyboard */, 92 | CB63E2461CE2309100E22B5C /* AppDelegate.swift */, 93 | CB63E2581CE230E300E22B5C /* SingleRequestViewController.swift */, 94 | CB63E25A1CE230E300E22B5C /* BatchRequestViewController.swift */, 95 | CB63E2591CE230E300E22B5C /* MathService.swift */, 96 | 7FD0A3421D4B5E80007C9EAB /* UIViewController+Error.swift */, 97 | CB63E2521CE2309100E22B5C /* Info.plist */, 98 | CB63E24D1CE2309100E22B5C /* Assets.xcassets */, 99 | CB63E24F1CE2309100E22B5C /* LaunchScreen.storyboard */, 100 | ); 101 | path = Example; 102 | sourceTree = ""; 103 | }; 104 | CB63E26E1CE232C700E22B5C /* Frameworks */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 7FD0A33E1D4B5926007C9EAB /* APIKit.framework */, 108 | CB31EFB61CF6E8B400DD13DD /* Alamofire.framework */, 109 | CB31EFB01CF6E88100DD13DD /* JSONRPCKit.framework */, 110 | CB31EFB31CF6E88800DD13DD /* Result.framework */, 111 | ); 112 | name = Frameworks; 113 | sourceTree = ""; 114 | }; 115 | /* End PBXGroup section */ 116 | 117 | /* Begin PBXNativeTarget section */ 118 | CB63E2421CE2309100E22B5C /* Example */ = { 119 | isa = PBXNativeTarget; 120 | buildConfigurationList = CB63E2551CE2309100E22B5C /* Build configuration list for PBXNativeTarget "Example" */; 121 | buildPhases = ( 122 | CB63E23F1CE2309100E22B5C /* Sources */, 123 | CB63E2401CE2309100E22B5C /* Frameworks */, 124 | CB63E2411CE2309100E22B5C /* Resources */, 125 | CB31EFAF1CF6E84400DD13DD /* Embed Frameworks */, 126 | ); 127 | buildRules = ( 128 | ); 129 | dependencies = ( 130 | ); 131 | name = Example; 132 | productName = Example; 133 | productReference = CB63E2431CE2309100E22B5C /* Example.app */; 134 | productType = "com.apple.product-type.application"; 135 | }; 136 | /* End PBXNativeTarget section */ 137 | 138 | /* Begin PBXProject section */ 139 | CB63E23B1CE2309100E22B5C /* Project object */ = { 140 | isa = PBXProject; 141 | attributes = { 142 | LastSwiftUpdateCheck = 0730; 143 | LastUpgradeCheck = 0920; 144 | ORGANIZATIONNAME = "Shinichiro Oba"; 145 | TargetAttributes = { 146 | CB63E2421CE2309100E22B5C = { 147 | CreatedOnToolsVersion = 7.3.1; 148 | LastSwiftMigration = 0920; 149 | }; 150 | }; 151 | }; 152 | buildConfigurationList = CB63E23E1CE2309100E22B5C /* Build configuration list for PBXProject "Example" */; 153 | compatibilityVersion = "Xcode 3.2"; 154 | developmentRegion = English; 155 | hasScannedForEncodings = 0; 156 | knownRegions = ( 157 | en, 158 | Base, 159 | ); 160 | mainGroup = CB63E23A1CE2309100E22B5C; 161 | productRefGroup = CB63E2441CE2309100E22B5C /* Products */; 162 | projectDirPath = ""; 163 | projectRoot = ""; 164 | targets = ( 165 | CB63E2421CE2309100E22B5C /* Example */, 166 | ); 167 | }; 168 | /* End PBXProject section */ 169 | 170 | /* Begin PBXResourcesBuildPhase section */ 171 | CB63E2411CE2309100E22B5C /* Resources */ = { 172 | isa = PBXResourcesBuildPhase; 173 | buildActionMask = 2147483647; 174 | files = ( 175 | CB63E2511CE2309100E22B5C /* LaunchScreen.storyboard in Resources */, 176 | CB63E24E1CE2309100E22B5C /* Assets.xcassets in Resources */, 177 | CB63E24C1CE2309100E22B5C /* Main.storyboard in Resources */, 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | }; 181 | /* End PBXResourcesBuildPhase section */ 182 | 183 | /* Begin PBXSourcesBuildPhase section */ 184 | CB63E23F1CE2309100E22B5C /* Sources */ = { 185 | isa = PBXSourcesBuildPhase; 186 | buildActionMask = 2147483647; 187 | files = ( 188 | CB63E25C1CE230E300E22B5C /* MathService.swift in Sources */, 189 | 7FD0A3431D4B5E80007C9EAB /* UIViewController+Error.swift in Sources */, 190 | CB63E25B1CE230E300E22B5C /* SingleRequestViewController.swift in Sources */, 191 | CB63E25D1CE230E300E22B5C /* BatchRequestViewController.swift in Sources */, 192 | CB63E2471CE2309100E22B5C /* AppDelegate.swift in Sources */, 193 | ); 194 | runOnlyForDeploymentPostprocessing = 0; 195 | }; 196 | /* End PBXSourcesBuildPhase section */ 197 | 198 | /* Begin PBXVariantGroup section */ 199 | CB63E24A1CE2309100E22B5C /* Main.storyboard */ = { 200 | isa = PBXVariantGroup; 201 | children = ( 202 | CB63E24B1CE2309100E22B5C /* Base */, 203 | ); 204 | name = Main.storyboard; 205 | sourceTree = ""; 206 | }; 207 | CB63E24F1CE2309100E22B5C /* LaunchScreen.storyboard */ = { 208 | isa = PBXVariantGroup; 209 | children = ( 210 | CB63E2501CE2309100E22B5C /* Base */, 211 | ); 212 | name = LaunchScreen.storyboard; 213 | sourceTree = ""; 214 | }; 215 | /* End PBXVariantGroup section */ 216 | 217 | /* Begin XCBuildConfiguration section */ 218 | CB63E2531CE2309100E22B5C /* Debug */ = { 219 | isa = XCBuildConfiguration; 220 | buildSettings = { 221 | ALWAYS_SEARCH_USER_PATHS = NO; 222 | CLANG_ANALYZER_NONNULL = YES; 223 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 224 | CLANG_CXX_LIBRARY = "libc++"; 225 | CLANG_ENABLE_MODULES = YES; 226 | CLANG_ENABLE_OBJC_ARC = YES; 227 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_COMMA = YES; 230 | CLANG_WARN_CONSTANT_CONVERSION = YES; 231 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INFINITE_RECURSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 237 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 239 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 240 | CLANG_WARN_STRICT_PROTOTYPES = YES; 241 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 242 | CLANG_WARN_UNREACHABLE_CODE = YES; 243 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 244 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 245 | COPY_PHASE_STRIP = NO; 246 | DEBUG_INFORMATION_FORMAT = dwarf; 247 | ENABLE_STRICT_OBJC_MSGSEND = YES; 248 | ENABLE_TESTABILITY = YES; 249 | GCC_C_LANGUAGE_STANDARD = gnu99; 250 | GCC_DYNAMIC_NO_PIC = NO; 251 | GCC_NO_COMMON_BLOCKS = YES; 252 | GCC_OPTIMIZATION_LEVEL = 0; 253 | GCC_PREPROCESSOR_DEFINITIONS = ( 254 | "DEBUG=1", 255 | "$(inherited)", 256 | ); 257 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 258 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 259 | GCC_WARN_UNDECLARED_SELECTOR = YES; 260 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 261 | GCC_WARN_UNUSED_FUNCTION = YES; 262 | GCC_WARN_UNUSED_VARIABLE = YES; 263 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 264 | MTL_ENABLE_DEBUG_INFO = YES; 265 | ONLY_ACTIVE_ARCH = YES; 266 | SDKROOT = iphoneos; 267 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 268 | TARGETED_DEVICE_FAMILY = "1,2"; 269 | }; 270 | name = Debug; 271 | }; 272 | CB63E2541CE2309100E22B5C /* Release */ = { 273 | isa = XCBuildConfiguration; 274 | buildSettings = { 275 | ALWAYS_SEARCH_USER_PATHS = NO; 276 | CLANG_ANALYZER_NONNULL = YES; 277 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 278 | CLANG_CXX_LIBRARY = "libc++"; 279 | CLANG_ENABLE_MODULES = YES; 280 | CLANG_ENABLE_OBJC_ARC = YES; 281 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 282 | CLANG_WARN_BOOL_CONVERSION = YES; 283 | CLANG_WARN_COMMA = YES; 284 | CLANG_WARN_CONSTANT_CONVERSION = YES; 285 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 286 | CLANG_WARN_EMPTY_BODY = YES; 287 | CLANG_WARN_ENUM_CONVERSION = YES; 288 | CLANG_WARN_INFINITE_RECURSION = YES; 289 | CLANG_WARN_INT_CONVERSION = YES; 290 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 291 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 292 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 293 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 294 | CLANG_WARN_STRICT_PROTOTYPES = YES; 295 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 296 | CLANG_WARN_UNREACHABLE_CODE = YES; 297 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 298 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 299 | COPY_PHASE_STRIP = NO; 300 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 301 | ENABLE_NS_ASSERTIONS = NO; 302 | ENABLE_STRICT_OBJC_MSGSEND = YES; 303 | GCC_C_LANGUAGE_STANDARD = gnu99; 304 | GCC_NO_COMMON_BLOCKS = YES; 305 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 306 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 307 | GCC_WARN_UNDECLARED_SELECTOR = YES; 308 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 309 | GCC_WARN_UNUSED_FUNCTION = YES; 310 | GCC_WARN_UNUSED_VARIABLE = YES; 311 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 312 | MTL_ENABLE_DEBUG_INFO = NO; 313 | SDKROOT = iphoneos; 314 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 315 | TARGETED_DEVICE_FAMILY = "1,2"; 316 | VALIDATE_PRODUCT = YES; 317 | }; 318 | name = Release; 319 | }; 320 | CB63E2561CE2309100E22B5C /* Debug */ = { 321 | isa = XCBuildConfiguration; 322 | buildSettings = { 323 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 324 | INFOPLIST_FILE = Example/Info.plist; 325 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 326 | PRODUCT_BUNDLE_IDENTIFIER = com.bricklife.ios.Example; 327 | PRODUCT_NAME = "$(TARGET_NAME)"; 328 | SWIFT_VERSION = 4.0; 329 | }; 330 | name = Debug; 331 | }; 332 | CB63E2571CE2309100E22B5C /* Release */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 336 | INFOPLIST_FILE = Example/Info.plist; 337 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 338 | PRODUCT_BUNDLE_IDENTIFIER = com.bricklife.ios.Example; 339 | PRODUCT_NAME = "$(TARGET_NAME)"; 340 | SWIFT_VERSION = 4.0; 341 | }; 342 | name = Release; 343 | }; 344 | /* End XCBuildConfiguration section */ 345 | 346 | /* Begin XCConfigurationList section */ 347 | CB63E23E1CE2309100E22B5C /* Build configuration list for PBXProject "Example" */ = { 348 | isa = XCConfigurationList; 349 | buildConfigurations = ( 350 | CB63E2531CE2309100E22B5C /* Debug */, 351 | CB63E2541CE2309100E22B5C /* Release */, 352 | ); 353 | defaultConfigurationIsVisible = 0; 354 | defaultConfigurationName = Release; 355 | }; 356 | CB63E2551CE2309100E22B5C /* Build configuration list for PBXNativeTarget "Example" */ = { 357 | isa = XCConfigurationList; 358 | buildConfigurations = ( 359 | CB63E2561CE2309100E22B5C /* Debug */, 360 | CB63E2571CE2309100E22B5C /* Release */, 361 | ); 362 | defaultConfigurationIsVisible = 0; 363 | defaultConfigurationName = Release; 364 | }; 365 | /* End XCConfigurationList section */ 366 | }; 367 | rootObject = CB63E23B1CE2309100E22B5C /* Project object */; 368 | } 369 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // iOS Example 4 | // 5 | // Created by Shinichiro Oba on 11/11/15. 6 | // Copyright © 2015 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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 batchElement or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // 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. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is batchElemented instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // BatchElemented 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. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // BatchElemented when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/Example/Assets.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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /Example/Example/Base.lproj/LaunchScreen.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 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Example/Example/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 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 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 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 112 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 202 | 212 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 240 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | -------------------------------------------------------------------------------- /Example/Example/BatchRequestViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BatchRequestViewController.swift 3 | // JSONRPCKit 4 | // 5 | // Created by Shinichiro Oba on 2015/11/11. 6 | // Copyright © 2015年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import JSONRPCKit 11 | import APIKit 12 | 13 | class BatchRequestViewController: UIViewController { 14 | 15 | @IBOutlet weak var firstTextField: UITextField! 16 | @IBOutlet weak var secondTextField: UITextField! 17 | @IBOutlet weak var subtractAnswerLabel: UILabel! 18 | @IBOutlet weak var multiplyAnswerLabel: UILabel! 19 | 20 | let batchFactory = BatchFactory() 21 | 22 | func subtractAndmultiply(_ first: Int, _ second: Int) { 23 | let subtractRequest = Subtract( 24 | minuend: first, 25 | subtrahend: second 26 | ) 27 | 28 | let multiplyRequest = Multiply( 29 | multiplicand: first, 30 | multiplier: second 31 | ) 32 | 33 | let batch = batchFactory.create(subtractRequest, multiplyRequest) 34 | let httpRequest = MathServiceRequest(batch: batch) 35 | 36 | Session.send(httpRequest) { [weak self] result in 37 | switch result { 38 | case .success(let subtractAnswer, let multiplyAnswer): 39 | self?.subtractAnswerLabel.text = "\(subtractAnswer)" 40 | self?.multiplyAnswerLabel.text = "\(multiplyAnswer)" 41 | 42 | case .failure(let error): 43 | self?.subtractAnswerLabel.text = "?" 44 | self?.multiplyAnswerLabel.text = "?" 45 | self?.showAlertWithError(error) 46 | } 47 | } 48 | } 49 | 50 | @IBAction func didPush(_ sender: AnyObject) { 51 | guard let first = Int(firstTextField.text!), let second = Int(secondTextField.text!) else { 52 | subtractAnswerLabel.text = "?" 53 | multiplyAnswerLabel.text = "?" 54 | return 55 | } 56 | 57 | subtractAndmultiply(first, second) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Example/Example/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 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Example/Example/MathService.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MathService.swift 3 | // JSONRPCKit 4 | // 5 | // Created by Shinichiro Oba on 11/11/15. 6 | // Copyright © 2015 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import APIKit 11 | import JSONRPCKit 12 | 13 | // use https://github.com/jenolan/jsonrpcx-php/blob/master/examples/server.php 14 | 15 | struct MathServiceRequest: APIKit.Request { 16 | let batch: Batch 17 | 18 | typealias Response = Batch.Responses 19 | 20 | var baseURL: URL { 21 | return URL(string: "https://jsonrpckit-demo.appspot.com")! 22 | } 23 | 24 | var method: HTTPMethod { 25 | return .post 26 | } 27 | 28 | var path: String { 29 | return "/" 30 | } 31 | 32 | var parameters: Any? { 33 | return batch.requestObject 34 | } 35 | 36 | func response(from object: Any, urlResponse: HTTPURLResponse) throws -> Response { 37 | return try batch.responses(from: object) 38 | } 39 | } 40 | 41 | struct CastError: Error { 42 | let actualValue: Any 43 | let expectedType: ExpectedType.Type 44 | } 45 | 46 | struct Subtract: JSONRPCKit.Request { 47 | typealias Response = Int 48 | 49 | let minuend: Int 50 | let subtrahend: Int 51 | 52 | var method: String { 53 | return "subtract" 54 | } 55 | 56 | var parameters: Any? { 57 | return [minuend, subtrahend] 58 | } 59 | 60 | func response(from resultObject: Any) throws -> Response { 61 | if let response = resultObject as? Response { 62 | return response 63 | } else { 64 | throw CastError(actualValue: resultObject, expectedType: Response.self) 65 | } 66 | } 67 | } 68 | 69 | struct Multiply: JSONRPCKit.Request { 70 | typealias Response = Int 71 | 72 | let multiplicand: Int 73 | let multiplier: Int 74 | 75 | var method: String { 76 | return "multiply" 77 | } 78 | 79 | var parameters: Any? { 80 | return [multiplicand, multiplier] 81 | } 82 | 83 | func response(from resultObject: Any) throws -> Response { 84 | if let response = resultObject as? Response { 85 | return response 86 | } else { 87 | throw CastError(actualValue: resultObject, expectedType: Response.self) 88 | } 89 | } 90 | } 91 | 92 | struct Divide: JSONRPCKit.Request { 93 | typealias Response = Float 94 | 95 | let dividend: Int 96 | let divisor: Int 97 | 98 | var method: String { 99 | return "divide" 100 | } 101 | 102 | var parameters: Any? { 103 | return [dividend, divisor] 104 | } 105 | 106 | func response(from resultObject: Any) throws -> Response { 107 | if let response = resultObject as? Response { 108 | return response 109 | } else { 110 | throw CastError(actualValue: resultObject, expectedType: Response.self) 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Example/Example/SingleRequestViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SingleRequestViewController.swift 3 | // iOS Example 4 | // 5 | // Created by Shinichiro Oba on 11/11/15. 6 | // Copyright © 2015 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import APIKit 11 | import JSONRPCKit 12 | 13 | public struct StringIdGenerator: IdGenerator { 14 | 15 | private var currentId = 1 16 | 17 | public mutating func next() -> Id { 18 | defer { 19 | currentId += 1 20 | } 21 | 22 | return .string("id\(currentId)") 23 | } 24 | } 25 | 26 | class SingleRequestViewController: UIViewController { 27 | 28 | @IBOutlet weak var firstTextField: UITextField! 29 | @IBOutlet weak var secondTextField: UITextField! 30 | @IBOutlet weak var subtractAnswerLabel: UILabel! 31 | 32 | let batchFactory = BatchFactory(idGenerator: StringIdGenerator()) 33 | 34 | func subtract(_ first: Int, _ second: Int) { 35 | let divideRequest = Divide( 36 | dividend: first, 37 | divisor: second 38 | ) 39 | 40 | let batch = batchFactory.create(divideRequest) 41 | let httpRequest = MathServiceRequest(batch: batch) 42 | 43 | Session.send(httpRequest) { [weak self] result in 44 | switch result { 45 | case .success(let answer): 46 | self?.subtractAnswerLabel.text = "\(answer)" 47 | 48 | case .failure(let error): 49 | self?.subtractAnswerLabel.text = "?" 50 | self?.showAlertWithError(error) 51 | } 52 | } 53 | } 54 | 55 | @IBAction func didPush(_ sender: AnyObject) { 56 | guard let first = Int(firstTextField.text!), let second = Int(secondTextField.text!) else { 57 | subtractAnswerLabel.text = "?" 58 | return 59 | } 60 | 61 | subtract(first, second) 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /Example/Example/UIViewController+Error.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+Error.swift 3 | // Example 4 | // 5 | // Created by ishkawa on 2016/07/29. 6 | // Copyright © 2016年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import APIKit 11 | import JSONRPCKit 12 | 13 | extension UIViewController { 14 | 15 | func showAlertWithError(_ error: SessionTaskError) { 16 | let title: String? 17 | let message: String? 18 | 19 | switch error { 20 | case .connectionError(let error as NSError): 21 | title = error.localizedDescription 22 | message = error.localizedRecoverySuggestion 23 | 24 | case .responseError(let error as JSONRPCError): 25 | if case .responseError(_, let errorMessage, let data as String) = error { 26 | title = errorMessage 27 | message = data 28 | } else { 29 | fallthrough 30 | } 31 | 32 | default: 33 | title = "Unknown error" 34 | message = nil 35 | } 36 | 37 | let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) 38 | let alertAction = UIAlertAction(title: "OK", style: .default, handler: nil) 39 | alertController.addAction(alertAction) 40 | present(alertController, animated: true, completion: nil) 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /JSONRPCKit.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "JSONRPCKit" 3 | s.version = "3.0.0" 4 | s.summary = "JSONRPCKit is a JSON-RPC 2.0 library purely written in Swift." 5 | s.homepage = "https://github.com/bricklife/JSONRPCKit" 6 | 7 | s.author = { 8 | "Shinichiro Oba" => "ooba@bricklife.com" 9 | } 10 | 11 | s.ios.deployment_target = "8.0" 12 | s.osx.deployment_target = "10.9" 13 | s.watchos.deployment_target = "2.0" 14 | s.tvos.deployment_target = "9.0" 15 | 16 | s.source_files = "Sources/JSONRPCKit/*.{swift,h,m}" 17 | s.source = { 18 | :git => "https://github.com/bricklife/JSONRPCKit.git", 19 | :tag => "#{s.version}", 20 | } 21 | 22 | s.license = { 23 | :type => "MIT", 24 | :text => <<-LICENSE 25 | Copyright (c) 2015-2016 Shinichiro Oba 26 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 27 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 28 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | LICENSE 30 | } 31 | s.dependency "Result", "~> 3.2.0" 32 | 33 | end 34 | -------------------------------------------------------------------------------- /JSONRPCKit.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7F359B761D4B1A1100032E8D /* BatchElementTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F359B751D4B1A1100032E8D /* BatchElementTests.swift */; }; 11 | 7F359B781D4B1B0500032E8D /* BatchFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F359B771D4B1B0500032E8D /* BatchFactoryTests.swift */; }; 12 | 7FC654F81D48B6CB004C390C /* Batch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC654F61D48B6CB004C390C /* Batch.swift */; }; 13 | 7FC654F91D48B6CB004C390C /* BatchElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC654F71D48B6CB004C390C /* BatchElement.swift */; }; 14 | 7FC654FB1D49DF27004C390C /* BatchFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC654FA1D49DF27004C390C /* BatchFactory.swift */; }; 15 | 7FC6550C1D49FA20004C390C /* TestRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FC6550B1D49FA20004C390C /* TestRequest.swift */; }; 16 | 7FD0A33D1D4B4024007C9EAB /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB31EFB91CF6E8FE00DD13DD /* Result.framework */; }; 17 | CB31EFBA1CF6E8FE00DD13DD /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB31EFB91CF6E8FE00DD13DD /* Result.framework */; }; 18 | CB36EB281BF39028003A4BCA /* Id.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB36EB271BF39028003A4BCA /* Id.swift */; }; 19 | CB82B9E21BF0C5CE00756CB1 /* JSONRPCError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB82B9E11BF0C5CE00756CB1 /* JSONRPCError.swift */; }; 20 | CBB0C3521BF0B1D6006A7D41 /* JSONRPCKit.h in Headers */ = {isa = PBXBuildFile; fileRef = CBB0C3511BF0B1D6006A7D41 /* JSONRPCKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 21 | CBB0C35A1BF0B2D3006A7D41 /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBB0C3591BF0B2D3006A7D41 /* Request.swift */; }; 22 | CBB4161C1BF3599D00B4DB0E /* IdGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBB4161B1BF3599D00B4DB0E /* IdGenerator.swift */; }; 23 | CBB4161E1BF370EA00B4DB0E /* NumberIdGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBB4161D1BF370EA00B4DB0E /* NumberIdGenerator.swift */; }; 24 | /* End PBXBuildFile section */ 25 | 26 | /* Begin PBXContainerItemProxy section */ 27 | 7FC655061D49EA19004C390C /* PBXContainerItemProxy */ = { 28 | isa = PBXContainerItemProxy; 29 | containerPortal = CBB0C3451BF0B1D6006A7D41 /* Project object */; 30 | proxyType = 1; 31 | remoteGlobalIDString = CBB0C34D1BF0B1D6006A7D41; 32 | remoteInfo = "JSONRPCKit-iOS"; 33 | }; 34 | /* End PBXContainerItemProxy section */ 35 | 36 | /* Begin PBXFileReference section */ 37 | 7F359B751D4B1A1100032E8D /* BatchElementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchElementTests.swift; sourceTree = ""; }; 38 | 7F359B771D4B1B0500032E8D /* BatchFactoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchFactoryTests.swift; sourceTree = ""; }; 39 | 7FC654F61D48B6CB004C390C /* Batch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Batch.swift; sourceTree = ""; }; 40 | 7FC654F71D48B6CB004C390C /* BatchElement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchElement.swift; sourceTree = ""; }; 41 | 7FC654FA1D49DF27004C390C /* BatchFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchFactory.swift; sourceTree = ""; }; 42 | 7FC655001D49EA19004C390C /* JSONRPCKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JSONRPCKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 7FC655041D49EA19004C390C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | 7FC6550B1D49FA20004C390C /* TestRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestRequest.swift; sourceTree = ""; }; 45 | CB31EFB91CF6E8FE00DD13DD /* Result.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Result.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | CB36EB271BF39028003A4BCA /* Id.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Id.swift; sourceTree = ""; }; 47 | CB82B9E11BF0C5CE00756CB1 /* JSONRPCError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONRPCError.swift; sourceTree = ""; }; 48 | CBB0C34E1BF0B1D6006A7D41 /* JSONRPCKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JSONRPCKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | CBB0C3511BF0B1D6006A7D41 /* JSONRPCKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSONRPCKit.h; sourceTree = ""; }; 50 | CBB0C3531BF0B1D7006A7D41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | CBB0C3591BF0B2D3006A7D41 /* Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = ""; }; 52 | CBB4161B1BF3599D00B4DB0E /* IdGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdGenerator.swift; sourceTree = ""; }; 53 | CBB4161D1BF370EA00B4DB0E /* NumberIdGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberIdGenerator.swift; sourceTree = ""; }; 54 | /* End PBXFileReference section */ 55 | 56 | /* Begin PBXFrameworksBuildPhase section */ 57 | 7FC654FD1D49EA19004C390C /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | 7FD0A33D1D4B4024007C9EAB /* Result.framework in Frameworks */, 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | CBB0C34A1BF0B1D6006A7D41 /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | CB31EFBA1CF6E8FE00DD13DD /* Result.framework in Frameworks */, 70 | ); 71 | runOnlyForDeploymentPostprocessing = 0; 72 | }; 73 | /* End PBXFrameworksBuildPhase section */ 74 | 75 | /* Begin PBXGroup section */ 76 | 7FC655011D49EA19004C390C /* JSONRPCKitTests */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | 7FC6550B1D49FA20004C390C /* TestRequest.swift */, 80 | 7F359B751D4B1A1100032E8D /* BatchElementTests.swift */, 81 | 7F359B771D4B1B0500032E8D /* BatchFactoryTests.swift */, 82 | 7FC655041D49EA19004C390C /* Info.plist */, 83 | ); 84 | path = JSONRPCKitTests; 85 | sourceTree = ""; 86 | }; 87 | CB63E2391CE22F7E00E22B5C /* Frameworks */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | CB31EFB91CF6E8FE00DD13DD /* Result.framework */, 91 | ); 92 | name = Frameworks; 93 | sourceTree = ""; 94 | }; 95 | CB7B4D4F2010BB1800AEB6FF /* Sources */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | CBB0C3501BF0B1D6006A7D41 /* JSONRPCKit */, 99 | ); 100 | path = Sources; 101 | sourceTree = ""; 102 | }; 103 | CB7B4D502010BB4400AEB6FF /* Tests */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | 7FC655011D49EA19004C390C /* JSONRPCKitTests */, 107 | ); 108 | path = Tests; 109 | sourceTree = ""; 110 | }; 111 | CBB0C3441BF0B1D5006A7D41 = { 112 | isa = PBXGroup; 113 | children = ( 114 | CB7B4D4F2010BB1800AEB6FF /* Sources */, 115 | CB7B4D502010BB4400AEB6FF /* Tests */, 116 | CBB0C34F1BF0B1D6006A7D41 /* Products */, 117 | CB63E2391CE22F7E00E22B5C /* Frameworks */, 118 | ); 119 | sourceTree = ""; 120 | }; 121 | CBB0C34F1BF0B1D6006A7D41 /* Products */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | CBB0C34E1BF0B1D6006A7D41 /* JSONRPCKit.framework */, 125 | 7FC655001D49EA19004C390C /* JSONRPCKitTests.xctest */, 126 | ); 127 | name = Products; 128 | sourceTree = ""; 129 | }; 130 | CBB0C3501BF0B1D6006A7D41 /* JSONRPCKit */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | CBB0C3511BF0B1D6006A7D41 /* JSONRPCKit.h */, 134 | CBB0C3591BF0B2D3006A7D41 /* Request.swift */, 135 | 7FC654F61D48B6CB004C390C /* Batch.swift */, 136 | 7FC654F71D48B6CB004C390C /* BatchElement.swift */, 137 | 7FC654FA1D49DF27004C390C /* BatchFactory.swift */, 138 | CB82B9E11BF0C5CE00756CB1 /* JSONRPCError.swift */, 139 | CB36EB271BF39028003A4BCA /* Id.swift */, 140 | CBB4161B1BF3599D00B4DB0E /* IdGenerator.swift */, 141 | CBB4161D1BF370EA00B4DB0E /* NumberIdGenerator.swift */, 142 | CBB0C3531BF0B1D7006A7D41 /* Info.plist */, 143 | ); 144 | path = JSONRPCKit; 145 | sourceTree = ""; 146 | }; 147 | /* End PBXGroup section */ 148 | 149 | /* Begin PBXHeadersBuildPhase section */ 150 | CBB0C34B1BF0B1D6006A7D41 /* Headers */ = { 151 | isa = PBXHeadersBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | CBB0C3521BF0B1D6006A7D41 /* JSONRPCKit.h in Headers */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXHeadersBuildPhase section */ 159 | 160 | /* Begin PBXNativeTarget section */ 161 | 7FC654FF1D49EA19004C390C /* JSONRPCKitTests */ = { 162 | isa = PBXNativeTarget; 163 | buildConfigurationList = 7FC655081D49EA19004C390C /* Build configuration list for PBXNativeTarget "JSONRPCKitTests" */; 164 | buildPhases = ( 165 | 7FC654FC1D49EA19004C390C /* Sources */, 166 | 7FC654FD1D49EA19004C390C /* Frameworks */, 167 | 7FC654FE1D49EA19004C390C /* Resources */, 168 | ); 169 | buildRules = ( 170 | ); 171 | dependencies = ( 172 | 7FC655071D49EA19004C390C /* PBXTargetDependency */, 173 | ); 174 | name = JSONRPCKitTests; 175 | productName = Tests; 176 | productReference = 7FC655001D49EA19004C390C /* JSONRPCKitTests.xctest */; 177 | productType = "com.apple.product-type.bundle.unit-test"; 178 | }; 179 | CBB0C34D1BF0B1D6006A7D41 /* JSONRPCKit */ = { 180 | isa = PBXNativeTarget; 181 | buildConfigurationList = CBB0C3561BF0B1D7006A7D41 /* Build configuration list for PBXNativeTarget "JSONRPCKit" */; 182 | buildPhases = ( 183 | CBB0C3491BF0B1D6006A7D41 /* Sources */, 184 | CBB0C34A1BF0B1D6006A7D41 /* Frameworks */, 185 | CBB0C34B1BF0B1D6006A7D41 /* Headers */, 186 | CBB0C34C1BF0B1D6006A7D41 /* Resources */, 187 | ); 188 | buildRules = ( 189 | ); 190 | dependencies = ( 191 | ); 192 | name = JSONRPCKit; 193 | productName = JSONRPCKit; 194 | productReference = CBB0C34E1BF0B1D6006A7D41 /* JSONRPCKit.framework */; 195 | productType = "com.apple.product-type.framework"; 196 | }; 197 | /* End PBXNativeTarget section */ 198 | 199 | /* Begin PBXProject section */ 200 | CBB0C3451BF0B1D6006A7D41 /* Project object */ = { 201 | isa = PBXProject; 202 | attributes = { 203 | LastSwiftUpdateCheck = 0730; 204 | LastUpgradeCheck = 0920; 205 | ORGANIZATIONNAME = "Shinichiro Oba"; 206 | TargetAttributes = { 207 | 7FC654FF1D49EA19004C390C = { 208 | CreatedOnToolsVersion = 7.3.1; 209 | LastSwiftMigration = 0920; 210 | }; 211 | CBB0C34D1BF0B1D6006A7D41 = { 212 | CreatedOnToolsVersion = 7.1; 213 | LastSwiftMigration = 0920; 214 | }; 215 | }; 216 | }; 217 | buildConfigurationList = CBB0C3481BF0B1D6006A7D41 /* Build configuration list for PBXProject "JSONRPCKit" */; 218 | compatibilityVersion = "Xcode 3.2"; 219 | developmentRegion = English; 220 | hasScannedForEncodings = 0; 221 | knownRegions = ( 222 | en, 223 | Base, 224 | ); 225 | mainGroup = CBB0C3441BF0B1D5006A7D41; 226 | productRefGroup = CBB0C34F1BF0B1D6006A7D41 /* Products */; 227 | projectDirPath = ""; 228 | projectRoot = ""; 229 | targets = ( 230 | CBB0C34D1BF0B1D6006A7D41 /* JSONRPCKit */, 231 | 7FC654FF1D49EA19004C390C /* JSONRPCKitTests */, 232 | ); 233 | }; 234 | /* End PBXProject section */ 235 | 236 | /* Begin PBXResourcesBuildPhase section */ 237 | 7FC654FE1D49EA19004C390C /* Resources */ = { 238 | isa = PBXResourcesBuildPhase; 239 | buildActionMask = 2147483647; 240 | files = ( 241 | ); 242 | runOnlyForDeploymentPostprocessing = 0; 243 | }; 244 | CBB0C34C1BF0B1D6006A7D41 /* Resources */ = { 245 | isa = PBXResourcesBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | ); 249 | runOnlyForDeploymentPostprocessing = 0; 250 | }; 251 | /* End PBXResourcesBuildPhase section */ 252 | 253 | /* Begin PBXSourcesBuildPhase section */ 254 | 7FC654FC1D49EA19004C390C /* Sources */ = { 255 | isa = PBXSourcesBuildPhase; 256 | buildActionMask = 2147483647; 257 | files = ( 258 | 7F359B781D4B1B0500032E8D /* BatchFactoryTests.swift in Sources */, 259 | 7F359B761D4B1A1100032E8D /* BatchElementTests.swift in Sources */, 260 | 7FC6550C1D49FA20004C390C /* TestRequest.swift in Sources */, 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | CBB0C3491BF0B1D6006A7D41 /* Sources */ = { 265 | isa = PBXSourcesBuildPhase; 266 | buildActionMask = 2147483647; 267 | files = ( 268 | CB82B9E21BF0C5CE00756CB1 /* JSONRPCError.swift in Sources */, 269 | 7FC654FB1D49DF27004C390C /* BatchFactory.swift in Sources */, 270 | CBB4161E1BF370EA00B4DB0E /* NumberIdGenerator.swift in Sources */, 271 | CB36EB281BF39028003A4BCA /* Id.swift in Sources */, 272 | CBB4161C1BF3599D00B4DB0E /* IdGenerator.swift in Sources */, 273 | 7FC654F91D48B6CB004C390C /* BatchElement.swift in Sources */, 274 | CBB0C35A1BF0B2D3006A7D41 /* Request.swift in Sources */, 275 | 7FC654F81D48B6CB004C390C /* Batch.swift in Sources */, 276 | ); 277 | runOnlyForDeploymentPostprocessing = 0; 278 | }; 279 | /* End PBXSourcesBuildPhase section */ 280 | 281 | /* Begin PBXTargetDependency section */ 282 | 7FC655071D49EA19004C390C /* PBXTargetDependency */ = { 283 | isa = PBXTargetDependency; 284 | target = CBB0C34D1BF0B1D6006A7D41 /* JSONRPCKit */; 285 | targetProxy = 7FC655061D49EA19004C390C /* PBXContainerItemProxy */; 286 | }; 287 | /* End PBXTargetDependency section */ 288 | 289 | /* Begin XCBuildConfiguration section */ 290 | 7FC655091D49EA19004C390C /* Debug */ = { 291 | isa = XCBuildConfiguration; 292 | buildSettings = { 293 | CLANG_ANALYZER_NONNULL = YES; 294 | INFOPLIST_FILE = Tests/JSONRPCKitTests/Info.plist; 295 | LD_RUNPATH_SEARCH_PATHS = ""; 296 | "LD_RUNPATH_SEARCH_PATHS[sdk=appletv*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 297 | "LD_RUNPATH_SEARCH_PATHS[sdk=iphone*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 298 | "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 299 | PRODUCT_BUNDLE_IDENTIFIER = "-.Tests"; 300 | PRODUCT_NAME = "$(TARGET_NAME)"; 301 | SWIFT_VERSION = 4.0; 302 | }; 303 | name = Debug; 304 | }; 305 | 7FC6550A1D49EA19004C390C /* Release */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | CLANG_ANALYZER_NONNULL = YES; 309 | INFOPLIST_FILE = Tests/JSONRPCKitTests/Info.plist; 310 | "LD_RUNPATH_SEARCH_PATHS[sdk=appletv*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 311 | "LD_RUNPATH_SEARCH_PATHS[sdk=iphone*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 312 | "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 313 | PRODUCT_BUNDLE_IDENTIFIER = "-.Tests"; 314 | PRODUCT_NAME = "$(TARGET_NAME)"; 315 | SWIFT_VERSION = 4.0; 316 | }; 317 | name = Release; 318 | }; 319 | CBB0C3541BF0B1D7006A7D41 /* Debug */ = { 320 | isa = XCBuildConfiguration; 321 | buildSettings = { 322 | ALWAYS_SEARCH_USER_PATHS = NO; 323 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 324 | CLANG_CXX_LIBRARY = "libc++"; 325 | CLANG_ENABLE_MODULES = YES; 326 | CLANG_ENABLE_OBJC_ARC = YES; 327 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 328 | CLANG_WARN_BOOL_CONVERSION = YES; 329 | CLANG_WARN_COMMA = YES; 330 | CLANG_WARN_CONSTANT_CONVERSION = YES; 331 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 332 | CLANG_WARN_EMPTY_BODY = YES; 333 | CLANG_WARN_ENUM_CONVERSION = YES; 334 | CLANG_WARN_INFINITE_RECURSION = YES; 335 | CLANG_WARN_INT_CONVERSION = YES; 336 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 337 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 338 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 339 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 340 | CLANG_WARN_STRICT_PROTOTYPES = YES; 341 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 342 | CLANG_WARN_UNREACHABLE_CODE = YES; 343 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 344 | COPY_PHASE_STRIP = NO; 345 | CURRENT_PROJECT_VERSION = 1; 346 | DEBUG_INFORMATION_FORMAT = dwarf; 347 | ENABLE_STRICT_OBJC_MSGSEND = YES; 348 | ENABLE_TESTABILITY = YES; 349 | GCC_C_LANGUAGE_STANDARD = gnu99; 350 | GCC_DYNAMIC_NO_PIC = NO; 351 | GCC_NO_COMMON_BLOCKS = YES; 352 | GCC_OPTIMIZATION_LEVEL = 0; 353 | GCC_PREPROCESSOR_DEFINITIONS = ( 354 | "DEBUG=1", 355 | "$(inherited)", 356 | ); 357 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 358 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 359 | GCC_WARN_UNDECLARED_SELECTOR = YES; 360 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 361 | GCC_WARN_UNUSED_FUNCTION = YES; 362 | GCC_WARN_UNUSED_VARIABLE = YES; 363 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 364 | MACOSX_DEPLOYMENT_TARGET = 10.9; 365 | MTL_ENABLE_DEBUG_INFO = YES; 366 | ONLY_ACTIVE_ARCH = YES; 367 | SDKROOT = macosx; 368 | SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; 369 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 370 | TVOS_DEPLOYMENT_TARGET = 9.0; 371 | VERSIONING_SYSTEM = "apple-generic"; 372 | VERSION_INFO_PREFIX = ""; 373 | WATCHOS_DEPLOYMENT_TARGET = 2.0; 374 | }; 375 | name = Debug; 376 | }; 377 | CBB0C3551BF0B1D7006A7D41 /* Release */ = { 378 | isa = XCBuildConfiguration; 379 | buildSettings = { 380 | ALWAYS_SEARCH_USER_PATHS = NO; 381 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 382 | CLANG_CXX_LIBRARY = "libc++"; 383 | CLANG_ENABLE_MODULES = YES; 384 | CLANG_ENABLE_OBJC_ARC = YES; 385 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 386 | CLANG_WARN_BOOL_CONVERSION = YES; 387 | CLANG_WARN_COMMA = YES; 388 | CLANG_WARN_CONSTANT_CONVERSION = YES; 389 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 390 | CLANG_WARN_EMPTY_BODY = YES; 391 | CLANG_WARN_ENUM_CONVERSION = YES; 392 | CLANG_WARN_INFINITE_RECURSION = YES; 393 | CLANG_WARN_INT_CONVERSION = YES; 394 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 395 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 396 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 397 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 398 | CLANG_WARN_STRICT_PROTOTYPES = YES; 399 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 400 | CLANG_WARN_UNREACHABLE_CODE = YES; 401 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 402 | COPY_PHASE_STRIP = NO; 403 | CURRENT_PROJECT_VERSION = 1; 404 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 405 | ENABLE_NS_ASSERTIONS = NO; 406 | ENABLE_STRICT_OBJC_MSGSEND = YES; 407 | GCC_C_LANGUAGE_STANDARD = gnu99; 408 | GCC_NO_COMMON_BLOCKS = YES; 409 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 410 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 411 | GCC_WARN_UNDECLARED_SELECTOR = YES; 412 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 413 | GCC_WARN_UNUSED_FUNCTION = YES; 414 | GCC_WARN_UNUSED_VARIABLE = YES; 415 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 416 | MACOSX_DEPLOYMENT_TARGET = 10.9; 417 | MTL_ENABLE_DEBUG_INFO = NO; 418 | SDKROOT = macosx; 419 | SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; 420 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 421 | TVOS_DEPLOYMENT_TARGET = 9.0; 422 | VALIDATE_PRODUCT = YES; 423 | VERSIONING_SYSTEM = "apple-generic"; 424 | VERSION_INFO_PREFIX = ""; 425 | WATCHOS_DEPLOYMENT_TARGET = 2.0; 426 | }; 427 | name = Release; 428 | }; 429 | CBB0C3571BF0B1D7006A7D41 /* Debug */ = { 430 | isa = XCBuildConfiguration; 431 | buildSettings = { 432 | CLANG_ENABLE_MODULES = YES; 433 | DEFINES_MODULE = YES; 434 | DYLIB_COMPATIBILITY_VERSION = 1; 435 | DYLIB_CURRENT_VERSION = 1; 436 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 437 | INFOPLIST_FILE = Sources/JSONRPCKit/Info.plist; 438 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 439 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 440 | "LD_RUNPATH_SEARCH_PATHS[sdk=appletv*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 441 | "LD_RUNPATH_SEARCH_PATHS[sdk=iphone*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 442 | "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 443 | "LD_RUNPATH_SEARCH_PATHS[sdk=watch*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 444 | PRODUCT_BUNDLE_IDENTIFIER = com.bricklife.JSONRPCKit; 445 | PRODUCT_NAME = "$(PROJECT_NAME)"; 446 | SKIP_INSTALL = YES; 447 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 448 | SWIFT_VERSION = 4.0; 449 | }; 450 | name = Debug; 451 | }; 452 | CBB0C3581BF0B1D7006A7D41 /* Release */ = { 453 | isa = XCBuildConfiguration; 454 | buildSettings = { 455 | CLANG_ENABLE_MODULES = YES; 456 | DEFINES_MODULE = YES; 457 | DYLIB_COMPATIBILITY_VERSION = 1; 458 | DYLIB_CURRENT_VERSION = 1; 459 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 460 | INFOPLIST_FILE = Sources/JSONRPCKit/Info.plist; 461 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 462 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 463 | "LD_RUNPATH_SEARCH_PATHS[sdk=appletv*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 464 | "LD_RUNPATH_SEARCH_PATHS[sdk=iphone*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 465 | "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 466 | "LD_RUNPATH_SEARCH_PATHS[sdk=watch*]" = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 467 | PRODUCT_BUNDLE_IDENTIFIER = com.bricklife.JSONRPCKit; 468 | PRODUCT_NAME = "$(PROJECT_NAME)"; 469 | SKIP_INSTALL = YES; 470 | SWIFT_VERSION = 4.0; 471 | }; 472 | name = Release; 473 | }; 474 | /* End XCBuildConfiguration section */ 475 | 476 | /* Begin XCConfigurationList section */ 477 | 7FC655081D49EA19004C390C /* Build configuration list for PBXNativeTarget "JSONRPCKitTests" */ = { 478 | isa = XCConfigurationList; 479 | buildConfigurations = ( 480 | 7FC655091D49EA19004C390C /* Debug */, 481 | 7FC6550A1D49EA19004C390C /* Release */, 482 | ); 483 | defaultConfigurationIsVisible = 0; 484 | defaultConfigurationName = Release; 485 | }; 486 | CBB0C3481BF0B1D6006A7D41 /* Build configuration list for PBXProject "JSONRPCKit" */ = { 487 | isa = XCConfigurationList; 488 | buildConfigurations = ( 489 | CBB0C3541BF0B1D7006A7D41 /* Debug */, 490 | CBB0C3551BF0B1D7006A7D41 /* Release */, 491 | ); 492 | defaultConfigurationIsVisible = 0; 493 | defaultConfigurationName = Release; 494 | }; 495 | CBB0C3561BF0B1D7006A7D41 /* Build configuration list for PBXNativeTarget "JSONRPCKit" */ = { 496 | isa = XCConfigurationList; 497 | buildConfigurations = ( 498 | CBB0C3571BF0B1D7006A7D41 /* Debug */, 499 | CBB0C3581BF0B1D7006A7D41 /* Release */, 500 | ); 501 | defaultConfigurationIsVisible = 0; 502 | defaultConfigurationName = Release; 503 | }; 504 | /* End XCConfigurationList section */ 505 | }; 506 | rootObject = CBB0C3451BF0B1D6006A7D41 /* Project object */; 507 | } 508 | -------------------------------------------------------------------------------- /JSONRPCKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JSONRPCKit.xcodeproj/xcshareddata/xcschemes/JSONRPCKit.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 34 | 40 | 41 | 42 | 43 | 44 | 50 | 51 | 52 | 53 | 54 | 55 | 66 | 67 | 73 | 74 | 75 | 76 | 77 | 78 | 84 | 85 | 91 | 92 | 93 | 94 | 96 | 97 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /JSONRPCKit.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /JSONRPCKit.xcworkspace/xcshareddata/JSONRPCKit.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "AD7BAB873C97DE45820C77B7C507D01D37AE8FCE", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "67620B5EFA902936DF04070AF595B76AB0333747" : 0, 8 | "956D2B21DD155C49504BB67697A67F7C5351A353" : 0, 9 | "F607A624BDF2624F7609EF66C123E17132AFE18F" : 0, 10 | "AD7BAB873C97DE45820C77B7C507D01D37AE8FCE" : 0 11 | }, 12 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "B7070147-19AF-425E-BE57-543D984E1DB3", 13 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 14 | "67620B5EFA902936DF04070AF595B76AB0333747" : "JSONRPCKit\/Carthage\/Checkouts\/Alamofire\/", 15 | "956D2B21DD155C49504BB67697A67F7C5351A353" : "JSONRPCKit\/Carthage\/Checkouts\/Result\/", 16 | "F607A624BDF2624F7609EF66C123E17132AFE18F" : "JSONRPCKit\/Carthage\/Checkouts\/APIKit\/", 17 | "AD7BAB873C97DE45820C77B7C507D01D37AE8FCE" : "JSONRPCKit\/" 18 | }, 19 | "DVTSourceControlWorkspaceBlueprintNameKey" : "JSONRPCKit", 20 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 21 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "JSONRPCKit.xcworkspace", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 23 | { 24 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/Alamofire\/Alamofire.git", 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "67620B5EFA902936DF04070AF595B76AB0333747" 27 | }, 28 | { 29 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/antitypical\/Result.git", 30 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 31 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "956D2B21DD155C49504BB67697A67F7C5351A353" 32 | }, 33 | { 34 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/bricklife\/JSONRPCKit.git", 35 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 36 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "AD7BAB873C97DE45820C77B7C507D01D37AE8FCE" 37 | }, 38 | { 39 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:ishkawa\/APIKit.git", 40 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 41 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "F607A624BDF2624F7609EF66C123E17132AFE18F" 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2016 Shinichiro Oba 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "Result", 6 | "repositoryURL": "https://github.com/antitypical/Result.git", 7 | "state": { 8 | "branch": null, 9 | "revision": "7477584259bfce2560a19e06ad9f71db441fff11", 10 | "version": "3.2.4" 11 | } 12 | } 13 | ] 14 | }, 15 | "version": 1 16 | } 17 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.0 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "JSONRPCKit", 8 | products: [ 9 | .library(name: "JSONRPCKit", targets: ["JSONRPCKit"]), 10 | ], 11 | dependencies: [ 12 | .package(url: "https://github.com/antitypical/Result.git", from: "3.2.0"), 13 | ], 14 | targets: [ 15 | .target(name: "JSONRPCKit", dependencies: ["Result"]), 16 | .testTarget(name: "JSONRPCKitTests", dependencies: ["JSONRPCKit"]), 17 | ], 18 | swiftLanguageVersions: [4] 19 | ) 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JSONRPCKit 2 | 3 | [![Build Status](https://travis-ci.org/bricklife/JSONRPCKit.svg?branch=master)](https://travis-ci.org/bricklife/JSONRPCKit) 4 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 5 | [![CocoaPods](https://img.shields.io/cocoapods/v/JSONRPCKit.svg)](https://cocoapods.org/) 6 | 7 | JSONRPCKit is a type-safe [JSON-RPC 2.0](http://www.jsonrpc.org/specification) library purely written in Swift. 8 | 9 | ```swift 10 | // Generating request JSON 11 | let batchFactory = BatchFactory(version: "2.0", idGenerator: NumberIdGenerator()) 12 | let request = Subtract(minuend: 42, subtrahend: 23) 13 | let batch = batchFactory.create(request) 14 | batch.requestObject // ["jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1] 15 | 16 | // Parsing response JSON 17 | let responseObject: Any = ["jsonrpc": "2.0", "result": 19, "id": 1] 18 | let response = try! batch.responses(from: responseObject) 19 | response // 19 (type of response is inferred from SubtractRequest.Response) 20 | ``` 21 | 22 | ## Requirements 23 | 24 | - Swift 4.0 / Xcode 9.0 or later 25 | - If you use Swift 3.1 (Xcode 8.3), you can use [2.0.3](https://github.com/bricklife/JSONRPCKit/tree/2.0.3) instead. 26 | - iOS 8.0 or later 27 | - macOS 10.9 or later 28 | - watchOS 2.0 or later 29 | - tvOS 9.0 or later 30 | - [Linux](https://swift.org/download/#linux) is also supported 31 | 32 | ## Basic usage 33 | 34 | 1. Define request type 35 | 2. Generate request JSON 36 | 3. Parse response JSON 37 | 38 | ### Defining request type 39 | 40 | First of all, define a request type that conforms to `Request`. 41 | 42 | ```swift 43 | struct Subtract: JSONRPCKit.Request { 44 | typealias Response = Int 45 | 46 | let minuend: Int 47 | let subtrahend: Int 48 | 49 | var method: String { 50 | return "subtract" 51 | } 52 | 53 | var parameters: Any? { 54 | return [minuend, subtrahend] 55 | } 56 | 57 | func response(from resultObject: Any) throws -> Response { 58 | if let response = resultObject as? Response { 59 | return response 60 | } else { 61 | throw CastError(actualValue: resultObject, expectedType: Response.self) 62 | } 63 | } 64 | } 65 | ``` 66 | 67 | 68 | ### Generating request JSON 69 | 70 | To generate request JSON, pass `Request` instances to `BatchFactory` instance, which has common JSON-RPC version and identifier generator. 71 | When `BatchFactory` instance receives request(s), it generates identifier(s) for the request(s) and request JSON by combining id, version, method and parameters. 72 | 73 | ```swift 74 | let batchFactory = BatchFactory(version: "2.0", idGenerator: NumberIdGenerator()) 75 | let request1 = Subtract(minuend: 42, subtrahend: 23) 76 | let request2 = Subtract(minuend: 23, subtrahend: 42) 77 | let batch = batchFactory.create(request1, request2) 78 | ``` 79 | 80 | The request JSON is available in `batch.requestObject`. It looks like below: 81 | 82 | ```json 83 | [ 84 | { 85 | "method" : "subtract", 86 | "jsonrpc" : "2.0", 87 | "id" : 1, 88 | "params" : [ 89 | 42, 90 | 23 91 | ] 92 | }, 93 | { 94 | "method" : "subtract", 95 | "jsonrpc" : "2.0", 96 | "id" : 2, 97 | "params" : [ 98 | 23, 99 | 42 100 | ] 101 | } 102 | ] 103 | ``` 104 | 105 | 106 | ### Parsing response JSON 107 | 108 | Suppose that following JSON is returned from server: 109 | 110 | ```json 111 | [ 112 | { 113 | "result" : 19, 114 | "jsonrpc" : "2.0", 115 | "id" : 1, 116 | "status" : 0 117 | }, 118 | { 119 | "result" : -19, 120 | "jsonrpc" : "2.0", 121 | "id" : 2, 122 | "status" : 0 123 | } 124 | ] 125 | ``` 126 | 127 | To parse response object, execute `responses(from:)` of `Batch` instance. 128 | When `responses(from:)` is called, `Batch` finds corresponding response object by comparing request id and response id. 129 | After it find the response object, it executes `responses(from:)` of `Response` to get `Request.Response` from the response object. 130 | 131 | ```swift 132 | let responseObject = ... 133 | let (response1, response2) = try! batch.responses(from: responseObject) 134 | print(response1) // 19 135 | print(response2) // -19 136 | ``` 137 | 138 | ## JSON-RPC over HTTP by [APIKit](https://github.com/ishkawa/APIKit) 139 | 140 | APIKit is a type-safe networking abstraction layer. 141 | 142 | ### Defining HTTP request type 143 | 144 | APIKit also has `RequestType` that represents HTTP request. 145 | 146 | ```swift 147 | import APIKit 148 | 149 | struct MyServiceRequest: APIKit.Request { 150 | let batch: Batch 151 | 152 | typealias Response = Batch.Responses 153 | 154 | var baseURL: URL { 155 | return URL(string: "https://api.example.com/")! 156 | } 157 | 158 | var method: HTTPMethod { 159 | return .post 160 | } 161 | 162 | var path: String { 163 | return "/" 164 | } 165 | 166 | var parameters: Any? { 167 | return batch.requestObject 168 | } 169 | 170 | func response(from object: Any, urlResponse: HTTPURLResponse) throws -> Response { 171 | return try batch.responses(from: object) 172 | } 173 | } 174 | ``` 175 | 176 | ### Sending HTTP/HTTPS request 177 | 178 | ```swift 179 | let batchFactory = BatchFactory(version: "2.0", idGenerator: NumberIdGenerator()) 180 | let request1 = Subtract(minuend: 42, subtrahend: 23) 181 | let request2 = Subtract(minuend: 23, subtrahend: 42) 182 | let batch = batchFactory.create(request1, request2) 183 | let httpRequest = MyServiceRequest(batch: batch) 184 | 185 | Session.sendRequest(httpRequest) { result in 186 | switch result { 187 | case .Success(let response1, let response2): 188 | print(response1.count) // CountCharactersResponse 189 | print(response2.count) // CountCharactersResponse 190 | 191 | case .Failure(let error): 192 | print(error) 193 | } 194 | } 195 | ``` 196 | 197 | ## License 198 | 199 | JSONRPCKit is released under the [MIT License](LICENSE.md). 200 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/Batch.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Batch.swift 3 | // JSONRPCKit 4 | // 5 | // Created by ishkawa on 2016/07/27. 6 | // Copyright © 2016年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Result 11 | 12 | public protocol Batch { 13 | associatedtype Responses 14 | associatedtype Results 15 | 16 | var requestObject: Any { get } 17 | 18 | func responses(from object: Any) throws -> Responses 19 | func results(from object: Any) -> Results 20 | 21 | static func responses(from results: Results) throws -> Responses 22 | } 23 | 24 | public struct Batch1: Batch { 25 | public typealias Responses = Request.Response 26 | public typealias Results = Result 27 | 28 | public let batchElement: BatchElement 29 | 30 | public var requestObject: Any { 31 | return batchElement.body 32 | } 33 | 34 | public func responses(from object: Any) throws -> Responses { 35 | return try batchElement.response(from: object) 36 | } 37 | 38 | public func results(from object: Any) -> Results { 39 | return batchElement.result(from: object) 40 | } 41 | 42 | public static func responses(from results: Results) throws -> Responses { 43 | return try results.dematerialize() 44 | } 45 | } 46 | 47 | public struct Batch2: Batch { 48 | public typealias Responses = (Request1.Response, Request2.Response) 49 | public typealias Results = (Result, Result) 50 | 51 | public let batchElement1: BatchElement 52 | public let batchElement2: BatchElement 53 | 54 | public var requestObject: Any { 55 | return [ 56 | batchElement1.body, 57 | batchElement2.body, 58 | ] 59 | } 60 | 61 | public func responses(from object: Any) throws -> Responses { 62 | guard let batchObjects = object as? [Any] else { 63 | throw JSONRPCError.nonArrayResponse(object) 64 | } 65 | 66 | return ( 67 | try batchElement1.response(from: batchObjects), 68 | try batchElement2.response(from: batchObjects) 69 | ) 70 | } 71 | 72 | public func results(from object: Any) -> Results { 73 | guard let batchObjects = object as? [Any] else { 74 | return ( 75 | .failure(.nonArrayResponse(object)), 76 | .failure(.nonArrayResponse(object)) 77 | ) 78 | } 79 | 80 | return ( 81 | batchElement1.result(from: batchObjects), 82 | batchElement2.result(from: batchObjects) 83 | ) 84 | } 85 | 86 | public static func responses(from results: Results) throws -> Responses { 87 | return ( 88 | try results.0.dematerialize(), 89 | try results.1.dematerialize() 90 | ) 91 | } 92 | } 93 | 94 | public struct Batch3: Batch { 95 | public typealias Responses = (Request1.Response, Request2.Response, Request3.Response) 96 | public typealias Results = (Result, Result, Result) 97 | 98 | public let batchElement1: BatchElement 99 | public let batchElement2: BatchElement 100 | public let batchElement3: BatchElement 101 | 102 | public var requestObject: Any { 103 | return [ 104 | batchElement1.body, 105 | batchElement2.body, 106 | batchElement3.body, 107 | ] 108 | } 109 | 110 | public func responses(from object: Any) throws -> Responses { 111 | guard let batchObjects = object as? [Any] else { 112 | throw JSONRPCError.nonArrayResponse(object) 113 | } 114 | 115 | return ( 116 | try batchElement1.response(from: batchObjects), 117 | try batchElement2.response(from: batchObjects), 118 | try batchElement3.response(from: batchObjects) 119 | ) 120 | } 121 | 122 | public func results(from object: Any) -> Results { 123 | guard let batchObjects = object as? [Any] else { 124 | return ( 125 | .failure(.nonArrayResponse(object)), 126 | .failure(.nonArrayResponse(object)), 127 | .failure(.nonArrayResponse(object)) 128 | ) 129 | } 130 | 131 | return ( 132 | batchElement1.result(from: batchObjects), 133 | batchElement2.result(from: batchObjects), 134 | batchElement3.result(from: batchObjects) 135 | ) 136 | } 137 | 138 | public static func responses(from results: Results) throws -> Responses { 139 | return ( 140 | try results.0.dematerialize(), 141 | try results.1.dematerialize(), 142 | try results.2.dematerialize() 143 | ) 144 | } 145 | } 146 | 147 | public struct Batch4: Batch { 148 | public typealias Responses = (Request1.Response, Request2.Response, Request3.Response, Request4.Response) 149 | public typealias Results = (Result, Result, Result, Result) 150 | 151 | public let batchElement1: BatchElement 152 | public let batchElement2: BatchElement 153 | public let batchElement3: BatchElement 154 | public let batchElement4: BatchElement 155 | 156 | public var requestObject: Any { 157 | return [ 158 | batchElement1.body, 159 | batchElement2.body, 160 | batchElement3.body, 161 | batchElement4.body, 162 | ] 163 | } 164 | 165 | public func responses(from object: Any) throws -> Responses { 166 | guard let batchObjects = object as? [Any] else { 167 | throw JSONRPCError.nonArrayResponse(object) 168 | } 169 | 170 | return ( 171 | try batchElement1.response(from: batchObjects), 172 | try batchElement2.response(from: batchObjects), 173 | try batchElement3.response(from: batchObjects), 174 | try batchElement4.response(from: batchObjects) 175 | ) 176 | } 177 | 178 | public func results(from object: Any) -> Results { 179 | guard let batchObjects = object as? [Any] else { 180 | return ( 181 | .failure(.nonArrayResponse(object)), 182 | .failure(.nonArrayResponse(object)), 183 | .failure(.nonArrayResponse(object)), 184 | .failure(.nonArrayResponse(object)) 185 | ) 186 | } 187 | 188 | return ( 189 | batchElement1.result(from: batchObjects), 190 | batchElement2.result(from: batchObjects), 191 | batchElement3.result(from: batchObjects), 192 | batchElement4.result(from: batchObjects) 193 | ) 194 | } 195 | 196 | public static func responses(from results: Results) throws -> Responses { 197 | return ( 198 | try results.0.dematerialize(), 199 | try results.1.dematerialize(), 200 | try results.2.dematerialize(), 201 | try results.3.dematerialize() 202 | ) 203 | } 204 | } 205 | 206 | public struct Batch5: Batch { 207 | public typealias Responses = (Request1.Response, Request2.Response, Request3.Response, Request4.Response, Request5.Response) 208 | public typealias Results = (Result, Result, Result, Result, Result) 209 | 210 | public let batchElement1: BatchElement 211 | public let batchElement2: BatchElement 212 | public let batchElement3: BatchElement 213 | public let batchElement4: BatchElement 214 | public let batchElement5: BatchElement 215 | 216 | public var requestObject: Any { 217 | return [ 218 | batchElement1.body, 219 | batchElement2.body, 220 | batchElement3.body, 221 | batchElement4.body, 222 | batchElement5.body, 223 | ] 224 | } 225 | 226 | public func responses(from object: Any) throws -> Responses { 227 | guard let batchObjects = object as? [Any] else { 228 | throw JSONRPCError.nonArrayResponse(object) 229 | } 230 | 231 | return ( 232 | try batchElement1.response(from: batchObjects), 233 | try batchElement2.response(from: batchObjects), 234 | try batchElement3.response(from: batchObjects), 235 | try batchElement4.response(from: batchObjects), 236 | try batchElement5.response(from: batchObjects) 237 | ) 238 | } 239 | 240 | public func results(from object: Any) -> Results { 241 | guard let batchObjects = object as? [Any] else { 242 | return ( 243 | .failure(.nonArrayResponse(object)), 244 | .failure(.nonArrayResponse(object)), 245 | .failure(.nonArrayResponse(object)), 246 | .failure(.nonArrayResponse(object)), 247 | .failure(.nonArrayResponse(object)) 248 | ) 249 | } 250 | 251 | return ( 252 | batchElement1.result(from: batchObjects), 253 | batchElement2.result(from: batchObjects), 254 | batchElement3.result(from: batchObjects), 255 | batchElement4.result(from: batchObjects), 256 | batchElement5.result(from: batchObjects) 257 | ) 258 | } 259 | 260 | public static func responses(from results: Results) throws -> Responses { 261 | return ( 262 | try results.0.dematerialize(), 263 | try results.1.dematerialize(), 264 | try results.2.dematerialize(), 265 | try results.3.dematerialize(), 266 | try results.4.dematerialize() 267 | ) 268 | } 269 | } 270 | 271 | public struct Batch6: Batch { 272 | public typealias Responses = (Request1.Response, Request2.Response, Request3.Response, Request4.Response, Request5.Response, Request6.Response) 273 | public typealias Results = (Result, Result, Result, Result, Result, Result) 274 | 275 | public let batchElement1: BatchElement 276 | public let batchElement2: BatchElement 277 | public let batchElement3: BatchElement 278 | public let batchElement4: BatchElement 279 | public let batchElement5: BatchElement 280 | public let batchElement6: BatchElement 281 | 282 | public var requestObject: Any { 283 | return [ 284 | batchElement1.body, 285 | batchElement2.body, 286 | batchElement3.body, 287 | batchElement4.body, 288 | batchElement5.body, 289 | batchElement6.body, 290 | ] 291 | } 292 | 293 | public func responses(from object: Any) throws -> Responses { 294 | guard let batchObjects = object as? [Any] else { 295 | throw JSONRPCError.nonArrayResponse(object) 296 | } 297 | 298 | return ( 299 | try batchElement1.response(from: batchObjects), 300 | try batchElement2.response(from: batchObjects), 301 | try batchElement3.response(from: batchObjects), 302 | try batchElement4.response(from: batchObjects), 303 | try batchElement5.response(from: batchObjects), 304 | try batchElement6.response(from: batchObjects) 305 | ) 306 | } 307 | 308 | public func results(from object: Any) -> Results { 309 | guard let batchObjects = object as? [Any] else { 310 | return ( 311 | .failure(.nonArrayResponse(object)), 312 | .failure(.nonArrayResponse(object)), 313 | .failure(.nonArrayResponse(object)), 314 | .failure(.nonArrayResponse(object)), 315 | .failure(.nonArrayResponse(object)), 316 | .failure(.nonArrayResponse(object)) 317 | ) 318 | } 319 | 320 | return ( 321 | batchElement1.result(from: batchObjects), 322 | batchElement2.result(from: batchObjects), 323 | batchElement3.result(from: batchObjects), 324 | batchElement4.result(from: batchObjects), 325 | batchElement5.result(from: batchObjects), 326 | batchElement6.result(from: batchObjects) 327 | ) 328 | } 329 | 330 | public static func responses(from results: Results) throws -> Responses { 331 | return ( 332 | try results.0.dematerialize(), 333 | try results.1.dematerialize(), 334 | try results.2.dematerialize(), 335 | try results.3.dematerialize(), 336 | try results.4.dematerialize(), 337 | try results.5.dematerialize() 338 | ) 339 | } 340 | } 341 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/BatchElement.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BatchElement.swift 3 | // JSONRPCKit 4 | // 5 | // Created by ishkawa on 2016/07/27. 6 | // Copyright © 2016年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Result 11 | 12 | internal protocol BatchElementProcotol { 13 | associatedtype Request: JSONRPCKit.Request 14 | 15 | var request: Request { get } 16 | var version: String { get } 17 | var id: Id? { get } 18 | var body: Any { get } 19 | 20 | func response(from: Any) throws -> Request.Response 21 | func response(from: [Any]) throws -> Request.Response 22 | 23 | func result(from: Any) -> Result 24 | func result(from: [Any]) -> Result 25 | } 26 | 27 | internal extension BatchElementProcotol { 28 | /// - Throws: JSONRPCError 29 | internal func response(from object: Any) throws -> Request.Response { 30 | switch result(from: object) { 31 | case .success(let response): 32 | return response 33 | 34 | case .failure(let error): 35 | throw error 36 | } 37 | } 38 | 39 | /// - Throws: JSONRPCError 40 | internal func response(from objects: [Any]) throws -> Request.Response { 41 | switch result(from: objects) { 42 | case .success(let response): 43 | return response 44 | 45 | case .failure(let error): 46 | throw error 47 | } 48 | } 49 | 50 | internal func result(from object: Any) -> Result { 51 | guard let dictionary = object as? [String: Any] else { 52 | return .failure(.unexpectedTypeObject(object)) 53 | } 54 | 55 | let receivedVersion = dictionary["jsonrpc"] as? String 56 | guard version == receivedVersion else { 57 | return .failure(.unsupportedVersion(receivedVersion)) 58 | } 59 | 60 | guard id == dictionary["id"].flatMap(Id.init) else { 61 | return .failure(.responseNotFound(requestId: id, object: dictionary)) 62 | } 63 | 64 | let resultObject = dictionary["result"] 65 | let errorObject = dictionary["error"] 66 | 67 | switch (resultObject, errorObject) { 68 | case (nil, let errorObject?): 69 | return .failure(JSONRPCError(errorObject: errorObject)) 70 | 71 | case (let resultObject?, nil): 72 | do { 73 | return .success(try request.response(from: resultObject)) 74 | } catch { 75 | return .failure(.resultObjectParseError(error)) 76 | } 77 | 78 | default: 79 | return .failure(.missingBothResultAndError(dictionary)) 80 | } 81 | } 82 | 83 | internal func result(from objects: [Any]) -> Result { 84 | let matchedObject = objects 85 | .flatMap { $0 as? [String: Any] } 86 | .filter { $0["id"].flatMap(Id.init) == id } 87 | .first 88 | 89 | guard let object = matchedObject else { 90 | return .failure(.responseNotFound(requestId: id, object: objects)) 91 | } 92 | 93 | return result(from: object) 94 | } 95 | } 96 | 97 | internal extension BatchElementProcotol where Request.Response == Void { 98 | internal func response(_ object: Any) throws -> Request.Response { 99 | return () 100 | } 101 | 102 | internal func response(_ objects: [Any]) throws -> Request.Response { 103 | return () 104 | } 105 | 106 | internal func result(_ object: Any) -> Result { 107 | return .success(()) 108 | } 109 | 110 | internal func result(_ objects: [Any]) -> Result { 111 | return .success(()) 112 | } 113 | } 114 | 115 | public struct BatchElement: BatchElementProcotol { 116 | public let request: Request 117 | public let version: String 118 | public let id: Id? 119 | public let body: Any 120 | 121 | public init(request: Request, version: String, id: Id) { 122 | let id: Id? = request.isNotification ? nil : id 123 | 124 | var body: [String: Any] = [ 125 | "jsonrpc": version, 126 | "method": request.method, 127 | ] 128 | 129 | body["id"] = id?.value 130 | body["params"] = request.parameters 131 | 132 | request.extendedFields?.forEach { (key, value) in 133 | body[key] = value 134 | } 135 | 136 | self.request = request 137 | self.version = version 138 | self.id = id 139 | self.body = body 140 | } 141 | } 142 | 143 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/BatchFactory.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BatchFactory.swift 3 | // JSONRPCKit 4 | // 5 | // Created by ishkawa on 2016/07/28. 6 | // Copyright © 2016年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Dispatch 11 | 12 | public final class BatchFactory { 13 | public let version: String 14 | public var idGenerator: IdGenerator 15 | 16 | private let semaphore = DispatchSemaphore(value: 1) 17 | 18 | public init(version: String = "2.0", idGenerator: IdGenerator = NumberIdGenerator()) { 19 | self.version = version 20 | self.idGenerator = idGenerator 21 | } 22 | 23 | public func create(_ request: Request) -> Batch1 { 24 | _ = semaphore.wait(timeout: DispatchTime.distantFuture) 25 | let batchElement = BatchElement(request: request, version: version, id: idGenerator.next()) 26 | semaphore.signal() 27 | 28 | return Batch1(batchElement: batchElement) 29 | } 30 | 31 | public func create(_ request1: Request1, _ request2: Request2) -> Batch2 { 32 | _ = semaphore.wait(timeout: DispatchTime.distantFuture) 33 | let batchElement1 = BatchElement(request: request1, version: version, id: idGenerator.next()) 34 | let batchElement2 = BatchElement(request: request2, version: version, id: idGenerator.next()) 35 | semaphore.signal() 36 | 37 | return Batch2(batchElement1: batchElement1, batchElement2: batchElement2) 38 | } 39 | 40 | public func create(_ request1: Request1, _ request2: Request2, _ request3: Request3) -> Batch3 { 41 | _ = semaphore.wait(timeout: DispatchTime.distantFuture) 42 | let batchElement1 = BatchElement(request: request1, version: version, id: idGenerator.next()) 43 | let batchElement2 = BatchElement(request: request2, version: version, id: idGenerator.next()) 44 | let batchElement3 = BatchElement(request: request3, version: version, id: idGenerator.next()) 45 | semaphore.signal() 46 | 47 | return Batch3(batchElement1: batchElement1, batchElement2: batchElement2, batchElement3: batchElement3) 48 | } 49 | 50 | public func create(_ request1: Request1, _ request2: Request2, _ request3: Request3, _ request4: Request4) -> Batch4 { 51 | _ = semaphore.wait(timeout: DispatchTime.distantFuture) 52 | let batchElement1 = BatchElement(request: request1, version: version, id: idGenerator.next()) 53 | let batchElement2 = BatchElement(request: request2, version: version, id: idGenerator.next()) 54 | let batchElement3 = BatchElement(request: request3, version: version, id: idGenerator.next()) 55 | let batchElement4 = BatchElement(request: request4, version: version, id: idGenerator.next()) 56 | semaphore.signal() 57 | 58 | return Batch4(batchElement1: batchElement1, batchElement2: batchElement2, batchElement3: batchElement3, batchElement4: batchElement4) 59 | } 60 | 61 | public func create(_ request1: Request1, _ request2: Request2, _ request3: Request3, _ request4: Request4, _ request5: Request5) -> Batch5 { 62 | _ = semaphore.wait(timeout: DispatchTime.distantFuture) 63 | let batchElement1 = BatchElement(request: request1, version: version, id: idGenerator.next()) 64 | let batchElement2 = BatchElement(request: request2, version: version, id: idGenerator.next()) 65 | let batchElement3 = BatchElement(request: request3, version: version, id: idGenerator.next()) 66 | let batchElement4 = BatchElement(request: request4, version: version, id: idGenerator.next()) 67 | let batchElement5 = BatchElement(request: request5, version: version, id: idGenerator.next()) 68 | semaphore.signal() 69 | 70 | return Batch5(batchElement1: batchElement1, batchElement2: batchElement2, batchElement3: batchElement3, batchElement4: batchElement4, batchElement5: batchElement5) 71 | } 72 | 73 | public func create(request1: Request1, _ request2: Request2, _ request3: Request3, _ request4: Request4, _ request5: Request5, _ request6: Request6) -> Batch6 { 74 | _ = semaphore.wait(timeout: DispatchTime.distantFuture) 75 | let batchElement1 = BatchElement(request: request1, version: version, id: idGenerator.next()) 76 | let batchElement2 = BatchElement(request: request2, version: version, id: idGenerator.next()) 77 | let batchElement3 = BatchElement(request: request3, version: version, id: idGenerator.next()) 78 | let batchElement4 = BatchElement(request: request4, version: version, id: idGenerator.next()) 79 | let batchElement5 = BatchElement(request: request5, version: version, id: idGenerator.next()) 80 | let batchElement6 = BatchElement(request: request6, version: version, id: idGenerator.next()) 81 | semaphore.signal() 82 | 83 | return Batch6(batchElement1: batchElement1, batchElement2: batchElement2, batchElement3: batchElement3, batchElement4: batchElement4, batchElement5: batchElement5, batchElement6: batchElement6) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/Id.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Id.swift 3 | // JSONRPCKit 4 | // 5 | // Created by Shinichiro Oba on 11/12/15. 6 | // Copyright © 2015 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public enum Id { 12 | case number(Int) 13 | case string(Swift.String) 14 | } 15 | 16 | extension Id { 17 | 18 | public init?(value: Any) { 19 | switch value { 20 | case let number as Int: 21 | self = .number(number) 22 | case let string as Swift.String: 23 | self = .string(string) 24 | default: 25 | return nil 26 | } 27 | } 28 | 29 | public var value: Any { 30 | switch self { 31 | case .number(let number): 32 | return number as Any 33 | case .string(let string): 34 | return string as Any 35 | } 36 | } 37 | } 38 | 39 | extension Id: Hashable { 40 | 41 | public var hashValue: Int { 42 | switch self { 43 | case .number(let number): 44 | return number 45 | case .string(let string): 46 | return string.hashValue 47 | } 48 | } 49 | } 50 | 51 | public func ==(lhs: Id, rhs: Id) -> Bool { 52 | if case let (.number(left), .number(right)) = (lhs, rhs) { 53 | return left == right 54 | } 55 | 56 | if case let (.string(left), .string(right)) = (lhs, rhs) { 57 | return left == right 58 | } 59 | 60 | return false 61 | } 62 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/IdGenerator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IdGenerator.swift 3 | // JSONRPCKit 4 | // 5 | // Created by Shinichiro Oba on 2015/11/11. 6 | // Copyright © 2015年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public protocol IdGenerator { 12 | 13 | mutating func next() -> Id 14 | } 15 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/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 | FMWK 17 | CFBundleShortVersionString 18 | 3.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/JSONRPCError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCError.swift 3 | // JSONRPCKit 4 | // 5 | // Created by Shinichiro Oba on 2015/11/09. 6 | // Copyright © 2015年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public enum JSONRPCError: Error { 12 | case responseError(code: Int, message: String, data: Any?) 13 | case responseNotFound(requestId: Id?, object: Any) 14 | case resultObjectParseError(Error) 15 | case errorObjectParseError(Error) 16 | case unsupportedVersion(String?) 17 | case unexpectedTypeObject(Any) 18 | case missingBothResultAndError(Any) 19 | case nonArrayResponse(Any) 20 | 21 | public init(errorObject: Any) { 22 | enum ParseError: Error { 23 | case nonDictionaryObject(object: Any) 24 | case missingKey(key: String, errorObject: Any) 25 | } 26 | 27 | do { 28 | guard let dictionary = errorObject as? [String: Any] else { 29 | throw ParseError.nonDictionaryObject(object: errorObject) 30 | } 31 | 32 | guard let code = dictionary["code"] as? Int else { 33 | throw ParseError.missingKey(key: "code", errorObject: errorObject) 34 | } 35 | 36 | guard let message = dictionary["message"] as? String else { 37 | throw ParseError.missingKey(key: "message", errorObject: errorObject) 38 | } 39 | 40 | self = .responseError(code: code, message: message, data: dictionary["data"]) 41 | } catch { 42 | self = .errorObjectParseError(error) 43 | } 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/JSONRPCKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRPCKit.h 3 | // JSONRPCKit 4 | // 5 | // Created by Shinichiro Oba on 2015/11/09. 6 | // Copyright © 2015年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | //! Project version number for JSONRPCKit. 10 | extern double JSONRPCKitVersionNumber; 11 | 12 | //! Project version string for JSONRPCKit. 13 | extern const unsigned char JSONRPCKitVersionString[]; 14 | 15 | // In this header, you should import all the public headers of your framework using statements like #import 16 | 17 | 18 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/NumberIdGenerator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NumberIdentifierGenerator.swift 3 | // JSONRPCKit 4 | // 5 | // Created by Shinichiro Oba on 2015/11/11. 6 | // Copyright © 2015年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct NumberIdGenerator: IdGenerator { 12 | 13 | private var currentId = 1 14 | 15 | public init() {} 16 | 17 | public mutating func next() -> Id { 18 | defer { 19 | currentId += 1 20 | } 21 | 22 | return .number(currentId) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/JSONRPCKit/Request.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Request.swift 3 | // JSONRPCKit 4 | // 5 | // Created by Shinichiro Oba on 2015/11/09. 6 | // Copyright © 2015年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public protocol Request { 12 | /// If `Response == Void`, request is treated as a notification. 13 | associatedtype Response 14 | 15 | var method: String { get } 16 | var parameters: Any? { get } 17 | var extendedFields: [String: Any]? { get } 18 | var isNotification: Bool { get } 19 | 20 | func response(from resultObject: Any) throws -> Response 21 | } 22 | 23 | public extension Request { 24 | public var parameters: Any? { 25 | return nil 26 | } 27 | 28 | public var extendedFields: [String: Any]? { 29 | return nil 30 | } 31 | 32 | public var isNotification: Bool { 33 | return false 34 | } 35 | } 36 | 37 | public extension Request where Response == Void { 38 | public var isNotification: Bool { 39 | return true 40 | } 41 | 42 | public func response(from resultObject: Any) throws -> Response { 43 | return () 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tests/JSONRPCKitTests/BatchElementTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BatchElementTests.swift 3 | // JSONRPCKit 4 | // 5 | // Created by ishkawa on 2016/07/29. 6 | // Copyright © 2016年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import JSONRPCKit 11 | 12 | class BatchElementTests: XCTestCase { 13 | 14 | func testRequestObject() { 15 | let request = TestRequest(method: "method", parameters: ["key": "value"], extendedFields: ["exkey": "exvalue"]) 16 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 17 | XCTAssertEqual(batchElement.id, Id.number(1)) 18 | XCTAssertEqual(batchElement.version, "2.0") 19 | 20 | let requestObject = batchElement.body as? [String: Any] 21 | XCTAssertEqual(requestObject?.keys.count, 5) 22 | XCTAssertEqual(requestObject?["jsonrpc"] as? String, "2.0") 23 | XCTAssertEqual(requestObject?["id"] as? Int, 1) 24 | XCTAssertEqual(requestObject?["method"] as? String, "method") 25 | XCTAssertEqual(requestObject?["exkey"] as? String, "exvalue") 26 | 27 | let parameters = requestObject?["params"] as? [String: Any] 28 | XCTAssertEqual(parameters?.keys.count, 1) 29 | XCTAssertEqual(parameters?["key"] as? String, "value") 30 | } 31 | 32 | func testNotificationRequestObject() { 33 | let request = TestNotificationRequest(method: "method", parameters: nil) 34 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 35 | 36 | XCTAssertNil(batchElement.id) 37 | XCTAssertEqual(batchElement.version, "2.0") 38 | 39 | let requestObject = batchElement.body as? [String: Any] 40 | XCTAssertEqual(requestObject?.keys.count, 2) 41 | XCTAssertEqual(requestObject?["jsonrpc"] as? String, "2.0") 42 | XCTAssertEqual(requestObject?["method"] as? String, "method") 43 | XCTAssertNil(requestObject?["id"]) 44 | XCTAssertNil(requestObject?["params"]) 45 | } 46 | 47 | func testResponseFromObject() { 48 | let request = TestRequest(method: "method", parameters: nil) 49 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 50 | 51 | let responseObject: Any = [ 52 | "id": 1, 53 | "jsonrpc": "2.0", 54 | "result": [ 55 | "key": "value", 56 | ] 57 | ] 58 | 59 | let response = try? batchElement.response(from: responseObject) 60 | let dictionary = response as? [String: Any] 61 | XCTAssertEqual(dictionary?["key"] as? String, "value") 62 | } 63 | 64 | func testResponseFromArray() { 65 | let request = TestRequest(method: "method", parameters: nil) 66 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 67 | 68 | let responseArray: [Any] = [ 69 | [ 70 | "id": 1, 71 | "jsonrpc": "2.0", 72 | "result": [ 73 | "key1": "value1", 74 | ] 75 | ], 76 | [ 77 | "id": 2, 78 | "jsonrpc": "2.0", 79 | "result": [ 80 | "key2": "value2", 81 | ] 82 | ] 83 | ] 84 | 85 | let response = try? batchElement.response(from: responseArray) 86 | let dictionary = response as? [String: Any] 87 | XCTAssertEqual(dictionary?["key1"] as? String, "value1") 88 | } 89 | 90 | func testResponseFromObjectResponseError() { 91 | let request = TestRequest(method: "method", parameters: nil) 92 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 93 | 94 | let responseObject: Any = [ 95 | "id": 1, 96 | "jsonrpc": "2.0", 97 | "error": [ 98 | "code": 123, 99 | "message": "abc", 100 | "data": [ 101 | "key": "value", 102 | ] 103 | ] 104 | ] 105 | 106 | do { 107 | _ = try batchElement.response(from: responseObject) 108 | XCTFail() 109 | } catch { 110 | let error = error as? JSONRPCError 111 | if case .responseError(let code, let message, let data as [String: Any])? = error { 112 | XCTAssertEqual(code, 123) 113 | XCTAssertEqual(message, "abc") 114 | XCTAssertEqual(data["key"] as? String, "value") 115 | } else { 116 | XCTFail() 117 | } 118 | } 119 | } 120 | 121 | func testResponseFromArrayResponseError() { 122 | let request = TestRequest(method: "method", parameters: nil) 123 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 124 | 125 | let responseArray: [Any] = [ 126 | [ 127 | "id": 1, 128 | "jsonrpc": "2.0", 129 | "error": [ 130 | "code": 123, 131 | "message": "abc", 132 | "data": [ 133 | "key": "value", 134 | ] 135 | ] 136 | ], 137 | [ 138 | "id": 2, 139 | "jsonrpc": "2.0", 140 | "result": [:], 141 | ] 142 | ] 143 | 144 | do { 145 | _ = try batchElement.response(from: responseArray) 146 | XCTFail() 147 | } catch { 148 | let error = error as? JSONRPCError 149 | if case .responseError(let code, let message, let data as [String: Any])? = error { 150 | XCTAssertEqual(code, 123) 151 | XCTAssertEqual(message, "abc") 152 | XCTAssertEqual(data["key"] as? String, "value") 153 | } else { 154 | XCTFail() 155 | } 156 | } 157 | } 158 | 159 | func testResponseFromObjectresultObjectParseError() { 160 | let request = TestParseErrorRequest(method: "method", parameters: nil) 161 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 162 | 163 | let responseObject: Any = [ 164 | "id": 1, 165 | "jsonrpc": "2.0", 166 | "result": [:], 167 | ] 168 | 169 | do { 170 | _ = try batchElement.response(from: responseObject) 171 | XCTFail() 172 | } catch { 173 | let error = error as? JSONRPCError 174 | if case .resultObjectParseError(let error)? = error { 175 | XCTAssert(error is TestParseErrorRequest.ParseError) 176 | } else { 177 | XCTFail() 178 | } 179 | } 180 | } 181 | 182 | func testResponseFromArrayresultObjectParseError() { 183 | let request = TestParseErrorRequest(method: "method", parameters: nil) 184 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 185 | 186 | let responseArray: [Any] = [ 187 | [ 188 | "id": 1, 189 | "jsonrpc": "2.0", 190 | "result": [:] 191 | ], 192 | [ 193 | "id": 2, 194 | "jsonrpc": "2.0", 195 | "result": [:], 196 | ] 197 | ] 198 | 199 | do { 200 | _ = try batchElement.response(from: responseArray) 201 | XCTFail() 202 | } catch { 203 | let error = error as? JSONRPCError 204 | if case .resultObjectParseError(let error)? = error { 205 | XCTAssert(error is TestParseErrorRequest.ParseError) 206 | } else { 207 | XCTFail() 208 | } 209 | } 210 | } 211 | 212 | func testResponseFromObjectErrorObjectParseError() { 213 | let request = TestRequest(method: "method", parameters: nil) 214 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 215 | 216 | let responseObject: Any = [ 217 | "id": 1, 218 | "jsonrpc": "2.0", 219 | "error": [ 220 | "message": "abc", 221 | ] 222 | ] 223 | 224 | do { 225 | _ = try batchElement.response(from: responseObject) 226 | XCTFail() 227 | } catch { 228 | let error = error as? JSONRPCError 229 | if case .errorObjectParseError? = error { 230 | 231 | } else { 232 | XCTFail() 233 | } 234 | } 235 | } 236 | 237 | func testResponseFromArrayErrorObjectParseError() { 238 | let request = TestRequest(method: "method", parameters: nil) 239 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 240 | 241 | let responseArray: [Any] = [ 242 | [ 243 | "id": 1, 244 | "jsonrpc": "2.0", 245 | "error": [ 246 | "message": "abc", 247 | ] 248 | ], 249 | [ 250 | "id": 2, 251 | "jsonrpc": "2.0", 252 | "result": [:], 253 | ] 254 | ] 255 | 256 | do { 257 | _ = try batchElement.response(from: responseArray) 258 | XCTFail() 259 | } catch { 260 | let error = error as? JSONRPCError 261 | if case .errorObjectParseError? = error { 262 | 263 | } else { 264 | XCTFail() 265 | } 266 | } 267 | } 268 | 269 | func testResponseFromObjectunsupportedVersion() { 270 | let request = TestRequest(method: "method", parameters: nil) 271 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 272 | 273 | let responseObject: Any = [ 274 | "id": 1, 275 | "jsonrpc": "1.0", 276 | "result": [ 277 | "key": "value", 278 | ] 279 | ] 280 | 281 | do { 282 | _ = try batchElement.response(from: responseObject) 283 | XCTFail() 284 | } catch { 285 | let error = error as? JSONRPCError 286 | if case .unsupportedVersion(let version)? = error { 287 | XCTAssertEqual(version, "1.0") 288 | } else { 289 | XCTFail() 290 | } 291 | } 292 | } 293 | 294 | func testResponseFromArrayunsupportedVersion() { 295 | let request = TestRequest(method: "method", parameters: nil) 296 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 297 | 298 | let responseArray: [Any] = [ 299 | [ 300 | "id": 1, 301 | "jsonrpc": "1.0", 302 | "result": [:], 303 | ], 304 | [ 305 | "id": 2, 306 | "jsonrpc": "2.0", 307 | "result": [:], 308 | ] 309 | ] 310 | 311 | do { 312 | _ = try batchElement.response(from: responseArray) 313 | XCTFail() 314 | } catch { 315 | let error = error as? JSONRPCError 316 | if case .unsupportedVersion(let version)? = error { 317 | XCTAssertEqual(version, "1.0") 318 | } else { 319 | XCTFail() 320 | } 321 | } 322 | } 323 | 324 | func testResponseFromObjectresponseNotFound() { 325 | let request = TestRequest(method: "method", parameters: nil) 326 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 327 | 328 | let responseObject: Any = [ 329 | "id": 2, 330 | "jsonrpc": "2.0", 331 | "result": [:] 332 | ] 333 | 334 | do { 335 | _ = try batchElement.response(from: responseObject) 336 | XCTFail() 337 | } catch { 338 | let error = error as? JSONRPCError 339 | if case .responseNotFound(let id, let object as [String: Any])? = error { 340 | XCTAssertEqual(id, batchElement.id) 341 | XCTAssertEqual(object["id"] as? Int, 2) 342 | } else { 343 | XCTFail() 344 | } 345 | } 346 | } 347 | 348 | func testResponseFromArrayresponseNotFound() { 349 | let request = TestRequest(method: "method", parameters: nil) 350 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 351 | 352 | let responseArray: [Any] = [ 353 | [ 354 | "id": 2, 355 | "jsonrpc": "2.0", 356 | "result": [:], 357 | ], 358 | [ 359 | "id": 3, 360 | "jsonrpc": "2.0", 361 | "result": [:], 362 | ] 363 | ] 364 | 365 | do { 366 | _ = try batchElement.response(from: responseArray) 367 | XCTFail() 368 | } catch { 369 | let error = error as? JSONRPCError 370 | if case .responseNotFound(let id, let object as [[String: Any]])? = error { 371 | XCTAssertEqual(id, batchElement.id) 372 | XCTAssertEqual(object[0]["id"] as? Int, 2) 373 | } else { 374 | XCTFail() 375 | } 376 | } 377 | } 378 | 379 | func testResponseFromObjectmissingBothResultAndError() { 380 | let request = TestRequest(method: "method", parameters: nil) 381 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 382 | 383 | let responseObject: Any = [ 384 | "id": 1, 385 | "jsonrpc": "2.0", 386 | ] 387 | 388 | do { 389 | _ = try batchElement.response(from: responseObject) 390 | XCTFail() 391 | } catch { 392 | let error = error as? JSONRPCError 393 | if case .missingBothResultAndError? = error { 394 | 395 | } else { 396 | XCTFail() 397 | } 398 | } 399 | } 400 | 401 | func testResponseFromArraymissingBothResultAndError() { 402 | let request = TestRequest(method: "method", parameters: nil) 403 | let batchElement = BatchElement(request: request, version: "2.0", id: Id.number(1)) 404 | 405 | let responseArray: [Any] = [ 406 | [ 407 | "id": 1, 408 | "jsonrpc": "2.0", 409 | ], 410 | [ 411 | "id": 2, 412 | "jsonrpc": "2.0", 413 | "result": [:], 414 | ] 415 | ] 416 | 417 | do { 418 | _ = try batchElement.response(from: responseArray) 419 | XCTFail() 420 | } catch { 421 | let error = error as? JSONRPCError 422 | if case .missingBothResultAndError? = error { 423 | 424 | } else { 425 | XCTFail() 426 | } 427 | } 428 | } 429 | 430 | static var allTests = [ 431 | ("testRequestObject", testRequestObject), 432 | ("testNotificationRequestObject", testNotificationRequestObject), 433 | ("testResponseFromObject", testResponseFromObject), 434 | ("testResponseFromArray", testResponseFromArray), 435 | ("testResponseFromObjectResponseError", testResponseFromObjectResponseError), 436 | ("testResponseFromArrayResponseError", testResponseFromArrayResponseError), 437 | ("testResponseFromObjectresultObjectParseError", testResponseFromObjectresultObjectParseError), 438 | ("testResponseFromArrayresultObjectParseError", testResponseFromArrayresultObjectParseError), 439 | ("testResponseFromObjectErrorObjectParseError", testResponseFromObjectErrorObjectParseError), 440 | ("testResponseFromArrayErrorObjectParseError", testResponseFromArrayErrorObjectParseError), 441 | ("testResponseFromObjectunsupportedVersion", testResponseFromObjectunsupportedVersion), 442 | ("testResponseFromArrayunsupportedVersion", testResponseFromArrayunsupportedVersion), 443 | ("testResponseFromObjectresponseNotFound", testResponseFromObjectresponseNotFound), 444 | ("testResponseFromArrayresponseNotFound", testResponseFromArrayresponseNotFound), 445 | ("testResponseFromObjectmissingBothResultAndError", testResponseFromObjectmissingBothResultAndError), 446 | ("testResponseFromArraymissingBothResultAndError", testResponseFromArraymissingBothResultAndError), 447 | ] 448 | } 449 | -------------------------------------------------------------------------------- /Tests/JSONRPCKitTests/BatchFactoryTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BatchFactoryTests.swift 3 | // JSONRPCKit 4 | // 5 | // Created by ishkawa on 2016/07/29. 6 | // Copyright © 2016年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import JSONRPCKit 11 | import Dispatch 12 | 13 | class BatchFactoryTests: XCTestCase { 14 | var batchFactory: BatchFactory! 15 | 16 | override func setUp() { 17 | super.setUp() 18 | 19 | batchFactory = BatchFactory() 20 | } 21 | 22 | func test1() { 23 | let request = TestRequest(method: "method", parameters: ["key": "value"]) 24 | let batch = batchFactory.create(request) 25 | 26 | XCTAssertEqual(batch.batchElement.id?.value as? Int, 1) 27 | } 28 | 29 | func test2() { 30 | let request1 = TestRequest(method: "method1", parameters: ["key1": "value1"]) 31 | let request2 = TestRequest(method: "method2", parameters: ["key2": "value2"]) 32 | let batch = batchFactory.create(request1, request2) 33 | 34 | XCTAssertEqual(batch.batchElement1.id?.value as? Int, 1) 35 | XCTAssertEqual(batch.batchElement2.id?.value as? Int, 2) 36 | } 37 | 38 | func test3() { 39 | let request1 = TestRequest(method: "method1", parameters: ["key1": "value1"]) 40 | let request2 = TestRequest(method: "method2", parameters: ["key2": "value2"]) 41 | let request3 = TestRequest(method: "method3", parameters: ["key3": "value3"]) 42 | let batch = batchFactory.create(request1, request2, request3) 43 | 44 | XCTAssertEqual(batch.batchElement1.id?.value as? Int, 1) 45 | XCTAssertEqual(batch.batchElement2.id?.value as? Int, 2) 46 | XCTAssertEqual(batch.batchElement3.id?.value as? Int, 3) 47 | } 48 | 49 | func test4() { 50 | let request1 = TestRequest(method: "method1", parameters: ["key1": "value1"]) 51 | let request2 = TestRequest(method: "method2", parameters: ["key2": "value2"]) 52 | let request3 = TestRequest(method: "method3", parameters: ["key3": "value3"]) 53 | let request4 = TestRequest(method: "method4", parameters: ["key4": "value4"]) 54 | let batch = batchFactory.create(request1, request2, request3, request4) 55 | 56 | XCTAssertEqual(batch.batchElement1.id?.value as? Int, 1) 57 | XCTAssertEqual(batch.batchElement2.id?.value as? Int, 2) 58 | XCTAssertEqual(batch.batchElement3.id?.value as? Int, 3) 59 | XCTAssertEqual(batch.batchElement4.id?.value as? Int, 4) 60 | } 61 | 62 | func test5() { 63 | let request1 = TestRequest(method: "method1", parameters: ["key1": "value1"]) 64 | let request2 = TestRequest(method: "method2", parameters: ["key2": "value2"]) 65 | let request3 = TestRequest(method: "method3", parameters: ["key3": "value3"]) 66 | let request4 = TestRequest(method: "method4", parameters: ["key4": "value4"]) 67 | let request5 = TestRequest(method: "method5", parameters: ["key5": "value5"]) 68 | let batch = batchFactory.create(request1, request2, request3, request4, request5) 69 | 70 | XCTAssertEqual(batch.batchElement1.id?.value as? Int, 1) 71 | XCTAssertEqual(batch.batchElement2.id?.value as? Int, 2) 72 | XCTAssertEqual(batch.batchElement3.id?.value as? Int, 3) 73 | XCTAssertEqual(batch.batchElement4.id?.value as? Int, 4) 74 | XCTAssertEqual(batch.batchElement5.id?.value as? Int, 5) 75 | } 76 | 77 | func testThreadSafety() { 78 | let operationQueue = OperationQueue() 79 | 80 | for _ in 1..<10000 { 81 | operationQueue.addOperation { 82 | let request = TestRequest(method: "method", parameters: nil) 83 | _ = self.batchFactory.create(request) 84 | } 85 | } 86 | 87 | operationQueue.waitUntilAllOperationsAreFinished() 88 | 89 | let nextId = batchFactory.idGenerator.next().value as? Int 90 | XCTAssertEqual(nextId, 10000) 91 | } 92 | 93 | static var allTests = [ 94 | ("test1", test1), 95 | ("test2", test2), 96 | ("test3", test3), 97 | ("test4", test4), 98 | ("test5", test5), 99 | ("testThreadSafety", testThreadSafety), 100 | ] 101 | } 102 | -------------------------------------------------------------------------------- /Tests/JSONRPCKitTests/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 | -------------------------------------------------------------------------------- /Tests/JSONRPCKitTests/TestRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TestRequest.swift 3 | // JSONRPCKit 4 | // 5 | // Created by ishkawa on 2016/07/28. 6 | // Copyright © 2016年 Shinichiro Oba. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import JSONRPCKit 11 | 12 | struct TestRequest: Request { 13 | typealias Response = Any 14 | 15 | let method: String 16 | let parameters: Any? 17 | let extendedFields: [String : Any]? 18 | 19 | init(method: String, parameters: Any?, extendedFields: [String: Any]? = nil) { 20 | self.method = method 21 | self.parameters = parameters 22 | self.extendedFields = extendedFields 23 | } 24 | 25 | func response(from resultObject: Any) throws -> Any { 26 | return resultObject 27 | } 28 | } 29 | 30 | struct TestNotificationRequest: Request { 31 | typealias Response = Void 32 | 33 | let method: String 34 | let parameters: Any? 35 | } 36 | 37 | struct TestParseErrorRequest: Request { 38 | struct ParseError: Error { 39 | 40 | } 41 | 42 | typealias Response = Any 43 | 44 | let method: String 45 | let parameters: Any? 46 | 47 | func response(from resultObject: Any) throws -> Any { 48 | throw ParseError() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import JSONRPCKitTests 3 | 4 | XCTMain([ 5 | testCase(BatchElementTests.allTests), 6 | testCase(BatchFactoryTests.allTests), 7 | ]) 8 | --------------------------------------------------------------------------------