├── .gitignore ├── .swift-version ├── .travis.yaml ├── AI.podspec ├── AI.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── AI.xcscheme ├── AI ├── AI.h ├── Info.plist └── src │ ├── AI.swift │ ├── CallbacksContainer.swift │ ├── Completion.swift │ ├── Credentials.swift │ ├── JSON.swift │ ├── NSError.swift │ ├── QueryResponse.swift │ ├── Requests │ ├── PrivateRequest.swift │ ├── QueryRequest.swift │ ├── Request.swift │ ├── RequestUtilites.swift │ ├── TextQueryRequest.swift │ ├── UserEntitiesRequest.swift │ └── Utils │ │ └── SessionStorage.swift │ ├── ResponseSerialize.swift │ └── Service.swift ├── AIDemo ├── AIDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── AIDemo │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── Result │ │ └── ResultViewController.swift │ └── TextRequest │ │ └── TextRequestViewController.swift └── Podfile ├── AIOSXDemo ├── AIOSXDemo.xcodeproj │ └── project.pbxproj ├── AIOSXDemo │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ └── Main.storyboard │ ├── Info.plist │ ├── LandingViewController.swift │ └── TextRequestViewController.swift └── Podfile ├── AITests ├── AITests.swift └── Info.plist ├── LICENSE └── README.md /.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 | Podfile.lock 28 | 29 | # Carthage 30 | # 31 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 32 | # Carthage/Checkouts 33 | 34 | Carthage/Build 35 | 36 | # Mac OS X 37 | *.DS_Store 38 | AIDemo/AIDemo.xcworkspace 39 | AIOSXDemo/AIOSXDemo.xcworkspace 40 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 3.0 2 | -------------------------------------------------------------------------------- /.travis.yaml: -------------------------------------------------------------------------------- 1 | language: swift 2 | osx_image: xcode8.2 3 | bundler_args: --retry 3 4 | git: 5 | depth: 2 6 | branches: 7 | only: 8 | - master 9 | - dev 10 | xcode_project: AI.xcodeproj 11 | xcode_scheme: AI 12 | xcode_sdk: iphonesimulator 13 | env: 14 | global: 15 | - FRAMEWORK_NAME=AI 16 | before_install: 17 | - brew update 18 | - brew outdated carthage || brew upgrade carthage 19 | before_deploy: 20 | - carthage build --no-skip-current 21 | - carthage archive $FRAMEWORK_NAME 22 | notifications: 23 | email: 24 | recipients: 25 | - dkuragin@ya.ru 26 | - kuragin@speaktoit.com 27 | -------------------------------------------------------------------------------- /AI.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'AI' 3 | s.version = '0.0.8' 4 | s.license = 'MIT' 5 | s.summary = 'The API.AI iOS SDK makes it easy to integrate speech recognition with API.AI natural language processing API on iOS devices.' 6 | s.homepage = 'https://api.ai/' 7 | s.authors = { 8 | 'Dmitriy Kuragin' => 'kuragin@speaktoit.com' 9 | } 10 | s.source = { 11 | :git => 'https://github.com/api-ai/api-ai-cocoa-swift.git', 12 | :tag => 'v' + s.version.to_s, 13 | :submodules => true 14 | } 15 | 16 | s.requires_arc = true 17 | 18 | s.ios.deployment_target = '8.0' 19 | s.osx.deployment_target = '10.9' 20 | s.tvos.deployment_target = '9.0' 21 | s.watchos.deployment_target = '2.0' 22 | 23 | s.source_files = 'AI/src/**/*.swift' 24 | end 25 | -------------------------------------------------------------------------------- /AI.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 58391DE91BF5D16500ED0C87 /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58391DE71BF5D16500ED0C87 /* Request.swift */; }; 11 | 58391DEA1BF5D16500ED0C87 /* RequestUtilites.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58391DE81BF5D16500ED0C87 /* RequestUtilites.swift */; }; 12 | 58391DEC1BF5D17700ED0C87 /* QueryRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58391DEB1BF5D17700ED0C87 /* QueryRequest.swift */; }; 13 | 58391DEE1BF5D1B000ED0C87 /* TextQueryRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58391DED1BF5D1B000ED0C87 /* TextQueryRequest.swift */; }; 14 | 58391DF01BF5D25400ED0C87 /* PrivateRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58391DEF1BF5D25400ED0C87 /* PrivateRequest.swift */; }; 15 | 5846F60B1C919E870067A9B5 /* UserEntitiesRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5846F60A1C919E870067A9B5 /* UserEntitiesRequest.swift */; }; 16 | 5846F60E1C929B7D0067A9B5 /* SessionStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5846F60D1C929B7D0067A9B5 /* SessionStorage.swift */; }; 17 | 58D6091A1BF35B0B00464A87 /* AI.h in Headers */ = {isa = PBXBuildFile; fileRef = 58D609191BF35B0B00464A87 /* AI.h */; settings = {ATTRIBUTES = (Public, ); }; }; 18 | 58D609211BF35B0B00464A87 /* AI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 58D609161BF35B0B00464A87 /* AI.framework */; }; 19 | 58D609261BF35B0B00464A87 /* AITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D609251BF35B0B00464A87 /* AITests.swift */; }; 20 | 58D609331BF35B1D00464A87 /* AI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D609311BF35B1D00464A87 /* AI.swift */; }; 21 | 58D609341BF35B1D00464A87 /* Credentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D609321BF35B1D00464A87 /* Credentials.swift */; }; 22 | 58D609381BF35C2700464A87 /* Service.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D609371BF35C2600464A87 /* Service.swift */; }; 23 | 58D6093C1BF47A9C00464A87 /* QueryResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D6093B1BF47A9C00464A87 /* QueryResponse.swift */; }; 24 | 58D6093E1BF47CBA00464A87 /* CallbacksContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D6093D1BF47CBA00464A87 /* CallbacksContainer.swift */; }; 25 | 58D609431BF4865300464A87 /* Completion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D6093F1BF4865300464A87 /* Completion.swift */; }; 26 | 58D609441BF4865300464A87 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D609401BF4865300464A87 /* JSON.swift */; }; 27 | 58D609451BF4865300464A87 /* NSError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D609411BF4865300464A87 /* NSError.swift */; }; 28 | 58D609481BF4867500464A87 /* ResponseSerialize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D609471BF4867500464A87 /* ResponseSerialize.swift */; }; 29 | /* End PBXBuildFile section */ 30 | 31 | /* Begin PBXContainerItemProxy section */ 32 | 58D609221BF35B0B00464A87 /* PBXContainerItemProxy */ = { 33 | isa = PBXContainerItemProxy; 34 | containerPortal = 58D6090D1BF35B0B00464A87 /* Project object */; 35 | proxyType = 1; 36 | remoteGlobalIDString = 58D609151BF35B0B00464A87; 37 | remoteInfo = AI; 38 | }; 39 | /* End PBXContainerItemProxy section */ 40 | 41 | /* Begin PBXFileReference section */ 42 | 582FAD161E49BCD3008DADF2 /* AI.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AI.podspec; sourceTree = ""; }; 43 | 58391DE71BF5D16500ED0C87 /* Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = ""; }; 44 | 58391DE81BF5D16500ED0C87 /* RequestUtilites.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestUtilites.swift; sourceTree = ""; }; 45 | 58391DEB1BF5D17700ED0C87 /* QueryRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryRequest.swift; sourceTree = ""; }; 46 | 58391DED1BF5D1B000ED0C87 /* TextQueryRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextQueryRequest.swift; sourceTree = ""; }; 47 | 58391DEF1BF5D25400ED0C87 /* PrivateRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivateRequest.swift; sourceTree = ""; }; 48 | 5846F60A1C919E870067A9B5 /* UserEntitiesRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserEntitiesRequest.swift; sourceTree = ""; }; 49 | 5846F60D1C929B7D0067A9B5 /* SessionStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionStorage.swift; sourceTree = ""; }; 50 | 58D609161BF35B0B00464A87 /* AI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AI.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | 58D609191BF35B0B00464A87 /* AI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AI.h; sourceTree = ""; }; 52 | 58D6091B1BF35B0B00464A87 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 53 | 58D609201BF35B0B00464A87 /* AITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 54 | 58D609251BF35B0B00464A87 /* AITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AITests.swift; sourceTree = ""; }; 55 | 58D609271BF35B0B00464A87 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56 | 58D609311BF35B1D00464A87 /* AI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AI.swift; sourceTree = ""; }; 57 | 58D609321BF35B1D00464A87 /* Credentials.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Credentials.swift; sourceTree = ""; }; 58 | 58D609371BF35C2600464A87 /* Service.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Service.swift; sourceTree = ""; }; 59 | 58D6093B1BF47A9C00464A87 /* QueryResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryResponse.swift; sourceTree = ""; }; 60 | 58D6093D1BF47CBA00464A87 /* CallbacksContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallbacksContainer.swift; sourceTree = ""; }; 61 | 58D6093F1BF4865300464A87 /* Completion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Completion.swift; sourceTree = ""; }; 62 | 58D609401BF4865300464A87 /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = ""; }; 63 | 58D609411BF4865300464A87 /* NSError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSError.swift; sourceTree = ""; }; 64 | 58D609471BF4867500464A87 /* ResponseSerialize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResponseSerialize.swift; sourceTree = ""; }; 65 | /* End PBXFileReference section */ 66 | 67 | /* Begin PBXFrameworksBuildPhase section */ 68 | 58D609121BF35B0B00464A87 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | 58D6091D1BF35B0B00464A87 /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | 58D609211BF35B0B00464A87 /* AI.framework in Frameworks */, 80 | ); 81 | runOnlyForDeploymentPostprocessing = 0; 82 | }; 83 | /* End PBXFrameworksBuildPhase section */ 84 | 85 | /* Begin PBXGroup section */ 86 | 58391DE61BF5D15300ED0C87 /* Requests */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 5846F60C1C929B6F0067A9B5 /* Utils */, 90 | 58391DE71BF5D16500ED0C87 /* Request.swift */, 91 | 58391DE81BF5D16500ED0C87 /* RequestUtilites.swift */, 92 | 58391DEB1BF5D17700ED0C87 /* QueryRequest.swift */, 93 | 58391DED1BF5D1B000ED0C87 /* TextQueryRequest.swift */, 94 | 58391DEF1BF5D25400ED0C87 /* PrivateRequest.swift */, 95 | 5846F60A1C919E870067A9B5 /* UserEntitiesRequest.swift */, 96 | ); 97 | path = Requests; 98 | sourceTree = ""; 99 | }; 100 | 5846F60C1C929B6F0067A9B5 /* Utils */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 5846F60D1C929B7D0067A9B5 /* SessionStorage.swift */, 104 | ); 105 | path = Utils; 106 | sourceTree = ""; 107 | }; 108 | 58D6090C1BF35B0B00464A87 = { 109 | isa = PBXGroup; 110 | children = ( 111 | 582FAD161E49BCD3008DADF2 /* AI.podspec */, 112 | 58D609181BF35B0B00464A87 /* AI */, 113 | 58D609241BF35B0B00464A87 /* AITests */, 114 | 58D609171BF35B0B00464A87 /* Products */, 115 | ); 116 | sourceTree = ""; 117 | }; 118 | 58D609171BF35B0B00464A87 /* Products */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 58D609161BF35B0B00464A87 /* AI.framework */, 122 | 58D609201BF35B0B00464A87 /* AITests.xctest */, 123 | ); 124 | name = Products; 125 | sourceTree = ""; 126 | }; 127 | 58D609181BF35B0B00464A87 /* AI */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 58D609301BF35B1D00464A87 /* src */, 131 | 58D609191BF35B0B00464A87 /* AI.h */, 132 | 58D6091B1BF35B0B00464A87 /* Info.plist */, 133 | ); 134 | path = AI; 135 | sourceTree = ""; 136 | }; 137 | 58D609241BF35B0B00464A87 /* AITests */ = { 138 | isa = PBXGroup; 139 | children = ( 140 | 58D609251BF35B0B00464A87 /* AITests.swift */, 141 | 58D609271BF35B0B00464A87 /* Info.plist */, 142 | ); 143 | path = AITests; 144 | sourceTree = ""; 145 | }; 146 | 58D609301BF35B1D00464A87 /* src */ = { 147 | isa = PBXGroup; 148 | children = ( 149 | 58391DE61BF5D15300ED0C87 /* Requests */, 150 | 58D609471BF4867500464A87 /* ResponseSerialize.swift */, 151 | 58D6093F1BF4865300464A87 /* Completion.swift */, 152 | 58D609401BF4865300464A87 /* JSON.swift */, 153 | 58D609411BF4865300464A87 /* NSError.swift */, 154 | 58D6093B1BF47A9C00464A87 /* QueryResponse.swift */, 155 | 58D609311BF35B1D00464A87 /* AI.swift */, 156 | 58D609321BF35B1D00464A87 /* Credentials.swift */, 157 | 58D609371BF35C2600464A87 /* Service.swift */, 158 | 58D6093D1BF47CBA00464A87 /* CallbacksContainer.swift */, 159 | ); 160 | path = src; 161 | sourceTree = ""; 162 | }; 163 | /* End PBXGroup section */ 164 | 165 | /* Begin PBXHeadersBuildPhase section */ 166 | 58D609131BF35B0B00464A87 /* Headers */ = { 167 | isa = PBXHeadersBuildPhase; 168 | buildActionMask = 2147483647; 169 | files = ( 170 | 58D6091A1BF35B0B00464A87 /* AI.h in Headers */, 171 | ); 172 | runOnlyForDeploymentPostprocessing = 0; 173 | }; 174 | /* End PBXHeadersBuildPhase section */ 175 | 176 | /* Begin PBXNativeTarget section */ 177 | 58D609151BF35B0B00464A87 /* AI */ = { 178 | isa = PBXNativeTarget; 179 | buildConfigurationList = 58D6092A1BF35B0B00464A87 /* Build configuration list for PBXNativeTarget "AI" */; 180 | buildPhases = ( 181 | 58D609111BF35B0B00464A87 /* Sources */, 182 | 58D609121BF35B0B00464A87 /* Frameworks */, 183 | 58D609131BF35B0B00464A87 /* Headers */, 184 | 58D609141BF35B0B00464A87 /* Resources */, 185 | ); 186 | buildRules = ( 187 | ); 188 | dependencies = ( 189 | ); 190 | name = AI; 191 | productName = AI; 192 | productReference = 58D609161BF35B0B00464A87 /* AI.framework */; 193 | productType = "com.apple.product-type.framework"; 194 | }; 195 | 58D6091F1BF35B0B00464A87 /* AITests */ = { 196 | isa = PBXNativeTarget; 197 | buildConfigurationList = 58D6092D1BF35B0B00464A87 /* Build configuration list for PBXNativeTarget "AITests" */; 198 | buildPhases = ( 199 | 58D6091C1BF35B0B00464A87 /* Sources */, 200 | 58D6091D1BF35B0B00464A87 /* Frameworks */, 201 | 58D6091E1BF35B0B00464A87 /* Resources */, 202 | ); 203 | buildRules = ( 204 | ); 205 | dependencies = ( 206 | 58D609231BF35B0B00464A87 /* PBXTargetDependency */, 207 | ); 208 | name = AITests; 209 | productName = AITests; 210 | productReference = 58D609201BF35B0B00464A87 /* AITests.xctest */; 211 | productType = "com.apple.product-type.bundle.unit-test"; 212 | }; 213 | /* End PBXNativeTarget section */ 214 | 215 | /* Begin PBXProject section */ 216 | 58D6090D1BF35B0B00464A87 /* Project object */ = { 217 | isa = PBXProject; 218 | attributes = { 219 | LastSwiftUpdateCheck = 0710; 220 | LastUpgradeCheck = 0820; 221 | ORGANIZATIONNAME = "Kuragin Dmitriy"; 222 | TargetAttributes = { 223 | 58D609151BF35B0B00464A87 = { 224 | CreatedOnToolsVersion = 7.1; 225 | LastSwiftMigration = 0820; 226 | }; 227 | 58D6091F1BF35B0B00464A87 = { 228 | CreatedOnToolsVersion = 7.1; 229 | LastSwiftMigration = 0820; 230 | }; 231 | }; 232 | }; 233 | buildConfigurationList = 58D609101BF35B0B00464A87 /* Build configuration list for PBXProject "AI" */; 234 | compatibilityVersion = "Xcode 3.2"; 235 | developmentRegion = English; 236 | hasScannedForEncodings = 0; 237 | knownRegions = ( 238 | en, 239 | ); 240 | mainGroup = 58D6090C1BF35B0B00464A87; 241 | productRefGroup = 58D609171BF35B0B00464A87 /* Products */; 242 | projectDirPath = ""; 243 | projectRoot = ""; 244 | targets = ( 245 | 58D609151BF35B0B00464A87 /* AI */, 246 | 58D6091F1BF35B0B00464A87 /* AITests */, 247 | ); 248 | }; 249 | /* End PBXProject section */ 250 | 251 | /* Begin PBXResourcesBuildPhase section */ 252 | 58D609141BF35B0B00464A87 /* Resources */ = { 253 | isa = PBXResourcesBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | ); 257 | runOnlyForDeploymentPostprocessing = 0; 258 | }; 259 | 58D6091E1BF35B0B00464A87 /* Resources */ = { 260 | isa = PBXResourcesBuildPhase; 261 | buildActionMask = 2147483647; 262 | files = ( 263 | ); 264 | runOnlyForDeploymentPostprocessing = 0; 265 | }; 266 | /* End PBXResourcesBuildPhase section */ 267 | 268 | /* Begin PBXSourcesBuildPhase section */ 269 | 58D609111BF35B0B00464A87 /* Sources */ = { 270 | isa = PBXSourcesBuildPhase; 271 | buildActionMask = 2147483647; 272 | files = ( 273 | 58391DEC1BF5D17700ED0C87 /* QueryRequest.swift in Sources */, 274 | 5846F60B1C919E870067A9B5 /* UserEntitiesRequest.swift in Sources */, 275 | 58D6093E1BF47CBA00464A87 /* CallbacksContainer.swift in Sources */, 276 | 58D609341BF35B1D00464A87 /* Credentials.swift in Sources */, 277 | 58391DF01BF5D25400ED0C87 /* PrivateRequest.swift in Sources */, 278 | 5846F60E1C929B7D0067A9B5 /* SessionStorage.swift in Sources */, 279 | 58D6093C1BF47A9C00464A87 /* QueryResponse.swift in Sources */, 280 | 58D609431BF4865300464A87 /* Completion.swift in Sources */, 281 | 58D609331BF35B1D00464A87 /* AI.swift in Sources */, 282 | 58D609481BF4867500464A87 /* ResponseSerialize.swift in Sources */, 283 | 58D609381BF35C2700464A87 /* Service.swift in Sources */, 284 | 58391DE91BF5D16500ED0C87 /* Request.swift in Sources */, 285 | 58D609441BF4865300464A87 /* JSON.swift in Sources */, 286 | 58391DEA1BF5D16500ED0C87 /* RequestUtilites.swift in Sources */, 287 | 58D609451BF4865300464A87 /* NSError.swift in Sources */, 288 | 58391DEE1BF5D1B000ED0C87 /* TextQueryRequest.swift in Sources */, 289 | ); 290 | runOnlyForDeploymentPostprocessing = 0; 291 | }; 292 | 58D6091C1BF35B0B00464A87 /* Sources */ = { 293 | isa = PBXSourcesBuildPhase; 294 | buildActionMask = 2147483647; 295 | files = ( 296 | 58D609261BF35B0B00464A87 /* AITests.swift in Sources */, 297 | ); 298 | runOnlyForDeploymentPostprocessing = 0; 299 | }; 300 | /* End PBXSourcesBuildPhase section */ 301 | 302 | /* Begin PBXTargetDependency section */ 303 | 58D609231BF35B0B00464A87 /* PBXTargetDependency */ = { 304 | isa = PBXTargetDependency; 305 | target = 58D609151BF35B0B00464A87 /* AI */; 306 | targetProxy = 58D609221BF35B0B00464A87 /* PBXContainerItemProxy */; 307 | }; 308 | /* End PBXTargetDependency section */ 309 | 310 | /* Begin XCBuildConfiguration section */ 311 | 58D609281BF35B0B00464A87 /* Debug */ = { 312 | isa = XCBuildConfiguration; 313 | buildSettings = { 314 | ALWAYS_SEARCH_USER_PATHS = NO; 315 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 316 | CLANG_CXX_LIBRARY = "libc++"; 317 | CLANG_ENABLE_MODULES = YES; 318 | CLANG_ENABLE_OBJC_ARC = YES; 319 | CLANG_WARN_BOOL_CONVERSION = YES; 320 | CLANG_WARN_CONSTANT_CONVERSION = YES; 321 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 322 | CLANG_WARN_EMPTY_BODY = YES; 323 | CLANG_WARN_ENUM_CONVERSION = YES; 324 | CLANG_WARN_INFINITE_RECURSION = YES; 325 | CLANG_WARN_INT_CONVERSION = YES; 326 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 327 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 328 | CLANG_WARN_UNREACHABLE_CODE = YES; 329 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 330 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 331 | COPY_PHASE_STRIP = NO; 332 | CURRENT_PROJECT_VERSION = 1; 333 | DEBUG_INFORMATION_FORMAT = dwarf; 334 | ENABLE_STRICT_OBJC_MSGSEND = YES; 335 | ENABLE_TESTABILITY = YES; 336 | GCC_C_LANGUAGE_STANDARD = gnu99; 337 | GCC_DYNAMIC_NO_PIC = NO; 338 | GCC_NO_COMMON_BLOCKS = YES; 339 | GCC_OPTIMIZATION_LEVEL = 0; 340 | GCC_PREPROCESSOR_DEFINITIONS = ( 341 | "DEBUG=1", 342 | "$(inherited)", 343 | ); 344 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 345 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 346 | GCC_WARN_UNDECLARED_SELECTOR = YES; 347 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 348 | GCC_WARN_UNUSED_FUNCTION = YES; 349 | GCC_WARN_UNUSED_VARIABLE = YES; 350 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 351 | MTL_ENABLE_DEBUG_INFO = YES; 352 | ONLY_ACTIVE_ARCH = YES; 353 | SDKROOT = iphoneos; 354 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 355 | TARGETED_DEVICE_FAMILY = "1,2"; 356 | VERSIONING_SYSTEM = "apple-generic"; 357 | VERSION_INFO_PREFIX = ""; 358 | }; 359 | name = Debug; 360 | }; 361 | 58D609291BF35B0B00464A87 /* Release */ = { 362 | isa = XCBuildConfiguration; 363 | buildSettings = { 364 | ALWAYS_SEARCH_USER_PATHS = NO; 365 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 366 | CLANG_CXX_LIBRARY = "libc++"; 367 | CLANG_ENABLE_MODULES = YES; 368 | CLANG_ENABLE_OBJC_ARC = YES; 369 | CLANG_WARN_BOOL_CONVERSION = YES; 370 | CLANG_WARN_CONSTANT_CONVERSION = YES; 371 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 372 | CLANG_WARN_EMPTY_BODY = YES; 373 | CLANG_WARN_ENUM_CONVERSION = YES; 374 | CLANG_WARN_INFINITE_RECURSION = YES; 375 | CLANG_WARN_INT_CONVERSION = YES; 376 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 377 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 378 | CLANG_WARN_UNREACHABLE_CODE = YES; 379 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 380 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 381 | COPY_PHASE_STRIP = NO; 382 | CURRENT_PROJECT_VERSION = 1; 383 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 384 | ENABLE_NS_ASSERTIONS = NO; 385 | ENABLE_STRICT_OBJC_MSGSEND = YES; 386 | GCC_C_LANGUAGE_STANDARD = gnu99; 387 | GCC_NO_COMMON_BLOCKS = YES; 388 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 389 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 390 | GCC_WARN_UNDECLARED_SELECTOR = YES; 391 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 392 | GCC_WARN_UNUSED_FUNCTION = YES; 393 | GCC_WARN_UNUSED_VARIABLE = YES; 394 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 395 | MTL_ENABLE_DEBUG_INFO = NO; 396 | SDKROOT = iphoneos; 397 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 398 | TARGETED_DEVICE_FAMILY = "1,2"; 399 | VALIDATE_PRODUCT = YES; 400 | VERSIONING_SYSTEM = "apple-generic"; 401 | VERSION_INFO_PREFIX = ""; 402 | }; 403 | name = Release; 404 | }; 405 | 58D6092B1BF35B0B00464A87 /* Debug */ = { 406 | isa = XCBuildConfiguration; 407 | buildSettings = { 408 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 409 | DEFINES_MODULE = YES; 410 | DYLIB_COMPATIBILITY_VERSION = 1; 411 | DYLIB_CURRENT_VERSION = 1; 412 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 413 | INFOPLIST_FILE = AI/Info.plist; 414 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 415 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 416 | PRODUCT_BUNDLE_IDENTIFIER = com.speaktoit.AI; 417 | PRODUCT_NAME = "$(TARGET_NAME)"; 418 | SDKROOT = ""; 419 | SKIP_INSTALL = YES; 420 | SUPPORTED_PLATFORMS = "macosx iphoneos appletvos watchos appletvsimulator iphonesimulator watchsimulator"; 421 | SWIFT_VERSION = 3.0; 422 | TARGETED_DEVICE_FAMILY = "1,2,3,4"; 423 | }; 424 | name = Debug; 425 | }; 426 | 58D6092C1BF35B0B00464A87 /* Release */ = { 427 | isa = XCBuildConfiguration; 428 | buildSettings = { 429 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 430 | DEFINES_MODULE = YES; 431 | DYLIB_COMPATIBILITY_VERSION = 1; 432 | DYLIB_CURRENT_VERSION = 1; 433 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 434 | INFOPLIST_FILE = AI/Info.plist; 435 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 436 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 437 | PRODUCT_BUNDLE_IDENTIFIER = com.speaktoit.AI; 438 | PRODUCT_NAME = "$(TARGET_NAME)"; 439 | SDKROOT = ""; 440 | SKIP_INSTALL = YES; 441 | SUPPORTED_PLATFORMS = "macosx iphoneos appletvos watchos appletvsimulator iphonesimulator watchsimulator"; 442 | SWIFT_VERSION = 3.0; 443 | TARGETED_DEVICE_FAMILY = "1,2,3,4"; 444 | }; 445 | name = Release; 446 | }; 447 | 58D6092E1BF35B0B00464A87 /* Debug */ = { 448 | isa = XCBuildConfiguration; 449 | buildSettings = { 450 | CLANG_ENABLE_MODULES = YES; 451 | INFOPLIST_FILE = AITests/Info.plist; 452 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 453 | PRODUCT_BUNDLE_IDENTIFIER = com.speaktoit.AITests; 454 | PRODUCT_NAME = "$(TARGET_NAME)"; 455 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 456 | SWIFT_VERSION = 3.0; 457 | }; 458 | name = Debug; 459 | }; 460 | 58D6092F1BF35B0B00464A87 /* Release */ = { 461 | isa = XCBuildConfiguration; 462 | buildSettings = { 463 | CLANG_ENABLE_MODULES = YES; 464 | INFOPLIST_FILE = AITests/Info.plist; 465 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 466 | PRODUCT_BUNDLE_IDENTIFIER = com.speaktoit.AITests; 467 | PRODUCT_NAME = "$(TARGET_NAME)"; 468 | SWIFT_VERSION = 3.0; 469 | }; 470 | name = Release; 471 | }; 472 | /* End XCBuildConfiguration section */ 473 | 474 | /* Begin XCConfigurationList section */ 475 | 58D609101BF35B0B00464A87 /* Build configuration list for PBXProject "AI" */ = { 476 | isa = XCConfigurationList; 477 | buildConfigurations = ( 478 | 58D609281BF35B0B00464A87 /* Debug */, 479 | 58D609291BF35B0B00464A87 /* Release */, 480 | ); 481 | defaultConfigurationIsVisible = 0; 482 | defaultConfigurationName = Release; 483 | }; 484 | 58D6092A1BF35B0B00464A87 /* Build configuration list for PBXNativeTarget "AI" */ = { 485 | isa = XCConfigurationList; 486 | buildConfigurations = ( 487 | 58D6092B1BF35B0B00464A87 /* Debug */, 488 | 58D6092C1BF35B0B00464A87 /* Release */, 489 | ); 490 | defaultConfigurationIsVisible = 0; 491 | defaultConfigurationName = Release; 492 | }; 493 | 58D6092D1BF35B0B00464A87 /* Build configuration list for PBXNativeTarget "AITests" */ = { 494 | isa = XCConfigurationList; 495 | buildConfigurations = ( 496 | 58D6092E1BF35B0B00464A87 /* Debug */, 497 | 58D6092F1BF35B0B00464A87 /* Release */, 498 | ); 499 | defaultConfigurationIsVisible = 0; 500 | defaultConfigurationName = Release; 501 | }; 502 | /* End XCConfigurationList section */ 503 | }; 504 | rootObject = 58D6090D1BF35B0B00464A87 /* Project object */; 505 | } 506 | -------------------------------------------------------------------------------- /AI.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AI.xcodeproj/xcshareddata/xcschemes/AI.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /AI/AI.h: -------------------------------------------------------------------------------- 1 | // 2 | // AI.h 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 11/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | //! Project version number for AI. 12 | FOUNDATION_EXPORT double AIVersionNumber; 13 | 14 | //! Project version string for AI. 15 | FOUNDATION_EXPORT const unsigned char AIVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /AI/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 | 0.0.8 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /AI/src/AI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AI.swift 3 | // APII 4 | // 5 | // Created by Kuragin Dmitriy on 11/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct AI { 12 | public static var language: Language = .english 13 | public static var credentials: Credentials? = .none { 14 | didSet { 15 | if let credentials = credentials { 16 | self.sharedService.credentials = credentials 17 | } 18 | } 19 | } 20 | 21 | public static var defaultQueryParameters: QueryParameters = QueryParameters() 22 | public static var session: URLSession = URLSession.shared 23 | 24 | public static func configure(_ credentials: Credentials) { 25 | self.credentials = credentials 26 | } 27 | 28 | public static func configure(_ clientAccessToken: String) { 29 | self.configure(Credentials(clientAccessToken)) 30 | } 31 | 32 | public static func configure(clientAccessToken: String) { 33 | self.configure(clientAccessToken) 34 | } 35 | } 36 | 37 | extension AI { 38 | public static var sharedService: Service = AI.retrieveSharedService() 39 | 40 | fileprivate static func retrieveSharedService() -> Service { 41 | if let credentials = AI.credentials { 42 | return Service(credentials: credentials, session: session, defaultQueryParameters: defaultQueryParameters, language: language) 43 | } else { 44 | fatalError("Library should be configured. Use AI.configure methods.") 45 | } 46 | } 47 | } 48 | 49 | extension AI { 50 | 51 | } 52 | -------------------------------------------------------------------------------- /AI/src/CallbacksContainer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CallbacksContainer.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 12/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class CallbacksContainer { 12 | fileprivate var callbacks: [(T) -> Void] = [] 13 | fileprivate var onResolvecallbacks: [() -> Void] = [] 14 | 15 | fileprivate var state: T? 16 | 17 | func resolve(_ object: T) { 18 | if state == nil { 19 | state = object 20 | 21 | while onResolvecallbacks.count > 0 { 22 | let callback = self.onResolvecallbacks.remove(at: 0) 23 | DispatchQueue.main.async(execute: { () -> Void in 24 | callback() 25 | }) 26 | } 27 | } 28 | 29 | self.fire() 30 | } 31 | 32 | fileprivate func fire() { 33 | while callbacks.count > 0 && state != nil { 34 | let q = self.callbacks.remove(at: 0) 35 | DispatchQueue.main.async(execute: { () -> Void in 36 | q(self.state!) 37 | }) 38 | } 39 | } 40 | 41 | func onResolve(_ fn: @escaping () -> Void) { 42 | onResolvecallbacks.append(fn) 43 | } 44 | 45 | func put(_ fn: @escaping (T) -> Void) { 46 | callbacks.append(fn) 47 | 48 | self.fire() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /AI/src/Completion.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Completion.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 10/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | typealias CompletionError = Error 13 | 14 | enum Completion { 15 | case success(A) 16 | case failure(CompletionError) 17 | } 18 | 19 | extension Completion { 20 | func next(_ f: (A) -> Completion) -> Completion{ 21 | switch self { 22 | case .success(let x): 23 | return f(x) 24 | case .failure(let error): 25 | return .failure(error) 26 | } 27 | } 28 | } 29 | 30 | extension Completion { 31 | func next(_ error: CompletionError?) -> Completion { 32 | switch self { 33 | case .success(let x): 34 | if let error = error { 35 | return .failure(error) 36 | } else { 37 | return .success(x) 38 | } 39 | case .failure(let error): 40 | return .failure(error) 41 | } 42 | } 43 | } 44 | 45 | struct CompletionStringError: Error { 46 | let errorMessage: String 47 | } 48 | -------------------------------------------------------------------------------- /AI/src/Credentials.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Credentials.swift 3 | // APII 4 | // 5 | // Created by Kuragin Dmitriy on 11/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct Credentials { 12 | var clientAccessToken: String 13 | 14 | public init(_ clientAccessToken: String) { 15 | self.clientAccessToken = clientAccessToken 16 | } 17 | 18 | public init(clientAccessToken: String) { 19 | self.clientAccessToken = clientAccessToken 20 | } 21 | } 22 | 23 | private let kAuthorizationHTTPHeaderFieldName = "Authorization" 24 | 25 | internal extension URLRequest { 26 | mutating func authenticate(_ credentials: Credentials) { 27 | self.addValue("Bearer \(credentials.clientAccessToken)", forHTTPHeaderField: kAuthorizationHTTPHeaderFieldName); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /AI/src/JSON.swift: -------------------------------------------------------------------------------- 1 | // 2 | // JSON.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 06/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | typealias JSONAny = AnyObject 12 | typealias JSONObject = [String: AnyObject] 13 | typealias JSONArray = [AnyObject] 14 | typealias JSONString = String 15 | typealias JSONNumber = NSNumber 16 | typealias JSONNull = NSNull 17 | 18 | enum JSON { 19 | case object(JSONObject) 20 | case array(JSONArray) 21 | case number(JSONNumber) 22 | case jString(JSONString) 23 | 24 | case null 25 | case none 26 | 27 | init(_ object: JSONAny?) { 28 | self.init(object: object) 29 | } 30 | 31 | init(object: JSONAny?) { 32 | if let object = object { 33 | switch object { 34 | case let object as JSONObject: 35 | self = .object(object) 36 | case let object as JSONArray: 37 | self = .array(object) 38 | case let object as JSONNumber: 39 | self = .number(object) 40 | case let object as JSONString: 41 | self = .jString(object) 42 | case _ as JSONNull: 43 | self = .null 44 | default: 45 | self = .none 46 | } 47 | } else { 48 | self = .none 49 | } 50 | } 51 | 52 | subscript(index: Int) -> JSON { 53 | get { 54 | if case .array(let array) = self { 55 | if index >= 0 && index < array.count { 56 | return JSON(array[index]) 57 | } 58 | 59 | return .none 60 | } 61 | 62 | return .none 63 | } 64 | } 65 | 66 | subscript(key: String) -> JSON { 67 | get { 68 | if case .object(let object) = self { 69 | return JSON(object[key]) 70 | } 71 | 72 | return .none 73 | } 74 | } 75 | } 76 | 77 | extension JSON { 78 | var string: String? { 79 | if case .jString(let object) = self { 80 | return object 81 | } 82 | 83 | return .none 84 | } 85 | 86 | var int: Int? { 87 | if case .number(let object) = self { 88 | return object.intValue 89 | } 90 | 91 | return .none 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /AI/src/NSError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSError.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 10/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public let AIErrorDomain: String = "AIErrorDomain" 12 | 13 | public enum AIErrorCode: Int { 14 | case unknownError 15 | 16 | case responseSerializeMissingKey 17 | case responseSerializeTypeMismatch 18 | case responseBodyEmpty 19 | 20 | case requestSerializeMissingKey 21 | case requestSerializeTypeMismatch 22 | 23 | case responseObjectEmpty 24 | case responseDataEmpty 25 | case mimeTypeEmpty 26 | case unexpectedMIMEType 27 | case wrongResponseObjectType 28 | 29 | case requestUserCancelled 30 | } 31 | 32 | internal extension NSError { 33 | convenience init(code: AIErrorCode, message: String) { 34 | let userInfo = [ 35 | NSLocalizedDescriptionKey: message 36 | ] 37 | 38 | self.init(domain: AIErrorDomain, code: code.rawValue, userInfo: userInfo) 39 | } 40 | } 41 | 42 | internal extension NSError { 43 | convenience init(forHTTPStatusCode statusCode: Int) { 44 | let userInfo = [ 45 | NSLocalizedDescriptionKey: HTTPURLResponse.localizedString(forStatusCode: statusCode) 46 | ] 47 | 48 | self.init(domain: NSURLErrorDomain, code: statusCode, userInfo: userInfo) 49 | } 50 | } 51 | 52 | internal extension NSError { 53 | convenience init(forErrorString errorString: String) { 54 | self.init(code: AIErrorCode.unknownError, message: errorString) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /AI/src/QueryResponse.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Response.swift 3 | // api 4 | // 5 | // Created by Kuragin Dmitriy on 06/10/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct Message { 12 | public let type: Int 13 | public let speech: String 14 | } 15 | 16 | public struct Fulfillment { 17 | public let speech: String 18 | public let messages: [Message] 19 | } 20 | 21 | public struct Metadata { 22 | public let intentId: String? 23 | public let intentName: String? 24 | } 25 | 26 | public struct Context { 27 | public let name: String 28 | public let parameters: [String: Any] 29 | } 30 | 31 | public struct Result { 32 | public let source: String 33 | public let resolvedQuery: String 34 | public let action: String? 35 | 36 | public let parameters: [String: Any]? 37 | public let contexts: [Context]? 38 | 39 | public let fulfillment: Fulfillment? 40 | public let metadata: Metadata 41 | } 42 | 43 | public struct QueryResponse { 44 | public let identifier: String 45 | public let timestamp: Date 46 | 47 | public let result: Result 48 | } 49 | -------------------------------------------------------------------------------- /AI/src/Requests/PrivateRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PrivateRequest.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 13/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | let kBaseURLString = "https://api.api.ai/v1" 12 | 13 | protocol QueryContainer { 14 | func query() -> String 15 | } 16 | 17 | protocol PrivateRequest: class { 18 | var method: String { get } 19 | var started: Bool { get set } 20 | var dataTask: URLSessionDataTask? { get set } 21 | 22 | var request: URLRequest { get } 23 | 24 | associatedtype ResponseType 25 | var callbacks: CallbacksContainer>? { get set } 26 | 27 | func runRequest() throws -> URLSessionDataTask 28 | 29 | func privateResume(_ completionHandler: @escaping (RequestCompletion) -> Void); 30 | } 31 | 32 | extension PrivateRequest { 33 | func privateResume(_ completionHandler: @escaping (RequestCompletion) -> Void) { 34 | if (!started) { 35 | started = true 36 | 37 | do { 38 | try self.dataTask = self.runRequest() 39 | } catch let error as NSError { 40 | self.callbacks?.resolve(.failure(error)) 41 | } 42 | } 43 | 44 | callbacks?.put(completionHandler) 45 | } 46 | } 47 | 48 | extension PrivateRequest where Self: Request { 49 | var request: URLRequest { 50 | guard let baseURL = URL(string: kBaseURLString) else { 51 | fatalError("Could not get URL from URL string for base URL.") 52 | } 53 | 54 | var request = URLRequest(url: baseURL) 55 | 56 | let components = URLComponents(url: baseURL.appendingPathComponent(self.method), resolvingAgainstBaseURL: false) 57 | if var components = components { 58 | if let queryContainer = self as? QueryContainer { 59 | components.query = queryContainer.query() 60 | } 61 | 62 | request.url = components.url 63 | } 64 | 65 | request.addValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type") 66 | 67 | request.httpMethod = "POST" 68 | 69 | request.authenticate(credentials) 70 | 71 | return request 72 | } 73 | } 74 | 75 | func += (left: inout Dictionary, right: Dictionary) { 76 | for (k, v) in right { 77 | left.updateValue(v, forKey: k) 78 | } 79 | } 80 | 81 | extension PrivateRequest where Self: QueryRequest { 82 | func jsonRequestParameters(_ additionalParameters: [String:AnyObject] = [String:AnyObject]()) throws -> Data { 83 | var parameters = queryParameters.jsonObject() 84 | parameters["lang"] = language.stringValue as AnyObject? 85 | 86 | parameters += additionalParameters 87 | 88 | 89 | let jsonBody = try JSONSerialization.data(withJSONObject: parameters, options: JSONSerialization.WritingOptions(rawValue: 0)) 90 | 91 | return jsonBody 92 | } 93 | } 94 | 95 | extension PrivateRequest where Self: QueryRequest { 96 | func handleQueryResponse(_ data: Data?, _ response: URLResponse?, _ error: Error?) -> RequestCompletion { 97 | let response = handle(data, response, error) 98 | .next(serializeJSON) 99 | .next(validateObject) 100 | .next(serializeObject) 101 | 102 | switch response { 103 | case .success(let object): 104 | return .success(object) 105 | case .failure(let error): 106 | return .failure(error) 107 | } 108 | } 109 | } 110 | 111 | protocol BoundaryContainer { 112 | associatedtype Generator: BoundaryGenerator 113 | var boundary: String { get } 114 | } 115 | 116 | protocol BoundaryGenerator { 117 | static func generate() -> String 118 | } 119 | 120 | class RandomBoundaryGenerator: BoundaryGenerator { 121 | static func generate() -> String { 122 | return String(format: "Boundary+%08X%08X", arc4random(), arc4random()) 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /AI/src/Requests/QueryRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // QueryRequest.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 13/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public enum Language { 12 | case english 13 | case spanish 14 | case russian 15 | case german 16 | case portuguese 17 | case portuguese_Brazil 18 | case french 19 | case italian 20 | case japanese 21 | case korean 22 | case chinese_Simplified 23 | case chinese_HongKong 24 | case chinese_Taiwan 25 | } 26 | 27 | extension Language { 28 | var stringValue: String { 29 | switch self { 30 | case .english: 31 | return "en" 32 | case .spanish: 33 | return "es" 34 | case .russian: 35 | return "ru" 36 | case .german: 37 | return "de" 38 | case .portuguese: 39 | return "pt" 40 | case .portuguese_Brazil: 41 | return "pt-BR" 42 | case .french: 43 | return "fr" 44 | case .italian: 45 | return "it" 46 | case .japanese: 47 | return "ja" 48 | case .korean: 49 | return "ko" 50 | case .chinese_Simplified: 51 | return "zh-CN" 52 | case .chinese_HongKong: 53 | return "zh-HK" 54 | case .chinese_Taiwan: 55 | return "zh-TW" 56 | } 57 | } 58 | } 59 | 60 | public protocol QueryRequest: Request { 61 | associatedtype ResponseType = QueryResponse 62 | 63 | var queryParameters: QueryParameters { get } 64 | var language: Language { get } 65 | } 66 | 67 | extension QueryRequest where Self: QueryContainer { 68 | func query() -> String { 69 | return "v=20150910" 70 | } 71 | } 72 | 73 | public struct Entry { 74 | public var value: String 75 | public var synonyms: [String] 76 | } 77 | 78 | public struct Entity { 79 | public var id: String? = .none 80 | public var name: String 81 | public var entries: [Entry] 82 | } 83 | 84 | public struct QueryParameters { 85 | public var contexts: [Context] = [] 86 | public var resetContexts: Bool = false 87 | public var sessionId: String? = SessionStorage.defaultSessionIdentifier 88 | public var timeZone: TimeZone? = TimeZone.autoupdatingCurrent 89 | public var entities: [Entity] = [] 90 | 91 | public init() {} 92 | } 93 | 94 | extension QueryParameters { 95 | func jsonObject() -> [String: Any] { 96 | var parameters = [String: Any]() 97 | 98 | parameters["contexts"] = contexts.map({ (context) -> [String: Any] in 99 | return ["name": context.name, "parameters": context.parameters] 100 | }) 101 | 102 | parameters["resetContexts"] = resetContexts 103 | 104 | if let sessionId = sessionId { 105 | parameters["sessionId"] = sessionId 106 | } 107 | 108 | if let timeZone = timeZone { 109 | parameters["timezone"] = timeZone.identifier 110 | } 111 | 112 | parameters["entities"] = entities.map({ (entity) -> [String: Any] in 113 | var entityObject = [String: Any]() 114 | 115 | entityObject["name"] = entity.name 116 | entityObject["entries"] = entity.entries.map({ (entry) -> [String:Any] in 117 | ["value": entry.value, "synonyms": entry.synonyms] 118 | }) 119 | 120 | return entityObject 121 | }) 122 | 123 | return parameters 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /AI/src/Requests/Request.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Request.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 11/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public enum RequestCompletion { 12 | case success(T) 13 | case failure(Error) 14 | } 15 | 16 | extension Completion { 17 | func toRequestCompletion() -> RequestCompletion { 18 | switch self { 19 | case .success(let object): 20 | return .success(object) 21 | case .failure(let error): 22 | return .failure(error) 23 | } 24 | } 25 | } 26 | 27 | public protocol Request: class { 28 | var credentials: Credentials { get } 29 | var session: URLSession { get } 30 | 31 | associatedtype ResponseType 32 | 33 | @discardableResult 34 | func resume(completionHandler: @escaping (RequestCompletion) -> Void) -> Self 35 | 36 | func cancel() 37 | } 38 | 39 | public extension Request { 40 | typealias SuccessCompletionHandler = (ResponseType) -> Void 41 | typealias FailureCompletionHandler = (Error) -> Void 42 | 43 | @discardableResult 44 | func success(completionHandler: @escaping SuccessCompletionHandler) -> Self { 45 | return self.resume { (completion) -> Void in 46 | if case .success(let object) = completion { 47 | completionHandler(object) 48 | } 49 | } 50 | } 51 | 52 | @discardableResult 53 | func failure(completionHandler: @escaping FailureCompletionHandler) -> Self { 54 | return self.resume { (completion) -> Void in 55 | if case .failure(let error) = completion { 56 | completionHandler(error) 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /AI/src/Requests/RequestUtilites.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RequestUtilites.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 11/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | func handle(_ data: Data?, _ response: URLResponse?, _ error: Error?) -> Completion { 12 | if let error = error { 13 | return .failure(error) 14 | } 15 | 16 | guard response != .none else { 17 | return .failure(NSError(code: .responseObjectEmpty, message: "NSURLResponse is empty.")) 18 | } 19 | 20 | guard let response = response as? HTTPURLResponse else { 21 | return .failure(NSError(code: .wrongResponseObjectType, message: "Wrong response type. Expected NSHTTPURLResponse.")) 22 | } 23 | 24 | let acceptableStatusCodes = IndexSet(integersIn: NSRange(location: 200, length: 100).toRange() ?? 0..<0) 25 | 26 | if !acceptableStatusCodes.contains(response.statusCode) { 27 | return .failure(NSError(forHTTPStatusCode: response.statusCode)) 28 | } 29 | 30 | guard let mimeType = response.mimeType else { 31 | return .failure(NSError(code: .mimeTypeEmpty, message: "MIMEType connot be empty")) 32 | } 33 | 34 | let acceptableContentTypes = Set(arrayLiteral: "application/json", "text/json", "text/javascript") 35 | 36 | if !acceptableContentTypes.contains(mimeType) { 37 | return .failure(NSError(code: .unexpectedMIMEType, message: "Wrong MIMEType type: \(mimeType). Expected \(acceptableContentTypes)")) 38 | } 39 | 40 | guard let data = data else { 41 | return .failure(NSError(code: .responseDataEmpty, message: "Response data is empty.")) 42 | } 43 | 44 | return .success(data) 45 | } 46 | 47 | func serializeJSON(_ data: Data) -> Completion { 48 | do { 49 | let object = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions(rawValue: 0)) 50 | return .success(object) 51 | } catch let error as NSError { 52 | return .failure(error) 53 | } 54 | } 55 | 56 | func validateObject(_ object: Any) -> Completion<[String: Any]> { 57 | if let object = object as? [String: Any] { 58 | if let code = JSON(object as JSONAny?)["status"]["code"].int { 59 | if code == 200 { 60 | return .success(object) 61 | } else { 62 | return .failure(NSError(forHTTPStatusCode: code)) 63 | } 64 | } else { 65 | return .failure(SerializeError.missingKey("status.code")) 66 | } 67 | } else { 68 | return .failure(SerializeError.typeMismatch("root")) 69 | } 70 | } 71 | 72 | func serializeObject(_ object: [String: Any]) -> Completion { 73 | do { 74 | let response = try ResponseSerializer().serialize(object) 75 | return .success(response) 76 | } catch let error { 77 | return .failure(error) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /AI/src/Requests/TextQueryRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextQueryRequest.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 13/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct TextQueryElement { 12 | public var text: String 13 | public var confidence: Double 14 | } 15 | 16 | public enum TextQueryType { 17 | case one(String) 18 | case array([TextQueryElement]) 19 | } 20 | 21 | public protocol TextQueryRequestType : QueryRequest { 22 | var query: TextQueryType { get } 23 | } 24 | 25 | public class TextQueryRequest: TextQueryRequestType, PrivateRequest, QueryContainer { 26 | internal var started: Bool = false 27 | 28 | //private properties 29 | 30 | weak var callbacks: CallbacksContainer>? = .none 31 | 32 | let method: String = "query" 33 | var dataTask: URLSessionDataTask? = nil 34 | 35 | // public properties 36 | 37 | public typealias ResponseType = QueryResponse 38 | 39 | public let credentials: Credentials 40 | public let session: URLSession 41 | 42 | public var queryParameters: QueryParameters 43 | 44 | public let query: TextQueryType 45 | 46 | public let language: Language 47 | 48 | public init(query: TextQueryType, credentials: Credentials, queryParameters: QueryParameters, session: URLSession, language: Language) { 49 | self.query = query 50 | self.credentials = credentials 51 | self.session = session 52 | self.queryParameters = queryParameters 53 | self.language = language 54 | } 55 | 56 | public convenience init(query: String, credentials: Credentials, queryParameters: QueryParameters, session: URLSession, language: Language) { 57 | self.init(query: .one(query), credentials: credentials, queryParameters: queryParameters, session: session, language: language) 58 | } 59 | 60 | public convenience init(query: [TextQueryElement], credentials: Credentials, queryParameters: QueryParameters, session: URLSession, language: Language) { 61 | self.init(query: .array(query), credentials: credentials, queryParameters: queryParameters, session: session, language: language) 62 | } 63 | 64 | func runRequest() throws -> URLSessionDataTask { 65 | let callbacksContainer = CallbacksContainer>() 66 | 67 | self.callbacks = callbacksContainer 68 | 69 | var request = self.request 70 | 71 | var requestJson: [String:Any] = [:]; 72 | 73 | switch query { 74 | case .one(let text): 75 | requestJson["query"] = text; 76 | case .array(let array): 77 | requestJson["query"] = array.map({ (element) -> String in 78 | return element.text 79 | }) 80 | 81 | requestJson["confidence"] = array.map({ (element) -> Double in 82 | return element.confidence 83 | }) 84 | } 85 | 86 | request.httpBody = try self.jsonRequestParameters(requestJson as [String: AnyObject]) 87 | 88 | let dataTask = self.session.dataTask(with: request) { (data, response, error) in 89 | callbacksContainer.resolve(self.handleQueryResponse(data, response, error)) 90 | } 91 | 92 | dataTask.resume() 93 | 94 | return dataTask 95 | } 96 | 97 | fileprivate func run(_ completionHandler: @escaping (RequestCompletion) -> Void) { 98 | self.privateResume(completionHandler) 99 | } 100 | 101 | @discardableResult 102 | public func resume(completionHandler: @escaping (RequestCompletion) -> Void) -> Self { 103 | // TODO: Replace run-function with the following call. 104 | // (self as TextQueryRequest).privateResume(completionHandler) 105 | self.run(completionHandler) 106 | return self 107 | } 108 | 109 | public func cancel() { 110 | let cancelError = NSError(code: .requestUserCancelled, message: "Request user cancelled.") 111 | 112 | callbacks?.resolve(.failure(cancelError)) 113 | 114 | dataTask?.cancel() 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /AI/src/Requests/UserEntitiesRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UserEntitiesRequest.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 10/03/16. 6 | // Copyright © 2016 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct UserEntityEntry { 12 | public var value: String 13 | public var synonyms: [String] 14 | 15 | public init(value: String, synonyms: [String]) { 16 | self.value = value 17 | self.synonyms = synonyms 18 | } 19 | } 20 | 21 | extension UserEntityEntry { 22 | func jsonObject() -> [String: AnyObject] { 23 | return [ 24 | "value": value as AnyObject, 25 | "synonyms": synonyms as AnyObject 26 | ] 27 | } 28 | } 29 | 30 | public struct UserEntity { 31 | public var sessionId: String? = SessionStorage.defaultSessionIdentifier 32 | public var name: String 33 | public var entries: [UserEntityEntry] 34 | public var extend: Bool = false 35 | 36 | public init(sessionId: String?, name: String, entries: [UserEntityEntry]) { 37 | self.sessionId = sessionId 38 | self.name = name 39 | self.entries = entries 40 | } 41 | 42 | public init(name: String, entries: [UserEntityEntry]) { 43 | self.name = name 44 | self.entries = entries 45 | } 46 | } 47 | 48 | extension UserEntity { 49 | func jsonObject() -> [String: Any] { 50 | var object: [String: Any] = [ 51 | "name": name as Any, 52 | "entries": entries.map { (entry) -> [String: Any] in 53 | entry.jsonObject() 54 | } 55 | ] 56 | 57 | if let sessionId = sessionId { 58 | object["sessionId"] = sessionId 59 | } 60 | 61 | object["extend"] = extend 62 | 63 | return object 64 | } 65 | } 66 | 67 | public struct UserEntitiesResponse { 68 | let code: Int 69 | let errorType: String? 70 | } 71 | 72 | public extension UserEntitiesResponse { 73 | var isSuccess: Bool { 74 | return code == 200 75 | } 76 | } 77 | 78 | public class UserEntitiesRequest: Request, PrivateRequest { 79 | var started: Bool = false 80 | 81 | weak var callbacks: CallbacksContainer>? = .none 82 | 83 | let method: String = "userEntities" 84 | var dataTask: URLSessionDataTask? = nil 85 | 86 | public typealias ResponseType = UserEntitiesResponse 87 | 88 | public let credentials: Credentials 89 | public let session: URLSession 90 | 91 | fileprivate let entities: [UserEntity] 92 | 93 | init(credentials: Credentials, entities: [UserEntity], session: URLSession) { 94 | self.credentials = credentials 95 | self.session = session 96 | self.entities = entities 97 | } 98 | 99 | fileprivate func serializeRequest() throws -> Data { 100 | let requestBody = self.entities.map { (entity) -> [String: Any] in 101 | entity.jsonObject() 102 | } 103 | 104 | return try JSONSerialization.data(withJSONObject: requestBody, options: JSONSerialization.WritingOptions(rawValue: 0)) 105 | } 106 | 107 | func runRequest() throws -> URLSessionDataTask { 108 | let callbacksContainer = CallbacksContainer>() 109 | 110 | self.callbacks = callbacksContainer 111 | 112 | var request = self.request 113 | 114 | request.httpBody = try self.serializeRequest() 115 | 116 | let dataTask = self.session.dataTask(with: request, completionHandler: { (data, response, error) -> Void in 117 | let response = handle(data, response, error).next(serializeJSON).next(validateObject).next(userEntitiesResponseSerialize) 118 | 119 | switch response { 120 | case .success(let object): 121 | callbacksContainer.resolve(.success(object)) 122 | case .failure(let error): 123 | callbacksContainer.resolve(.failure(error)) 124 | } 125 | }) 126 | 127 | dataTask.resume() 128 | 129 | return dataTask 130 | } 131 | 132 | fileprivate func run(_ completionHandler: @escaping (RequestCompletion) -> Void) { 133 | self.privateResume(completionHandler) 134 | } 135 | 136 | @discardableResult 137 | public func resume(completionHandler: @escaping (RequestCompletion) -> Void) -> Self { 138 | // TODO: Replace run-function with the following call. 139 | // (self as TextQueryRequest).privateResume(completionHandler) 140 | self.run(completionHandler) 141 | return self 142 | } 143 | 144 | public func cancel() { 145 | let cancelError = NSError(code: .requestUserCancelled, message: "Request user cancelled.") 146 | 147 | callbacks?.resolve(.failure(cancelError)) 148 | 149 | dataTask?.cancel() 150 | } 151 | } 152 | 153 | func userEntitiesResponseSerialize(_ object: [String: Any]) -> Completion { 154 | guard let statusObject = object["status"] else { 155 | return .failure(SerializeError.missingKey("status")) 156 | } 157 | 158 | guard let status = statusObject as? [String: AnyObject] else { 159 | return .failure(SerializeError.typeMismatch("status")) 160 | } 161 | 162 | guard let code = status["code"] as? Int else { 163 | return .failure(SerializeError.missingKey("code")) 164 | } 165 | 166 | guard let errorType = status["errorType"] as? String else { 167 | return .failure(SerializeError.missingKey("errorType")) 168 | } 169 | 170 | return .success(UserEntitiesResponse(code: code, errorType: errorType)) 171 | } 172 | -------------------------------------------------------------------------------- /AI/src/Requests/Utils/SessionStorage.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SessionStorage.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 11/03/16. 6 | // Copyright © 2016 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | fileprivate let kSessionIdentifierStoreKey = "kSessionIdentifierStoreKey" 12 | 13 | public struct SessionStorage { 14 | public static var defaultSessionIdentifier: String = SessionStorage.retrieveDefaultSessionIdentifier() 15 | 16 | fileprivate static func retrieveDefaultSessionIdentifier() -> String { 17 | let userDefaults = UserDefaults.standard 18 | 19 | if let storedSessionIdentifier = userDefaults.object(forKey: kSessionIdentifierStoreKey) as? String { 20 | return storedSessionIdentifier 21 | } else { 22 | let generatedSessionIdentifier = NSUUID().uuidString 23 | 24 | userDefaults.set(generatedSessionIdentifier, forKey: kSessionIdentifierStoreKey) 25 | userDefaults.synchronize() 26 | 27 | return generatedSessionIdentifier 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AI/src/ResponseSerialize.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ResponseMapping.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 10/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum SerializeError { 12 | case missingKey(String) 13 | case typeMismatch(String) 14 | } 15 | 16 | extension SerializeError: Error {} 17 | 18 | protocol Serializer { 19 | associatedtype Source = [String: Any] 20 | associatedtype Destination 21 | 22 | func serialize(_ source: Source) throws -> Destination 23 | } 24 | 25 | func objectForKey(_ key: String, dict: [String: Any], ignoreMissingKey: Bool = false) throws -> T { 26 | // TODO: The ignoreMissingKey is never used; remove if it's redundant. 27 | if let object = dict[key] { 28 | if let object = object as? T { 29 | return object 30 | } else { 31 | throw SerializeError.typeMismatch(key) 32 | } 33 | } else { 34 | throw SerializeError.missingKey(key) 35 | } 36 | } 37 | 38 | func objectForKeyOrNull(_ key: String, dict: [String: Any]) -> T? { 39 | if let object = dict[key] { 40 | if let object = object as? T { 41 | return object 42 | } else { 43 | return .none 44 | } 45 | } else { 46 | return .none 47 | } 48 | } 49 | 50 | struct MessageSerializer: Serializer { 51 | typealias Destination = Message 52 | 53 | func serialize(_ source: Dictionary) throws -> Message { 54 | let type: Int = try objectForKey("type", dict: source) 55 | let speech: String = try objectForKey("speech", dict: source) 56 | 57 | return Message(type: type, speech: speech) 58 | } 59 | } 60 | 61 | struct FulfillmentSerializer: Serializer { 62 | typealias Destination = Fulfillment 63 | 64 | func serialize(_ source: FulfillmentSerializer.Source) throws -> FulfillmentSerializer.Destination { 65 | let speech: String = try objectForKey("speech", dict: source) 66 | 67 | let messageSerializer = MessageSerializer() 68 | 69 | let sourceMessages: [[String:Any]] = objectForKeyOrNull("messages", dict: source) ?? [] 70 | 71 | let messages = try sourceMessages.map { (sourceMessage) -> Message in 72 | return try messageSerializer.serialize(sourceMessage) 73 | } 74 | 75 | return Destination(speech: speech, messages: messages) 76 | } 77 | } 78 | 79 | struct MetadataSerializer: Serializer { 80 | typealias Destination = Metadata 81 | 82 | func serialize(_ source: MetadataSerializer.Source) throws -> MetadataSerializer.Destination { 83 | let intentId: String? = objectForKeyOrNull("intentId", dict: source) 84 | let intentName: String? = objectForKeyOrNull("intentName", dict: source) 85 | 86 | return Destination(intentId: intentId, intentName: intentName) 87 | } 88 | } 89 | 90 | struct ContextSerializer: Serializer { 91 | typealias Destination = Context 92 | 93 | func serialize(_ source: ContextSerializer.Source) throws -> ContextSerializer.Destination { 94 | let name: String = try objectForKey("name", dict: source) 95 | let parameters: [String:Any] = try objectForKey("parameters", dict: source) 96 | 97 | return Destination(name: name, parameters: parameters) 98 | } 99 | } 100 | 101 | struct ResultSerializer: Serializer { 102 | typealias Destination = Result 103 | 104 | func serialize(_ source: ResultSerializer.Source) throws -> ResultSerializer.Destination { 105 | let sourceResult: String = try objectForKey("source", dict: source) 106 | let resolvedQuery: String = try objectForKey("resolvedQuery", dict: source) 107 | let action: String? = objectForKeyOrNull("action", dict: source) 108 | 109 | let parameters: [String:Any]? = try? objectForKey("parameters", dict: source) 110 | 111 | let contextsArray: [[String:Any]]? = try? objectForKey("contexts", dict: source) 112 | let contextSerializer = ContextSerializer() 113 | 114 | let contexts = try contextsArray.map { (object) -> [Context] in 115 | try object.map({ (object) -> Context in 116 | try contextSerializer.serialize(object) 117 | }) 118 | } 119 | 120 | let fulfillmentObject: [String:Any]? = try? objectForKey("fulfillment", dict: source) 121 | 122 | let fulfillment = try fulfillmentObject.map({ (obj) -> Fulfillment in 123 | try FulfillmentSerializer().serialize(obj) 124 | }) 125 | 126 | let metadata = try MetadataSerializer().serialize(try objectForKey("metadata", dict: source)) 127 | 128 | return Destination( 129 | source: sourceResult, 130 | resolvedQuery: resolvedQuery, 131 | action: action, 132 | parameters: parameters, 133 | contexts: contexts, 134 | fulfillment: fulfillment, 135 | metadata: metadata 136 | ) 137 | } 138 | } 139 | 140 | struct ResponseSerializer: Serializer { 141 | typealias Destination = QueryResponse 142 | 143 | func serialize(_ source: ResponseSerializer.Source) throws -> ResponseSerializer.Destination { 144 | let identifier: String = try objectForKey("id", dict: source) 145 | 146 | let dateFormatter = DateFormatter() 147 | dateFormatter.locale = Locale(identifier: "en_US") 148 | dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" 149 | 150 | guard let timestamp: Date = dateFormatter.date(from: try objectForKey("timestamp", dict: source)) else { 151 | throw SerializeError.typeMismatch("timestamp") 152 | } 153 | 154 | let result = try ResultSerializer().serialize(try objectForKey("result", dict: source)) 155 | 156 | return Destination( 157 | identifier: identifier, 158 | timestamp: timestamp, 159 | result: result 160 | ) 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /AI/src/Service.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Service.swift 3 | // AI 4 | // 5 | // Created by Kuragin Dmitriy on 11/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public protocol BaseService { 12 | var credentials: Credentials { get } 13 | var session: URLSession { get } 14 | } 15 | 16 | public protocol QueryService: BaseService { 17 | var defaultQueryParameters: QueryParameters { get set } 18 | var language: Language { get } 19 | } 20 | 21 | public extension QueryService { 22 | func textRequest(_ query: TextQueryType) -> TextQueryRequest { 23 | return TextQueryRequest(query: query, credentials: credentials, queryParameters: defaultQueryParameters, session: session, language: language) 24 | } 25 | 26 | func textRequest(_ query: String) -> TextQueryRequest { 27 | return textRequest(.one(query)) 28 | } 29 | 30 | func textRequest(_ query: [TextQueryElement]) -> TextQueryRequest { 31 | return textRequest(.array(query)) 32 | } 33 | } 34 | 35 | public protocol UserEntitiesService: BaseService { 36 | 37 | } 38 | 39 | public extension UserEntitiesService { 40 | func userEntitiesUploadRequest(_ entities: [UserEntity]) -> UserEntitiesRequest { 41 | return UserEntitiesRequest(credentials: credentials, entities: entities, session: session) 42 | } 43 | } 44 | 45 | public class Service: BaseService, QueryService, UserEntitiesService { 46 | public var credentials: Credentials 47 | public var session: URLSession 48 | 49 | public let language: Language 50 | 51 | public var defaultQueryParameters: QueryParameters 52 | 53 | init(credentials: Credentials, session: URLSession, defaultQueryParameters: QueryParameters, language: Language) { 54 | self.session = session 55 | self.credentials = credentials 56 | 57 | self.defaultQueryParameters = defaultQueryParameters 58 | 59 | self.language = language 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /AIDemo/AIDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 581409EF1C843D340014BBE8 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 581409EE1C843D340014BBE8 /* AVFoundation.framework */; }; 11 | 58D1E4B31BFC6BB400D257AA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D1E4B21BFC6BB400D257AA /* AppDelegate.swift */; }; 12 | 58D1E4B81BFC6BB400D257AA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 58D1E4B61BFC6BB400D257AA /* Main.storyboard */; }; 13 | 58D1E4BA1BFC6BB400D257AA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 58D1E4B91BFC6BB400D257AA /* Assets.xcassets */; }; 14 | 58D1E4BD1BFC6BB400D257AA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 58D1E4BB1BFC6BB400D257AA /* LaunchScreen.storyboard */; }; 15 | 58D1E4C61BFC6D7200D257AA /* TextRequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D1E4C51BFC6D7200D257AA /* TextRequestViewController.swift */; }; 16 | 58D1E4C91BFC6E0100D257AA /* ResultViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D1E4C81BFC6E0100D257AA /* ResultViewController.swift */; }; 17 | EF171C8443E8B5AA44FA5594 /* Pods_AIDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34D2689E82A65A36E929393F /* Pods_AIDemo.framework */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 214B739D944FBA0038FC493D /* Pods-AIDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AIDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AIDemo/Pods-AIDemo.debug.xcconfig"; sourceTree = ""; }; 22 | 34D2689E82A65A36E929393F /* Pods_AIDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AIDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 581409EE1C843D340014BBE8 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 24 | 58D1E4AF1BFC6BB400D257AA /* AIDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AIDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 25 | 58D1E4B21BFC6BB400D257AA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 26 | 58D1E4B71BFC6BB400D257AA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | 58D1E4B91BFC6BB400D257AA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 58D1E4BC1BFC6BB400D257AA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 58D1E4BE1BFC6BB400D257AA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 58D1E4C51BFC6D7200D257AA /* TextRequestViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextRequestViewController.swift; sourceTree = ""; }; 31 | 58D1E4C81BFC6E0100D257AA /* ResultViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultViewController.swift; sourceTree = ""; }; 32 | F182421779ABBD2542C80E0C /* Pods-AIDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AIDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-AIDemo/Pods-AIDemo.release.xcconfig"; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 58D1E4AC1BFC6BB400D257AA /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | 581409EF1C843D340014BBE8 /* AVFoundation.framework in Frameworks */, 41 | EF171C8443E8B5AA44FA5594 /* Pods_AIDemo.framework in Frameworks */, 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 58D1E4A61BFC6BB400D257AA = { 49 | isa = PBXGroup; 50 | children = ( 51 | 58D1E4B11BFC6BB400D257AA /* AIDemo */, 52 | 58D1E4B01BFC6BB400D257AA /* Products */, 53 | 7797100665D99C1A89DA2062 /* Pods */, 54 | F6538459F510446765E5D455 /* Frameworks */, 55 | ); 56 | sourceTree = ""; 57 | }; 58 | 58D1E4B01BFC6BB400D257AA /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 58D1E4AF1BFC6BB400D257AA /* AIDemo.app */, 62 | ); 63 | name = Products; 64 | sourceTree = ""; 65 | }; 66 | 58D1E4B11BFC6BB400D257AA /* AIDemo */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 58D1E4C41BFC6D6600D257AA /* TextRequest */, 70 | 58D1E4C71BFC6DF000D257AA /* Result */, 71 | 58D1E4B21BFC6BB400D257AA /* AppDelegate.swift */, 72 | 58D1E4B61BFC6BB400D257AA /* Main.storyboard */, 73 | 58D1E4B91BFC6BB400D257AA /* Assets.xcassets */, 74 | 58D1E4BB1BFC6BB400D257AA /* LaunchScreen.storyboard */, 75 | 58D1E4BE1BFC6BB400D257AA /* Info.plist */, 76 | ); 77 | path = AIDemo; 78 | sourceTree = ""; 79 | }; 80 | 58D1E4C41BFC6D6600D257AA /* TextRequest */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 58D1E4C51BFC6D7200D257AA /* TextRequestViewController.swift */, 84 | ); 85 | path = TextRequest; 86 | sourceTree = ""; 87 | }; 88 | 58D1E4C71BFC6DF000D257AA /* Result */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 58D1E4C81BFC6E0100D257AA /* ResultViewController.swift */, 92 | ); 93 | path = Result; 94 | sourceTree = ""; 95 | }; 96 | 7797100665D99C1A89DA2062 /* Pods */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | 214B739D944FBA0038FC493D /* Pods-AIDemo.debug.xcconfig */, 100 | F182421779ABBD2542C80E0C /* Pods-AIDemo.release.xcconfig */, 101 | ); 102 | name = Pods; 103 | sourceTree = ""; 104 | }; 105 | F6538459F510446765E5D455 /* Frameworks */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 581409EE1C843D340014BBE8 /* AVFoundation.framework */, 109 | 34D2689E82A65A36E929393F /* Pods_AIDemo.framework */, 110 | ); 111 | name = Frameworks; 112 | sourceTree = ""; 113 | }; 114 | /* End PBXGroup section */ 115 | 116 | /* Begin PBXNativeTarget section */ 117 | 58D1E4AE1BFC6BB400D257AA /* AIDemo */ = { 118 | isa = PBXNativeTarget; 119 | buildConfigurationList = 58D1E4C11BFC6BB400D257AA /* Build configuration list for PBXNativeTarget "AIDemo" */; 120 | buildPhases = ( 121 | 2BEF95B8FF07C320FB0DC103 /* [CP] Check Pods Manifest.lock */, 122 | 58D1E4AB1BFC6BB400D257AA /* Sources */, 123 | 58D1E4AC1BFC6BB400D257AA /* Frameworks */, 124 | 58D1E4AD1BFC6BB400D257AA /* Resources */, 125 | A937B83877837E2C3D229AC0 /* [CP] Embed Pods Frameworks */, 126 | 398F0DB78AD428D6AEA2AC37 /* [CP] Copy Pods Resources */, 127 | ); 128 | buildRules = ( 129 | ); 130 | dependencies = ( 131 | ); 132 | name = AIDemo; 133 | productName = AIDemo; 134 | productReference = 58D1E4AF1BFC6BB400D257AA /* AIDemo.app */; 135 | productType = "com.apple.product-type.application"; 136 | }; 137 | /* End PBXNativeTarget section */ 138 | 139 | /* Begin PBXProject section */ 140 | 58D1E4A71BFC6BB400D257AA /* Project object */ = { 141 | isa = PBXProject; 142 | attributes = { 143 | LastSwiftUpdateCheck = 0710; 144 | LastUpgradeCheck = 0820; 145 | ORGANIZATIONNAME = "Kuragin Dmitriy"; 146 | TargetAttributes = { 147 | 58D1E4AE1BFC6BB400D257AA = { 148 | CreatedOnToolsVersion = 7.1.1; 149 | LastSwiftMigration = 0820; 150 | }; 151 | }; 152 | }; 153 | buildConfigurationList = 58D1E4AA1BFC6BB400D257AA /* Build configuration list for PBXProject "AIDemo" */; 154 | compatibilityVersion = "Xcode 3.2"; 155 | developmentRegion = English; 156 | hasScannedForEncodings = 0; 157 | knownRegions = ( 158 | en, 159 | Base, 160 | ); 161 | mainGroup = 58D1E4A61BFC6BB400D257AA; 162 | productRefGroup = 58D1E4B01BFC6BB400D257AA /* Products */; 163 | projectDirPath = ""; 164 | projectRoot = ""; 165 | targets = ( 166 | 58D1E4AE1BFC6BB400D257AA /* AIDemo */, 167 | ); 168 | }; 169 | /* End PBXProject section */ 170 | 171 | /* Begin PBXResourcesBuildPhase section */ 172 | 58D1E4AD1BFC6BB400D257AA /* Resources */ = { 173 | isa = PBXResourcesBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | 58D1E4BD1BFC6BB400D257AA /* LaunchScreen.storyboard in Resources */, 177 | 58D1E4BA1BFC6BB400D257AA /* Assets.xcassets in Resources */, 178 | 58D1E4B81BFC6BB400D257AA /* Main.storyboard in Resources */, 179 | ); 180 | runOnlyForDeploymentPostprocessing = 0; 181 | }; 182 | /* End PBXResourcesBuildPhase section */ 183 | 184 | /* Begin PBXShellScriptBuildPhase section */ 185 | 2BEF95B8FF07C320FB0DC103 /* [CP] Check Pods Manifest.lock */ = { 186 | isa = PBXShellScriptBuildPhase; 187 | buildActionMask = 2147483647; 188 | files = ( 189 | ); 190 | inputPaths = ( 191 | ); 192 | name = "[CP] Check Pods Manifest.lock"; 193 | outputPaths = ( 194 | ); 195 | runOnlyForDeploymentPostprocessing = 0; 196 | shellPath = /bin/sh; 197 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; 198 | showEnvVarsInLog = 0; 199 | }; 200 | 398F0DB78AD428D6AEA2AC37 /* [CP] Copy Pods Resources */ = { 201 | isa = PBXShellScriptBuildPhase; 202 | buildActionMask = 2147483647; 203 | files = ( 204 | ); 205 | inputPaths = ( 206 | ); 207 | name = "[CP] Copy Pods Resources"; 208 | outputPaths = ( 209 | ); 210 | runOnlyForDeploymentPostprocessing = 0; 211 | shellPath = /bin/sh; 212 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AIDemo/Pods-AIDemo-resources.sh\"\n"; 213 | showEnvVarsInLog = 0; 214 | }; 215 | A937B83877837E2C3D229AC0 /* [CP] Embed Pods Frameworks */ = { 216 | isa = PBXShellScriptBuildPhase; 217 | buildActionMask = 2147483647; 218 | files = ( 219 | ); 220 | inputPaths = ( 221 | ); 222 | name = "[CP] Embed Pods Frameworks"; 223 | outputPaths = ( 224 | ); 225 | runOnlyForDeploymentPostprocessing = 0; 226 | shellPath = /bin/sh; 227 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AIDemo/Pods-AIDemo-frameworks.sh\"\n"; 228 | showEnvVarsInLog = 0; 229 | }; 230 | /* End PBXShellScriptBuildPhase section */ 231 | 232 | /* Begin PBXSourcesBuildPhase section */ 233 | 58D1E4AB1BFC6BB400D257AA /* Sources */ = { 234 | isa = PBXSourcesBuildPhase; 235 | buildActionMask = 2147483647; 236 | files = ( 237 | 58D1E4C61BFC6D7200D257AA /* TextRequestViewController.swift in Sources */, 238 | 58D1E4B31BFC6BB400D257AA /* AppDelegate.swift in Sources */, 239 | 58D1E4C91BFC6E0100D257AA /* ResultViewController.swift in Sources */, 240 | ); 241 | runOnlyForDeploymentPostprocessing = 0; 242 | }; 243 | /* End PBXSourcesBuildPhase section */ 244 | 245 | /* Begin PBXVariantGroup section */ 246 | 58D1E4B61BFC6BB400D257AA /* Main.storyboard */ = { 247 | isa = PBXVariantGroup; 248 | children = ( 249 | 58D1E4B71BFC6BB400D257AA /* Base */, 250 | ); 251 | name = Main.storyboard; 252 | sourceTree = ""; 253 | }; 254 | 58D1E4BB1BFC6BB400D257AA /* LaunchScreen.storyboard */ = { 255 | isa = PBXVariantGroup; 256 | children = ( 257 | 58D1E4BC1BFC6BB400D257AA /* Base */, 258 | ); 259 | name = LaunchScreen.storyboard; 260 | sourceTree = ""; 261 | }; 262 | /* End PBXVariantGroup section */ 263 | 264 | /* Begin XCBuildConfiguration section */ 265 | 58D1E4BF1BFC6BB400D257AA /* Debug */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | ALWAYS_SEARCH_USER_PATHS = NO; 269 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 270 | CLANG_CXX_LIBRARY = "libc++"; 271 | CLANG_ENABLE_MODULES = YES; 272 | CLANG_ENABLE_OBJC_ARC = YES; 273 | CLANG_WARN_BOOL_CONVERSION = YES; 274 | CLANG_WARN_CONSTANT_CONVERSION = YES; 275 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 276 | CLANG_WARN_EMPTY_BODY = YES; 277 | CLANG_WARN_ENUM_CONVERSION = YES; 278 | CLANG_WARN_INFINITE_RECURSION = YES; 279 | CLANG_WARN_INT_CONVERSION = YES; 280 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 281 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 282 | CLANG_WARN_UNREACHABLE_CODE = YES; 283 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 284 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 285 | COPY_PHASE_STRIP = NO; 286 | DEBUG_INFORMATION_FORMAT = dwarf; 287 | ENABLE_STRICT_OBJC_MSGSEND = YES; 288 | ENABLE_TESTABILITY = YES; 289 | GCC_C_LANGUAGE_STANDARD = gnu99; 290 | GCC_DYNAMIC_NO_PIC = NO; 291 | GCC_NO_COMMON_BLOCKS = YES; 292 | GCC_OPTIMIZATION_LEVEL = 0; 293 | GCC_PREPROCESSOR_DEFINITIONS = ( 294 | "DEBUG=1", 295 | "$(inherited)", 296 | ); 297 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 298 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 299 | GCC_WARN_UNDECLARED_SELECTOR = YES; 300 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 301 | GCC_WARN_UNUSED_FUNCTION = YES; 302 | GCC_WARN_UNUSED_VARIABLE = YES; 303 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 304 | MTL_ENABLE_DEBUG_INFO = YES; 305 | ONLY_ACTIVE_ARCH = YES; 306 | SDKROOT = iphoneos; 307 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 308 | }; 309 | name = Debug; 310 | }; 311 | 58D1E4C01BFC6BB400D257AA /* Release */ = { 312 | isa = XCBuildConfiguration; 313 | buildSettings = { 314 | ALWAYS_SEARCH_USER_PATHS = NO; 315 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 316 | CLANG_CXX_LIBRARY = "libc++"; 317 | CLANG_ENABLE_MODULES = YES; 318 | CLANG_ENABLE_OBJC_ARC = YES; 319 | CLANG_WARN_BOOL_CONVERSION = YES; 320 | CLANG_WARN_CONSTANT_CONVERSION = YES; 321 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 322 | CLANG_WARN_EMPTY_BODY = YES; 323 | CLANG_WARN_ENUM_CONVERSION = YES; 324 | CLANG_WARN_INFINITE_RECURSION = YES; 325 | CLANG_WARN_INT_CONVERSION = YES; 326 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 327 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 328 | CLANG_WARN_UNREACHABLE_CODE = YES; 329 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 330 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 331 | COPY_PHASE_STRIP = NO; 332 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 333 | ENABLE_NS_ASSERTIONS = NO; 334 | ENABLE_STRICT_OBJC_MSGSEND = YES; 335 | GCC_C_LANGUAGE_STANDARD = gnu99; 336 | GCC_NO_COMMON_BLOCKS = YES; 337 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 338 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 339 | GCC_WARN_UNDECLARED_SELECTOR = YES; 340 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 341 | GCC_WARN_UNUSED_FUNCTION = YES; 342 | GCC_WARN_UNUSED_VARIABLE = YES; 343 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 344 | MTL_ENABLE_DEBUG_INFO = NO; 345 | SDKROOT = iphoneos; 346 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 347 | VALIDATE_PRODUCT = YES; 348 | }; 349 | name = Release; 350 | }; 351 | 58D1E4C21BFC6BB400D257AA /* Debug */ = { 352 | isa = XCBuildConfiguration; 353 | baseConfigurationReference = 214B739D944FBA0038FC493D /* Pods-AIDemo.debug.xcconfig */; 354 | buildSettings = { 355 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 356 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 357 | INFOPLIST_FILE = AIDemo/Info.plist; 358 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 359 | PRODUCT_BUNDLE_IDENTIFIER = com.speaktoit.AIDemo; 360 | PRODUCT_NAME = "$(TARGET_NAME)"; 361 | SWIFT_VERSION = 3.0; 362 | }; 363 | name = Debug; 364 | }; 365 | 58D1E4C31BFC6BB400D257AA /* Release */ = { 366 | isa = XCBuildConfiguration; 367 | baseConfigurationReference = F182421779ABBD2542C80E0C /* Pods-AIDemo.release.xcconfig */; 368 | buildSettings = { 369 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 370 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 371 | INFOPLIST_FILE = AIDemo/Info.plist; 372 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 373 | PRODUCT_BUNDLE_IDENTIFIER = com.speaktoit.AIDemo; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | SWIFT_VERSION = 3.0; 376 | }; 377 | name = Release; 378 | }; 379 | /* End XCBuildConfiguration section */ 380 | 381 | /* Begin XCConfigurationList section */ 382 | 58D1E4AA1BFC6BB400D257AA /* Build configuration list for PBXProject "AIDemo" */ = { 383 | isa = XCConfigurationList; 384 | buildConfigurations = ( 385 | 58D1E4BF1BFC6BB400D257AA /* Debug */, 386 | 58D1E4C01BFC6BB400D257AA /* Release */, 387 | ); 388 | defaultConfigurationIsVisible = 0; 389 | defaultConfigurationName = Release; 390 | }; 391 | 58D1E4C11BFC6BB400D257AA /* Build configuration list for PBXNativeTarget "AIDemo" */ = { 392 | isa = XCConfigurationList; 393 | buildConfigurations = ( 394 | 58D1E4C21BFC6BB400D257AA /* Debug */, 395 | 58D1E4C31BFC6BB400D257AA /* Release */, 396 | ); 397 | defaultConfigurationIsVisible = 0; 398 | defaultConfigurationName = Release; 399 | }; 400 | /* End XCConfigurationList section */ 401 | }; 402 | rootObject = 58D1E4A71BFC6BB400D257AA /* Project object */; 403 | } 404 | -------------------------------------------------------------------------------- /AIDemo/AIDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AIDemo/AIDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AIDemo 4 | // 5 | // Created by Kuragin Dmitriy on 18/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AVFoundation 11 | import AI 12 | 13 | @UIApplicationMain 14 | class AppDelegate: UIResponder, UIApplicationDelegate { 15 | 16 | var window: UIWindow? 17 | 18 | 19 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 20 | AI.configure("YOUR_CLIENT_ACCESS_TOKEN") 21 | 22 | let session = AVAudioSession.sharedInstance() 23 | 24 | do { 25 | try session.setCategory(AVAudioSessionCategoryPlayAndRecord, with: [.allowBluetooth]) 26 | try session.setActive(true) 27 | } catch { 28 | // handle error 29 | } 30 | 31 | return true 32 | } 33 | 34 | func applicationWillResignActive(_ application: UIApplication) { 35 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 36 | // 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. 37 | } 38 | 39 | func applicationDidEnterBackground(_ application: UIApplication) { 40 | // 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. 41 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 42 | } 43 | 44 | func applicationWillEnterForeground(_ application: UIApplication) { 45 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 46 | } 47 | 48 | func applicationDidBecomeActive(_ application: UIApplication) { 49 | // 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. 50 | } 51 | 52 | func applicationWillTerminate(_ application: UIApplication) { 53 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 54 | } 55 | 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /AIDemo/AIDemo/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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /AIDemo/AIDemo/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 | -------------------------------------------------------------------------------- /AIDemo/AIDemo/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 | 32 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /AIDemo/AIDemo/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 | 40 | 41 | -------------------------------------------------------------------------------- /AIDemo/AIDemo/Result/ResultViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ResultViewController.swift 3 | // AIDemo 4 | // 5 | // Created by Kuragin Dmitriy on 18/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AI 11 | 12 | class ResultViewController: UIViewController { 13 | var result: QueryResponse! 14 | 15 | @IBOutlet weak var textView: UITextView! 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | 20 | textView.text = "\(result)" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /AIDemo/AIDemo/TextRequest/TextRequestViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextRequestViewController.swift 3 | // AIDemo 4 | // 5 | // Created by Kuragin Dmitriy on 18/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AI 11 | 12 | class TextRequestViewController: UIViewController { 13 | @IBOutlet weak var textField: UITextField! 14 | 15 | fileprivate var response: QueryResponse? = .none 16 | 17 | @IBAction func send(_ sender: AnyObject) { 18 | AI.sharedService.textRequest(textField.text ?? "").success {[weak self] (response) -> Void in 19 | self?.response = response 20 | DispatchQueue.main.async { [weak self] in 21 | if let sself = self { 22 | sself.performSegue(withIdentifier: "ShowResult", sender: sself) 23 | } 24 | } 25 | }.failure { (error) -> Void in 26 | DispatchQueue.main.async { 27 | let alert = UIAlertController( 28 | title: "Error", 29 | message: error.localizedDescription, 30 | preferredStyle: .alert 31 | ) 32 | 33 | alert.addAction( 34 | UIAlertAction( 35 | title: "Cancel", 36 | style: .cancel, 37 | handler: .none 38 | ) 39 | ) 40 | 41 | self.present( 42 | alert, 43 | animated: true, 44 | completion: .none 45 | ) 46 | } 47 | } 48 | } 49 | 50 | override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { 51 | if let _ = response { 52 | return true 53 | } 54 | 55 | return false 56 | } 57 | 58 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 59 | if segue.identifier == "ShowResult" { 60 | let resultViewController = segue.destination as! ResultViewController 61 | resultViewController.result = response! 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /AIDemo/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | platform :ios, '8.0' 3 | 4 | # Uncomment this line if you're using Swift 5 | use_frameworks! 6 | 7 | target 'AIDemo' do 8 | 9 | pod "AI" #, :path => "../" 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /AIOSXDemo/AIOSXDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 814FCDEDB2AB39641B204B86 /* Pods_AIOSXDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2DA2F26F1FF3989B924EEA38 /* Pods_AIOSXDemo.framework */; }; 11 | CE5E742B1C1A79E400890183 /* TextRequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5E742A1C1A79E400890183 /* TextRequestViewController.swift */; }; 12 | CEABF95C1C1990AB004BCF62 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEABF95B1C1990AB004BCF62 /* AppDelegate.swift */; }; 13 | CEABF95E1C1990AB004BCF62 /* LandingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEABF95D1C1990AB004BCF62 /* LandingViewController.swift */; }; 14 | CEABF9601C1990AB004BCF62 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CEABF95F1C1990AB004BCF62 /* Assets.xcassets */; }; 15 | CEABF9631C1990AC004BCF62 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CEABF9611C1990AC004BCF62 /* Main.storyboard */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 2DA2F26F1FF3989B924EEA38 /* Pods_AIOSXDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AIOSXDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 3C7D49D1CB9FB37E0F633D82 /* Pods-AIOSXDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AIOSXDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-AIOSXDemo/Pods-AIOSXDemo.release.xcconfig"; sourceTree = ""; }; 21 | 7739E50E38EF7232DAB45666 /* Pods-AIOSXDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AIOSXDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AIOSXDemo/Pods-AIOSXDemo.debug.xcconfig"; sourceTree = ""; }; 22 | CE5E742A1C1A79E400890183 /* TextRequestViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextRequestViewController.swift; sourceTree = ""; }; 23 | CEABF9581C1990AB004BCF62 /* AIOSXDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AIOSXDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | CEABF95B1C1990AB004BCF62 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 25 | CEABF95D1C1990AB004BCF62 /* LandingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LandingViewController.swift; sourceTree = ""; }; 26 | CEABF95F1C1990AB004BCF62 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 27 | CEABF9621C1990AC004BCF62 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 28 | CEABF9641C1990AC004BCF62 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | CEABF9551C1990AB004BCF62 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | 814FCDEDB2AB39641B204B86 /* Pods_AIOSXDemo.framework in Frameworks */, 37 | ); 38 | runOnlyForDeploymentPostprocessing = 0; 39 | }; 40 | /* End PBXFrameworksBuildPhase section */ 41 | 42 | /* Begin PBXGroup section */ 43 | 7C63D67ACA7DBAC4A42F4D49 /* Pods */ = { 44 | isa = PBXGroup; 45 | children = ( 46 | 7739E50E38EF7232DAB45666 /* Pods-AIOSXDemo.debug.xcconfig */, 47 | 3C7D49D1CB9FB37E0F633D82 /* Pods-AIOSXDemo.release.xcconfig */, 48 | ); 49 | name = Pods; 50 | sourceTree = ""; 51 | }; 52 | C34C831AFCFE22B65A72910C /* Frameworks */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | 2DA2F26F1FF3989B924EEA38 /* Pods_AIOSXDemo.framework */, 56 | ); 57 | name = Frameworks; 58 | sourceTree = ""; 59 | }; 60 | CEABF94F1C1990AB004BCF62 = { 61 | isa = PBXGroup; 62 | children = ( 63 | CEABF95A1C1990AB004BCF62 /* AIOSXDemo */, 64 | CEABF9591C1990AB004BCF62 /* Products */, 65 | 7C63D67ACA7DBAC4A42F4D49 /* Pods */, 66 | C34C831AFCFE22B65A72910C /* Frameworks */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | CEABF9591C1990AB004BCF62 /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | CEABF9581C1990AB004BCF62 /* AIOSXDemo.app */, 74 | ); 75 | name = Products; 76 | sourceTree = ""; 77 | }; 78 | CEABF95A1C1990AB004BCF62 /* AIOSXDemo */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | CEABF95B1C1990AB004BCF62 /* AppDelegate.swift */, 82 | CEABF95D1C1990AB004BCF62 /* LandingViewController.swift */, 83 | CE5E742A1C1A79E400890183 /* TextRequestViewController.swift */, 84 | CEABF95F1C1990AB004BCF62 /* Assets.xcassets */, 85 | CEABF9641C1990AC004BCF62 /* Info.plist */, 86 | CEABF9611C1990AC004BCF62 /* Main.storyboard */, 87 | ); 88 | path = AIOSXDemo; 89 | sourceTree = ""; 90 | }; 91 | /* End PBXGroup section */ 92 | 93 | /* Begin PBXNativeTarget section */ 94 | CEABF9571C1990AB004BCF62 /* AIOSXDemo */ = { 95 | isa = PBXNativeTarget; 96 | buildConfigurationList = CEABF97D1C1990AC004BCF62 /* Build configuration list for PBXNativeTarget "AIOSXDemo" */; 97 | buildPhases = ( 98 | 31EB21B9F098C6B3ACFBDC26 /* [CP] Check Pods Manifest.lock */, 99 | CEABF9541C1990AB004BCF62 /* Sources */, 100 | CEABF9551C1990AB004BCF62 /* Frameworks */, 101 | CEABF9561C1990AB004BCF62 /* Resources */, 102 | 901F1021474427752AC8EA20 /* [CP] Embed Pods Frameworks */, 103 | 96703AD7B15DAAE83FA78C40 /* [CP] Copy Pods Resources */, 104 | ); 105 | buildRules = ( 106 | ); 107 | dependencies = ( 108 | ); 109 | name = AIOSXDemo; 110 | productName = AIOSXDemo; 111 | productReference = CEABF9581C1990AB004BCF62 /* AIOSXDemo.app */; 112 | productType = "com.apple.product-type.application"; 113 | }; 114 | /* End PBXNativeTarget section */ 115 | 116 | /* Begin PBXProject section */ 117 | CEABF9501C1990AB004BCF62 /* Project object */ = { 118 | isa = PBXProject; 119 | attributes = { 120 | LastSwiftUpdateCheck = 0720; 121 | LastUpgradeCheck = 0820; 122 | ORGANIZATIONNAME = Api.ai; 123 | TargetAttributes = { 124 | CEABF9571C1990AB004BCF62 = { 125 | CreatedOnToolsVersion = 7.2; 126 | LastSwiftMigration = 0820; 127 | }; 128 | }; 129 | }; 130 | buildConfigurationList = CEABF9531C1990AB004BCF62 /* Build configuration list for PBXProject "AIOSXDemo" */; 131 | compatibilityVersion = "Xcode 3.2"; 132 | developmentRegion = English; 133 | hasScannedForEncodings = 0; 134 | knownRegions = ( 135 | en, 136 | Base, 137 | ); 138 | mainGroup = CEABF94F1C1990AB004BCF62; 139 | productRefGroup = CEABF9591C1990AB004BCF62 /* Products */; 140 | projectDirPath = ""; 141 | projectRoot = ""; 142 | targets = ( 143 | CEABF9571C1990AB004BCF62 /* AIOSXDemo */, 144 | ); 145 | }; 146 | /* End PBXProject section */ 147 | 148 | /* Begin PBXResourcesBuildPhase section */ 149 | CEABF9561C1990AB004BCF62 /* Resources */ = { 150 | isa = PBXResourcesBuildPhase; 151 | buildActionMask = 2147483647; 152 | files = ( 153 | CEABF9601C1990AB004BCF62 /* Assets.xcassets in Resources */, 154 | CEABF9631C1990AC004BCF62 /* Main.storyboard in Resources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXResourcesBuildPhase section */ 159 | 160 | /* Begin PBXShellScriptBuildPhase section */ 161 | 31EB21B9F098C6B3ACFBDC26 /* [CP] Check Pods Manifest.lock */ = { 162 | isa = PBXShellScriptBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | ); 166 | inputPaths = ( 167 | ); 168 | name = "[CP] Check Pods Manifest.lock"; 169 | outputPaths = ( 170 | ); 171 | runOnlyForDeploymentPostprocessing = 0; 172 | shellPath = /bin/sh; 173 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; 174 | showEnvVarsInLog = 0; 175 | }; 176 | 901F1021474427752AC8EA20 /* [CP] Embed Pods Frameworks */ = { 177 | isa = PBXShellScriptBuildPhase; 178 | buildActionMask = 2147483647; 179 | files = ( 180 | ); 181 | inputPaths = ( 182 | ); 183 | name = "[CP] Embed Pods Frameworks"; 184 | outputPaths = ( 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | shellPath = /bin/sh; 188 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AIOSXDemo/Pods-AIOSXDemo-frameworks.sh\"\n"; 189 | showEnvVarsInLog = 0; 190 | }; 191 | 96703AD7B15DAAE83FA78C40 /* [CP] Copy Pods Resources */ = { 192 | isa = PBXShellScriptBuildPhase; 193 | buildActionMask = 2147483647; 194 | files = ( 195 | ); 196 | inputPaths = ( 197 | ); 198 | name = "[CP] Copy Pods Resources"; 199 | outputPaths = ( 200 | ); 201 | runOnlyForDeploymentPostprocessing = 0; 202 | shellPath = /bin/sh; 203 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AIOSXDemo/Pods-AIOSXDemo-resources.sh\"\n"; 204 | showEnvVarsInLog = 0; 205 | }; 206 | /* End PBXShellScriptBuildPhase section */ 207 | 208 | /* Begin PBXSourcesBuildPhase section */ 209 | CEABF9541C1990AB004BCF62 /* Sources */ = { 210 | isa = PBXSourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | CE5E742B1C1A79E400890183 /* TextRequestViewController.swift in Sources */, 214 | CEABF95E1C1990AB004BCF62 /* LandingViewController.swift in Sources */, 215 | CEABF95C1C1990AB004BCF62 /* AppDelegate.swift in Sources */, 216 | ); 217 | runOnlyForDeploymentPostprocessing = 0; 218 | }; 219 | /* End PBXSourcesBuildPhase section */ 220 | 221 | /* Begin PBXVariantGroup section */ 222 | CEABF9611C1990AC004BCF62 /* Main.storyboard */ = { 223 | isa = PBXVariantGroup; 224 | children = ( 225 | CEABF9621C1990AC004BCF62 /* Base */, 226 | ); 227 | name = Main.storyboard; 228 | sourceTree = ""; 229 | }; 230 | /* End PBXVariantGroup section */ 231 | 232 | /* Begin XCBuildConfiguration section */ 233 | CEABF97B1C1990AC004BCF62 /* Debug */ = { 234 | isa = XCBuildConfiguration; 235 | buildSettings = { 236 | ALWAYS_SEARCH_USER_PATHS = NO; 237 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 238 | CLANG_CXX_LIBRARY = "libc++"; 239 | CLANG_ENABLE_MODULES = YES; 240 | CLANG_ENABLE_OBJC_ARC = YES; 241 | CLANG_WARN_BOOL_CONVERSION = YES; 242 | CLANG_WARN_CONSTANT_CONVERSION = YES; 243 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 244 | CLANG_WARN_EMPTY_BODY = YES; 245 | CLANG_WARN_ENUM_CONVERSION = YES; 246 | CLANG_WARN_INFINITE_RECURSION = YES; 247 | CLANG_WARN_INT_CONVERSION = YES; 248 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 249 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 250 | CLANG_WARN_UNREACHABLE_CODE = YES; 251 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 252 | CODE_SIGN_IDENTITY = "-"; 253 | COPY_PHASE_STRIP = NO; 254 | DEBUG_INFORMATION_FORMAT = dwarf; 255 | ENABLE_STRICT_OBJC_MSGSEND = YES; 256 | ENABLE_TESTABILITY = YES; 257 | GCC_C_LANGUAGE_STANDARD = gnu99; 258 | GCC_DYNAMIC_NO_PIC = NO; 259 | GCC_NO_COMMON_BLOCKS = YES; 260 | GCC_OPTIMIZATION_LEVEL = 0; 261 | GCC_PREPROCESSOR_DEFINITIONS = ( 262 | "DEBUG=1", 263 | "$(inherited)", 264 | ); 265 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 266 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 267 | GCC_WARN_UNDECLARED_SELECTOR = YES; 268 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 269 | GCC_WARN_UNUSED_FUNCTION = YES; 270 | GCC_WARN_UNUSED_VARIABLE = YES; 271 | MACOSX_DEPLOYMENT_TARGET = 10.11; 272 | MTL_ENABLE_DEBUG_INFO = YES; 273 | ONLY_ACTIVE_ARCH = YES; 274 | SDKROOT = macosx; 275 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 276 | }; 277 | name = Debug; 278 | }; 279 | CEABF97C1C1990AC004BCF62 /* Release */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ALWAYS_SEARCH_USER_PATHS = NO; 283 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 284 | CLANG_CXX_LIBRARY = "libc++"; 285 | CLANG_ENABLE_MODULES = YES; 286 | CLANG_ENABLE_OBJC_ARC = YES; 287 | CLANG_WARN_BOOL_CONVERSION = YES; 288 | CLANG_WARN_CONSTANT_CONVERSION = YES; 289 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 290 | CLANG_WARN_EMPTY_BODY = YES; 291 | CLANG_WARN_ENUM_CONVERSION = YES; 292 | CLANG_WARN_INFINITE_RECURSION = YES; 293 | CLANG_WARN_INT_CONVERSION = YES; 294 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 295 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 296 | CLANG_WARN_UNREACHABLE_CODE = YES; 297 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 298 | CODE_SIGN_IDENTITY = "-"; 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 | MACOSX_DEPLOYMENT_TARGET = 10.11; 312 | MTL_ENABLE_DEBUG_INFO = NO; 313 | SDKROOT = macosx; 314 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 315 | }; 316 | name = Release; 317 | }; 318 | CEABF97E1C1990AC004BCF62 /* Debug */ = { 319 | isa = XCBuildConfiguration; 320 | baseConfigurationReference = 7739E50E38EF7232DAB45666 /* Pods-AIOSXDemo.debug.xcconfig */; 321 | buildSettings = { 322 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 323 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 324 | COMBINE_HIDPI_IMAGES = YES; 325 | INFOPLIST_FILE = AIOSXDemo/Info.plist; 326 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 327 | PRODUCT_BUNDLE_IDENTIFIER = com.api.ai.AIOSXDemo; 328 | PRODUCT_NAME = "$(TARGET_NAME)"; 329 | SWIFT_VERSION = 3.0; 330 | }; 331 | name = Debug; 332 | }; 333 | CEABF97F1C1990AC004BCF62 /* Release */ = { 334 | isa = XCBuildConfiguration; 335 | baseConfigurationReference = 3C7D49D1CB9FB37E0F633D82 /* Pods-AIOSXDemo.release.xcconfig */; 336 | buildSettings = { 337 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 338 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 339 | COMBINE_HIDPI_IMAGES = YES; 340 | INFOPLIST_FILE = AIOSXDemo/Info.plist; 341 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 342 | PRODUCT_BUNDLE_IDENTIFIER = com.api.ai.AIOSXDemo; 343 | PRODUCT_NAME = "$(TARGET_NAME)"; 344 | SWIFT_VERSION = 3.0; 345 | }; 346 | name = Release; 347 | }; 348 | /* End XCBuildConfiguration section */ 349 | 350 | /* Begin XCConfigurationList section */ 351 | CEABF9531C1990AB004BCF62 /* Build configuration list for PBXProject "AIOSXDemo" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | CEABF97B1C1990AC004BCF62 /* Debug */, 355 | CEABF97C1C1990AC004BCF62 /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | defaultConfigurationName = Release; 359 | }; 360 | CEABF97D1C1990AC004BCF62 /* Build configuration list for PBXNativeTarget "AIOSXDemo" */ = { 361 | isa = XCConfigurationList; 362 | buildConfigurations = ( 363 | CEABF97E1C1990AC004BCF62 /* Debug */, 364 | CEABF97F1C1990AC004BCF62 /* Release */, 365 | ); 366 | defaultConfigurationIsVisible = 0; 367 | defaultConfigurationName = Release; 368 | }; 369 | /* End XCConfigurationList section */ 370 | }; 371 | rootObject = CEABF9501C1990AB004BCF62 /* Project object */; 372 | } 373 | -------------------------------------------------------------------------------- /AIOSXDemo/AIOSXDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AIOSXDemo 4 | // 5 | 6 | import AI 7 | import Cocoa 8 | 9 | @NSApplicationMain 10 | class AppDelegate: NSObject, NSApplicationDelegate { 11 | 12 | func applicationDidFinishLaunching(_ aNotification: Notification) { 13 | AI.configure("YOUR_CLIENT_ACCESS_TOKEN") 14 | } 15 | 16 | func applicationWillTerminate(_ aNotification: Notification) { 17 | // Insert code here to tear down your application 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /AIOSXDemo/AIOSXDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /AIOSXDemo/AIOSXDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | $(MACOSX_DEPLOYMENT_TARGET) 27 | NSHumanReadableCopyright 28 | Copyright © 2015 Api.ai. All rights reserved. 29 | NSMainStoryboardFile 30 | Main 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /AIOSXDemo/AIOSXDemo/LandingViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LandingViewController.swift 3 | // AIOSXDemo 4 | // 5 | 6 | import Cocoa 7 | 8 | class LandingViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { 9 | 10 | // NSTableViewDataSource implementation 11 | 12 | func numberOfRows(in tableView: NSTableView) -> Int { 13 | return Details.TableView.numberOfRows 14 | } 15 | 16 | func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { 17 | let identifier = Details.TableView.viewIdentifierForTableRow(row) 18 | guard let cellView = tableView.make(withIdentifier: identifier, owner: self) as? NSTableCellView else { 19 | return nil 20 | } 21 | 22 | return cellView 23 | } 24 | 25 | func tableViewSelectionDidChange(_ notification: Notification) { 26 | guard let tableView = notification.object as? NSTableView else { 27 | return 28 | } 29 | 30 | let selectedRow = tableView.selectedRow 31 | let segueIdentifier = Details.segueIdentifierForTableRow(selectedRow) 32 | 33 | self.performSegue(withIdentifier: segueIdentifier, sender: self) 34 | tableView.deselectRow(selectedRow) 35 | } 36 | 37 | // Details 38 | 39 | fileprivate struct Details { 40 | 41 | struct TableView { 42 | static func viewIdentifierForTableRow(_ row: Int) -> String { 43 | return "TableCellView\(row)" 44 | } 45 | 46 | static let numberOfRows: Int = 2 47 | } 48 | 49 | static func segueIdentifierForTableRow(_ row: Int) -> String { 50 | return "Segue\(row)" 51 | } 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /AIOSXDemo/AIOSXDemo/TextRequestViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextRequestViewController.swift 3 | // AIOSXDemo 4 | // 5 | 6 | import AI 7 | import Cocoa 8 | 9 | class TextRequestViewController: NSViewController { 10 | 11 | @IBOutlet weak var inputTextField: NSTextField! 12 | @IBOutlet weak var outputTextField: NSTextField! 13 | 14 | @IBOutlet weak var sendButton: NSButton! 15 | 16 | @IBOutlet weak var progressIndicator: NSProgressIndicator! 17 | 18 | @IBAction func userDidTouchSendButton(_ sender: NSButton) { 19 | self.outputTextField.stringValue = "" 20 | 21 | let query = self.inputTextField.stringValue 22 | let request = AI.sharedService.textRequest(query) 23 | request.success { [weak self] (response) in 24 | DispatchQueue.main.async { 25 | self?.outputTextField.stringValue = "\(response)" 26 | } 27 | }.failure { (error) in 28 | DispatchQueue.main.async { 29 | let alert = NSAlert(error: error) 30 | alert.addButton(withTitle: "Cancel") 31 | alert.alertStyle = NSAlertStyle.warning 32 | 33 | alert.runModal() 34 | } 35 | }.resume { [weak self] (_) in 36 | if let sself = self { 37 | sself.progressIndicator.stopAnimation(self) 38 | 39 | sself.sendButton.isEnabled = true 40 | sself.inputTextField.isEnabled = true 41 | } 42 | } 43 | 44 | self.progressIndicator.startAnimation(self) 45 | 46 | self.sendButton.isEnabled = false 47 | self.inputTextField.isEnabled = false 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /AIOSXDemo/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | platform :osx, '10.9' 3 | 4 | # Uncomment this line if you're using Swift 5 | use_frameworks! 6 | 7 | target 'AIOSXDemo' do 8 | 9 | pod "AI" #, :path => "../" 10 | 11 | end 12 | -------------------------------------------------------------------------------- /AITests/AITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AITests.swift 3 | // AITests 4 | // 5 | // Created by Kuragin Dmitriy on 11/11/15. 6 | // Copyright © 2015 Kuragin Dmitriy. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import AVFoundation 11 | @testable import AI 12 | 13 | class AITests: XCTestCase { 14 | 15 | lazy var ai = AI.sharedService 16 | 17 | override func setUp() { 18 | super.setUp() 19 | 20 | AI.configure("09604c7f91ce4cd8a4ede55eb5340b9d") 21 | } 22 | 23 | func testUserEntities() { 24 | let expectationUploadUserEntities = self.expectation(description: "Expect upload user entities.") 25 | 26 | let entities = [ 27 | UserEntity(name: "Application", entries: [ 28 | UserEntityEntry(value: "Firefox", synonyms: ["Firefox"]), 29 | UserEntityEntry(value: "XCode", synonyms: ["XCode"]), 30 | UserEntityEntry(value: "Sublime Text", synonyms: ["Sublime Text"]) 31 | ]) 32 | ] 33 | 34 | ai.userEntitiesUploadRequest(entities).success { (response) in 35 | expectationUploadUserEntities.fulfill() 36 | }.failure { (error) in 37 | XCTAssert(false, "Some error while uploading user entities. Detailed: \(error)") 38 | expectationUploadUserEntities.fulfill() 39 | } 40 | 41 | self.waitForExpectations(timeout: 30.0) { (error) in 42 | XCTAssertNil(error, "Some error while uploading user entities.") 43 | } 44 | 45 | let expectationQueryRequest = self.expectation(description: "Expect query request.") 46 | 47 | let query = "Open application XCode" 48 | 49 | ai.textRequest(query).success { (response) in 50 | let result = response.result 51 | 52 | XCTAssertEqual(result.resolvedQuery.lowercased(), query.lowercased(), "resolvedQuery should be equal query.") 53 | XCTAssertNotNil(result.action, "expecting nonnull action.") 54 | XCTAssertEqual(result.action!, "open_application", "expecting action 'open_application'.") 55 | 56 | XCTAssertNotNil(result.parameters, "expecting nonnull parameters.") 57 | let parameters = result.parameters! 58 | 59 | XCTAssertNotNil(parameters["application"] as? String, "expecting parameter 'application'.") 60 | XCTAssertEqual(parameters["application"] as! String, "XCode", "Unexpected parameter value.") 61 | 62 | expectationQueryRequest.fulfill() 63 | }.failure { (error) in 64 | XCTAssert(false, "Some error while sending query requests. Detailed: \(error)") 65 | expectationQueryRequest.fulfill() 66 | } 67 | 68 | self.waitForExpectations(timeout: 30.0) { (error) in 69 | XCTAssertNil(error, "Some error while sending query request.") 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /AITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED Cocoa SDK for api.ai 2 | 3 | ## This library is deprecated. Please use [API.AI's Apple Client library](https://github.com/api-ai/apiai-apple-client) 4 | 5 | [![Build Status](https://travis-ci.org/api-ai/api-ai-ios-sdk.svg?branch=master)](https://travis-ci.org/api-ai/api-ai-cocoa-swift) 6 | [![Version](https://img.shields.io/cocoapods/v/AI.svg?style=flat)](http://cocoapods.org/pods/AI) 7 | [![License](https://img.shields.io/cocoapods/l/AI.svg?style=flat)](http://cocoapods.org/pods/AI) 8 | [![Platform](https://img.shields.io/cocoapods/p/AI.svg?style=flat)](http://cocoapods.org/pods/AI) 9 | [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 10 | 11 | * [Overview](#overview) 12 | * [Prerequisites](#prerequisites) 13 | * [Running the Demo app](#runningthedemoapp) 14 | * [Integrating api.ai into your Cocoa app](#integratingintoyourapp) 15 | 16 | --------------- 17 | 18 | ## Overview 19 | The API.AI iOS SDK makes it easy to integrate natural language processing API on Apple devices. API.AI allows using voice commands and integration with dialog scenarios defined for a particular agent in API.AI. 20 | 21 | ## Prerequsites 22 | * Create an [API.AI account](http://api.ai) 23 | * Install [CocoaPods](#cocoapods) or [Carthage](#carthage) 24 | 25 | 26 | ## Running the Demo app (CocoaPods supports only) 27 | * Run ```pod update``` in the AIDemo project folder. 28 | * Open **AIDemo.xworkspace** in Xcode. 29 | * In **AppDelegate** insert API key. 30 | ``` 31 | AI.configure("YOUR_CLIENT_ACCESS_TOKEN") 32 | ``` 33 | 34 | Note: an agent in **api.ai** should exist. Keys could be obtained on the agent's settings page. 35 | 36 | * Define sample intents in the agent. 37 | * Run the app in Xcode. 38 | Inputs are possible with text and voice (experimental). 39 | 40 | 41 | ## Integrating into your app 42 | 43 | ### CocoaPods 44 | 45 | [CocoaPods](http://cocoapods.org) is a dependency manager for Swift and Objective-C Cocoa projects. Installing: 46 | 47 | ```bash 48 | $ [sudo] gem install cocoapods 49 | ``` 50 | 51 | List "AI" in a text file named `Podfile` in your Xcode project directory: 52 | 53 | ```ruby 54 | source 'https://github.com/CocoaPods/Specs.git' 55 | platform :ios, '10.0' 56 | use_frameworks! 57 | 58 | target '' do 59 | pod 'AI', '~> 0.7' 60 | end 61 | ``` 62 | 63 | Now you can install the dependencies in your project: 64 | 65 | ```bash 66 | $ pod install 67 | ``` 68 | 69 | ### Carthage 70 | 71 | [Carthage](https://github.com/Carthage/Carthage) is intended to be the simplest way to add frameworks to your Cocoa application. 72 | 73 | You can use [Homebrew](http://brew.sh) and install the `carthage` tool on your system simply by running `brew update` and `brew install carthage`. 74 | 75 | Create a `Cartfile` with following text: 76 | ``` 77 | github "api-ai/AI" 78 | ``` 79 | 80 | Run `carthage update`. 81 | Drag the built `AI.framework` into your Xcode project. 82 | 83 | ### Init the SDK. 84 | 85 | In the ```AppDelegate.swift```, add AI import: 86 | ```Swift 87 | import AI 88 | ``` 89 | 90 | In the AppDelegate.swift, add 91 | 92 | ```Swift 93 | // Define API.AI configuration here. 94 | AI.configure("YOUR_CLIENT_ACCESS_TOKEN") 95 | ``` 96 | 97 | ### Perform request. 98 | 99 | ```Swift 100 | ... 101 | // Request using text (assumes that speech recognition / ASR 102 | // is done using a third-party library, e.g. AT&T) 103 | AI.sharedService.TextRequest("Hello").success { (response) -> Void in 104 | // Handle success ... 105 | }.failure { (error) -> Void in 106 | // Handle error ... 107 | } 108 | ``` 109 | --------------------------------------------------------------------------------