Compare commits

..

No commits in common. "master" and "1.1" have entirely different histories.
master ... 1.1

49 changed files with 543 additions and 1368 deletions

View File

@ -1,33 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
---
<!--
## Is it really a bug?
Before opening an issue, check the following:
1. You are using the **SITE** key
2. The correct domain, with protocol, is setup.
3. You are using an **Invisible** reCAPTCHA v2 key.
4. If the widget doesn't appear, that is expected since the library will try to resolve the challenge _invisibly_.
https://www.google.com/recaptcha/admin#site
-->
## Bug description
A clear and concise description of what the bug is.
## To Reproduce
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '...'
3. ...
4. Profit (jk See error)
## Expected behavior
A clear and concise description of what you expected to happen.
## Logs
Please add as many logs as you feel necessary. Be mindful of your application and remove any sensitive data.
## Additional context
Add any other context about the problem here.

3
.gitignore vendored
View File

@ -51,6 +51,3 @@ fastlane/Preview.html
fastlane/screenshots fastlane/screenshots
fastlane/README.md fastlane/README.md
fastlane/test_output fastlane/test_output
## VS Code
.vscode

View File

@ -1,14 +0,0 @@
author: Flávio Caetano (@fjcaetano)
author_url: https://github.com/fjcaetano
github_url: https://github.com/fjcaetano/ReCaptcha
readme: README.md
module: ReCaptcha
xcodebuild_arguments:
- -workspace
- Example/ReCaptcha.xcworkspace
- -scheme
- ReCaptcha-Example
- -configuration
- Release

1
.swift-version Normal file
View File

@ -0,0 +1 @@
4.0

View File

@ -44,5 +44,5 @@ file_header:
\/\/ ReCaptcha \/\/ ReCaptcha
\/\/ \/\/
\/\/ Created by .*? on \d{1,2}\/\d{1,2}\/\d{2}\. \/\/ Created by .*? on \d{1,2}\/\d{1,2}\/\d{2}\.
\/\/ Copyright © 2018 ReCaptcha\. All rights reserved\. \/\/ Copyright © \d{4} ReCaptcha\. All rights reserved\.
\/\/ \/\/

View File

@ -1,4 +1,4 @@
osx_image: xcode10 osx_image: xcode9
language: objective-c language: objective-c
cache: cache:

View File

@ -1,38 +1,3 @@
# 1.4.2
- Fix: Webview's resource loading detection (#56 #60)
# 1.4.1
- Fix RxSwift dependency version (#58)
# 1.4
- Feature: Support Swift 4.2
- Feature: enable validation to be skipped for testing
# 1.3.1
- Fix: Removing leftover print
- Fix: Removing Result dependency from Carthage
# 1.3
- Feature: Locale support (#39)
- Fix: Reset not flagging ReCaptha as ready-to-execute (#36)
- Fix: Multiple configure calls after app being idle (#40)
# 1.2
- Feature: Resettable ReCaptchas. (#23)
- Feature: Forcing visible challenge on DEBUG. (#19)
- Fix: Better encapsulation architecture.
- Fix: Retiring Result dependency. (#24)
- Fix: `validate` completion closure being called consecutively. (#29)
- Fix: `configureWebView` being called multiple times. (#31)
# 1.1 # 1.1
- Fix: better logging for when protocol isn't found on - Fix: better logging for when protocol isn't found on

View File

@ -1 +1,2 @@
binary "https://raw.github.com/TouchInstinct/CarthageBinaries/master/RxSwift/RxSwift.json" github "antitypical/Result" ~> 3.0
github "ReactiveX/RxSwift" ~> 4.0

View File

@ -1 +1,2 @@
binary "https://raw.github.com/TouchInstinct/CarthageBinaries/master/RxSwift/RxSwift.json" "4.5.0" github "ReactiveX/RxSwift" "4.0.0"
github "antitypical/Result" "3.2.4"

View File

@ -5,14 +5,13 @@ inhibit_all_warnings!
target 'ReCaptcha_Example' do target 'ReCaptcha_Example' do
pod 'ReCaptcha/RxSwift', :path => '../' pod 'ReCaptcha/RxSwift', :path => '../'
pod 'RxCocoa', '~> 4.3' pod 'RxCocoa', '~> 4.0'
pod 'SwiftLint', '~> 0.27' pod 'SwiftLint', '~> 0.24'
target 'ReCaptcha_Tests' do target 'ReCaptcha_Tests' do
inherit! :search_paths inherit! :search_paths
pod 'AppSwizzle', '~> 1.3' pod 'AppSwizzle', :git => 'https://github.com/fjcaetano/AppSwizzle.git', :branch => 'swift4'
pod 'RxBlocking', '~> 4.0'
end end
target 'ReCaptcha_UITests' do target 'ReCaptcha_UITests' do

View File

@ -1,48 +1,42 @@
PODS: PODS:
- AppSwizzle (1.3.1) - AppSwizzle (1.2)
- ReCaptcha/Core (1.4.1) - ReCaptcha/Core (1.0.2):
- ReCaptcha/RxSwift (1.4.1): - Result (~> 3.0)
- ReCaptcha/RxSwift (1.0.2):
- ReCaptcha/Core - ReCaptcha/Core
- RxSwift (~> 4.3)
- RxAtomic (4.4.0)
- RxBlocking (4.4.0):
- RxAtomic (~> 4.4)
- RxSwift (~> 4.0) - RxSwift (~> 4.0)
- RxCocoa (4.4.0): - Result (3.2.4)
- RxCocoa (4.1.1):
- RxSwift (~> 4.0) - RxSwift (~> 4.0)
- RxSwift (4.4.0): - RxSwift (4.1.1)
- RxAtomic (~> 4.4) - SwiftLint (0.24.1)
- SwiftLint (0.27.0)
DEPENDENCIES: DEPENDENCIES:
- AppSwizzle (~> 1.3) - AppSwizzle (from `https://github.com/fjcaetano/AppSwizzle.git`, branch `swift4`)
- ReCaptcha/RxSwift (from `../`) - ReCaptcha/RxSwift (from `../`)
- RxBlocking (~> 4.0) - RxCocoa (~> 4.0)
- RxCocoa (~> 4.3) - SwiftLint (~> 0.24)
- SwiftLint (~> 0.27)
SPEC REPOS:
https://github.com/cocoapods/specs.git:
- AppSwizzle
- RxAtomic
- RxBlocking
- RxCocoa
- RxSwift
- SwiftLint
EXTERNAL SOURCES: EXTERNAL SOURCES:
AppSwizzle:
:branch: swift4
:git: https://github.com/fjcaetano/AppSwizzle.git
ReCaptcha: ReCaptcha:
:path: "../" :path: ../
CHECKOUT OPTIONS:
AppSwizzle:
:commit: c432a73e43779d20ef8e8a589aabd9622b7b6a5d
:git: https://github.com/fjcaetano/AppSwizzle.git
SPEC CHECKSUMS: SPEC CHECKSUMS:
AppSwizzle: db36e436f56110d93e5ae0147683435df593cabc AppSwizzle: bbd3782652fc426ce59c045a92ec61d36f261984
ReCaptcha: 520a707a38dfbb1e5de812aa3c041df60bd31827 ReCaptcha: f1d10fd37e8f219c00521790aa9124ca12b65e16
RxAtomic: eacf60db868c96bfd63320e28619fe29c179656f Result: d2d07204ce72856f1fd9130bbe42c35a7b0fea10
RxBlocking: 138ad53217434444d6eeeb4fb406a45431d92e31 RxCocoa: fd0862fd2df95fa55562ad28ffd2522c25eb4a85
RxCocoa: df63ebf7b9a70d6b4eeea407ed5dd4efc8979749 RxSwift: c6e3b1c7b325c7d121cd4327e9d98b7ed746b570
RxSwift: 5976ecd04fc2fefd648827c23de5e11157faa973 SwiftLint: 2e4b89feed5909c42c3735bbd6745f4345c4b772
SwiftLint: 3207c1faa2240bf8973b191820a116113cd11073
PODFILE CHECKSUM: 63f50401dee6a885ae0eea927fb966553c6d0f33 PODFILE CHECKSUM: 583c68236539bad71551001f4022b6f2e14d0438
COCOAPODS: 1.5.3 COCOAPODS: 1.3.1

View File

@ -16,12 +16,10 @@
BD850CB2DF4C9C94FC51226C /* Pods_ReCaptcha_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 62BEEA62161F672468CCFD64 /* Pods_ReCaptcha_Example.framework */; }; BD850CB2DF4C9C94FC51226C /* Pods_ReCaptcha_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 62BEEA62161F672468CCFD64 /* Pods_ReCaptcha_Example.framework */; };
D091B6E053FD250B4757E34C /* Pods_ReCaptcha_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9417A28DC340FF0BC1627B3F /* Pods_ReCaptcha_Tests.framework */; }; D091B6E053FD250B4757E34C /* Pods_ReCaptcha_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9417A28DC340FF0BC1627B3F /* Pods_ReCaptcha_Tests.framework */; };
F206BAD51F8D3FEB00A25807 /* Cartfile in Resources */ = {isa = PBXBuildFile; fileRef = F206BAD41F8D3FEB00A25807 /* Cartfile */; }; F206BAD51F8D3FEB00A25807 /* Cartfile in Resources */ = {isa = PBXBuildFile; fileRef = F206BAD41F8D3FEB00A25807 /* Cartfile */; };
F211C22220F7E0B100709B26 /* ReCaptcha_Endpoint__Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F211C22120F7E0B100709B26 /* ReCaptcha_Endpoint__Tests.swift */; };
F231B3971FEC325A00F82943 /* DispatchQueue__Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F231B3961FEC325A00F82943 /* DispatchQueue__Tests.swift */; }; F231B3971FEC325A00F82943 /* DispatchQueue__Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F231B3961FEC325A00F82943 /* DispatchQueue__Tests.swift */; };
F231B39F1FED4A8C00F82943 /* ReCaptchaDecoder+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F231B39E1FED4A8C00F82943 /* ReCaptchaDecoder+Helper.swift */; }; F231B39F1FED4A8C00F82943 /* ReCaptchaDecoder+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F231B39E1FED4A8C00F82943 /* ReCaptchaDecoder+Helper.swift */; };
F288E9451F9537760018688D /* ReCaptchaError+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F288E9441F9537760018688D /* ReCaptchaError+Equatable.swift */; }; F288E9451F9537760018688D /* ReCaptchaError+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F288E9441F9537760018688D /* ReCaptchaError+Equatable.swift */; };
F28FAC9F200E425600E14987 /* ReCaptcha_UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F28FAC9E200E425600E14987 /* ReCaptcha_UITests.swift */; }; F28FAC9F200E425600E14987 /* ReCaptcha_UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F28FAC9E200E425600E14987 /* ReCaptcha_UITests.swift */; };
F2AE8612204F3430002E28D7 /* ReCaptchaResult__Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2AE8611204F3430002E28D7 /* ReCaptchaResult__Tests.swift */; };
F2E2685E1F7AEE3400CD876D /* ReCaptcha__Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E2685D1F7AEE3400CD876D /* ReCaptcha__Tests.swift */; }; F2E2685E1F7AEE3400CD876D /* ReCaptcha__Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2E2685D1F7AEE3400CD876D /* ReCaptcha__Tests.swift */; };
F2ECCF8A1E9FCEFE0097B199 /* ReCaptchaDecoder__Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2ECCF891E9FCEFE0097B199 /* ReCaptchaDecoder__Tests.swift */; }; F2ECCF8A1E9FCEFE0097B199 /* ReCaptchaDecoder__Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2ECCF891E9FCEFE0097B199 /* ReCaptchaDecoder__Tests.swift */; };
F2ECCF8C1E9FE37C0097B199 /* mock.html in Resources */ = {isa = PBXBuildFile; fileRef = F2ECCF8B1E9FE37C0097B199 /* mock.html */; }; F2ECCF8C1E9FE37C0097B199 /* mock.html in Resources */ = {isa = PBXBuildFile; fileRef = F2ECCF8B1E9FE37C0097B199 /* mock.html */; };
@ -61,7 +59,7 @@
607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; }; 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; }; 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
62BEEA62161F672468CCFD64 /* Pods_ReCaptcha_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ReCaptcha_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 62BEEA62161F672468CCFD64 /* Pods_ReCaptcha_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ReCaptcha_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
62C1DD0E80E9920845E5DA51 /* ReCaptcha.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = ReCaptcha.podspec; path = ../ReCaptcha.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 62C1DD0E80E9920845E5DA51 /* ReCaptcha.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = ReCaptcha.podspec; path = ../ReCaptcha.podspec; sourceTree = "<group>"; };
80FF4E03D71AACBD81A36301 /* Pods-ReCaptcha_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReCaptcha_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ReCaptcha_Example/Pods-ReCaptcha_Example.debug.xcconfig"; sourceTree = "<group>"; }; 80FF4E03D71AACBD81A36301 /* Pods-ReCaptcha_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReCaptcha_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ReCaptcha_Example/Pods-ReCaptcha_Example.debug.xcconfig"; sourceTree = "<group>"; };
930BD5ACA20B973070B89ACF /* Pods-ReCaptcha_UITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReCaptcha_UITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ReCaptcha_UITests/Pods-ReCaptcha_UITests.debug.xcconfig"; sourceTree = "<group>"; }; 930BD5ACA20B973070B89ACF /* Pods-ReCaptcha_UITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReCaptcha_UITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ReCaptcha_UITests/Pods-ReCaptcha_UITests.debug.xcconfig"; sourceTree = "<group>"; };
9417A28DC340FF0BC1627B3F /* Pods_ReCaptcha_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ReCaptcha_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9417A28DC340FF0BC1627B3F /* Pods_ReCaptcha_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ReCaptcha_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@ -69,7 +67,6 @@
C2A0BDD35B5E219129E9BC65 /* Pods-ReCaptcha_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReCaptcha_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-ReCaptcha_Example/Pods-ReCaptcha_Example.release.xcconfig"; sourceTree = "<group>"; }; C2A0BDD35B5E219129E9BC65 /* Pods-ReCaptcha_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReCaptcha_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-ReCaptcha_Example/Pods-ReCaptcha_Example.release.xcconfig"; sourceTree = "<group>"; };
C8537003ECC47117AF54DCA9 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; }; C8537003ECC47117AF54DCA9 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
F206BAD41F8D3FEB00A25807 /* Cartfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Cartfile; path = ../Cartfile; sourceTree = "<group>"; }; F206BAD41F8D3FEB00A25807 /* Cartfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Cartfile; path = ../Cartfile; sourceTree = "<group>"; };
F211C22120F7E0B100709B26 /* ReCaptcha_Endpoint__Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReCaptcha_Endpoint__Tests.swift; sourceTree = "<group>"; };
F21901D91F98D62F00D8E2C9 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = CHANGELOG.md; path = ../CHANGELOG.md; sourceTree = "<group>"; }; F21901D91F98D62F00D8E2C9 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = CHANGELOG.md; path = ../CHANGELOG.md; sourceTree = "<group>"; };
F231B3961FEC325A00F82943 /* DispatchQueue__Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DispatchQueue__Tests.swift; sourceTree = "<group>"; }; F231B3961FEC325A00F82943 /* DispatchQueue__Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DispatchQueue__Tests.swift; sourceTree = "<group>"; };
F231B39E1FED4A8C00F82943 /* ReCaptchaDecoder+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ReCaptchaDecoder+Helper.swift"; sourceTree = "<group>"; }; F231B39E1FED4A8C00F82943 /* ReCaptchaDecoder+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ReCaptchaDecoder+Helper.swift"; sourceTree = "<group>"; };
@ -77,7 +74,6 @@
F28FAC9C200E425600E14987 /* ReCaptcha_UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReCaptcha_UITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; F28FAC9C200E425600E14987 /* ReCaptcha_UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReCaptcha_UITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F28FAC9E200E425600E14987 /* ReCaptcha_UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReCaptcha_UITests.swift; sourceTree = "<group>"; }; F28FAC9E200E425600E14987 /* ReCaptcha_UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReCaptcha_UITests.swift; sourceTree = "<group>"; };
F28FACA0200E425600E14987 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; F28FACA0200E425600E14987 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F2AE8611204F3430002E28D7 /* ReCaptchaResult__Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReCaptchaResult__Tests.swift; sourceTree = "<group>"; };
F2E2685D1F7AEE3400CD876D /* ReCaptcha__Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReCaptcha__Tests.swift; sourceTree = "<group>"; }; F2E2685D1F7AEE3400CD876D /* ReCaptcha__Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReCaptcha__Tests.swift; sourceTree = "<group>"; };
F2ECCF761E9FC47B0097B199 /* ReCaptcha_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReCaptcha_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; F2ECCF761E9FC47B0097B199 /* ReCaptcha_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReCaptcha_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F2ECCF7A1E9FC47B0097B199 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; F2ECCF7A1E9FC47B0097B199 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -215,8 +211,6 @@
F2ECCF8D1E9FE68C0097B199 /* ReCaptchaWebViewManager__Tests.swift */, F2ECCF8D1E9FE68C0097B199 /* ReCaptchaWebViewManager__Tests.swift */,
F2E2685D1F7AEE3400CD876D /* ReCaptcha__Tests.swift */, F2E2685D1F7AEE3400CD876D /* ReCaptcha__Tests.swift */,
F231B3961FEC325A00F82943 /* DispatchQueue__Tests.swift */, F231B3961FEC325A00F82943 /* DispatchQueue__Tests.swift */,
F2AE8611204F3430002E28D7 /* ReCaptchaResult__Tests.swift */,
F211C22120F7E0B100709B26 /* ReCaptcha_Endpoint__Tests.swift */,
); );
path = Core; path = Core;
sourceTree = "<group>"; sourceTree = "<group>";
@ -262,6 +256,7 @@
607FACCD1AFB9204008FA782 /* Frameworks */, 607FACCD1AFB9204008FA782 /* Frameworks */,
607FACCE1AFB9204008FA782 /* Resources */, 607FACCE1AFB9204008FA782 /* Resources */,
8F03FFB3F5C55E873C23C682 /* [CP] Embed Pods Frameworks */, 8F03FFB3F5C55E873C23C682 /* [CP] Embed Pods Frameworks */,
ED1C0E07490C9C4B4A401061 /* [CP] Copy Pods Resources */,
F231B3981FEC3B7F00F82943 /* SwiftLint */, F231B3981FEC3B7F00F82943 /* SwiftLint */,
); );
buildRules = ( buildRules = (
@ -281,6 +276,8 @@
F28FAC98200E425600E14987 /* Sources */, F28FAC98200E425600E14987 /* Sources */,
F28FAC99200E425600E14987 /* Frameworks */, F28FAC99200E425600E14987 /* Frameworks */,
F28FAC9A200E425600E14987 /* Resources */, F28FAC9A200E425600E14987 /* Resources */,
BF2909E4520B29BFFBC94AD6 /* [CP] Embed Pods Frameworks */,
DCB1D99E77E589CD76CD3186 /* [CP] Copy Pods Resources */,
F28FACA6200E447600E14987 /* ShellScript */, F28FACA6200E447600E14987 /* ShellScript */,
); );
buildRules = ( buildRules = (
@ -302,6 +299,7 @@
F2ECCF731E9FC47B0097B199 /* Frameworks */, F2ECCF731E9FC47B0097B199 /* Frameworks */,
F2ECCF741E9FC47B0097B199 /* Resources */, F2ECCF741E9FC47B0097B199 /* Resources */,
77003100630E7783A936C451 /* [CP] Embed Pods Frameworks */, 77003100630E7783A936C451 /* [CP] Embed Pods Frameworks */,
44209D7CDDDE3A11075B8104 /* [CP] Copy Pods Resources */,
); );
buildRules = ( buildRules = (
); );
@ -390,6 +388,21 @@
/* End PBXResourcesBuildPhase section */ /* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */
44209D7CDDDE3A11075B8104 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ReCaptcha_Tests/Pods-ReCaptcha_Tests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
51299F67A8756E2B3EAE411A /* [CP] Check Pods Manifest.lock */ = { 51299F67A8756E2B3EAE411A /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
@ -415,17 +428,11 @@
); );
inputPaths = ( inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-ReCaptcha_Tests/Pods-ReCaptcha_Tests-frameworks.sh", "${SRCROOT}/Pods/Target Support Files/Pods-ReCaptcha_Tests/Pods-ReCaptcha_Tests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/RxAtomic/RxAtomic.framework",
"${BUILT_PRODUCTS_DIR}/RxSwift/RxSwift.framework",
"${BUILT_PRODUCTS_DIR}/AppSwizzle/AppSwizzle.framework", "${BUILT_PRODUCTS_DIR}/AppSwizzle/AppSwizzle.framework",
"${BUILT_PRODUCTS_DIR}/RxBlocking/RxBlocking.framework",
); );
name = "[CP] Embed Pods Frameworks"; name = "[CP] Embed Pods Frameworks";
outputPaths = ( outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxAtomic.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AppSwizzle.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AppSwizzle.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxBlocking.framework",
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
@ -440,14 +447,14 @@
inputPaths = ( inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-ReCaptcha_Example/Pods-ReCaptcha_Example-frameworks.sh", "${SRCROOT}/Pods/Target Support Files/Pods-ReCaptcha_Example/Pods-ReCaptcha_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/ReCaptcha/ReCaptcha.framework", "${BUILT_PRODUCTS_DIR}/ReCaptcha/ReCaptcha.framework",
"${BUILT_PRODUCTS_DIR}/RxAtomic/RxAtomic.framework", "${BUILT_PRODUCTS_DIR}/Result/Result.framework",
"${BUILT_PRODUCTS_DIR}/RxCocoa/RxCocoa.framework", "${BUILT_PRODUCTS_DIR}/RxCocoa/RxCocoa.framework",
"${BUILT_PRODUCTS_DIR}/RxSwift/RxSwift.framework", "${BUILT_PRODUCTS_DIR}/RxSwift/RxSwift.framework",
); );
name = "[CP] Embed Pods Frameworks"; name = "[CP] Embed Pods Frameworks";
outputPaths = ( outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ReCaptcha.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ReCaptcha.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxAtomic.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Result.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxCocoa.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxCocoa.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxSwift.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxSwift.framework",
); );
@ -474,6 +481,36 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/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# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/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# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0; showEnvVarsInLog = 0;
}; };
BF2909E4520B29BFFBC94AD6 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ReCaptcha_UITests/Pods-ReCaptcha_UITests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
DCB1D99E77E589CD76CD3186 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ReCaptcha_UITests/Pods-ReCaptcha_UITests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
DDB47454887253730AB35230 /* [CP] Check Pods Manifest.lock */ = { DDB47454887253730AB35230 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
@ -492,6 +529,21 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/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# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/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# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0; showEnvVarsInLog = 0;
}; };
ED1C0E07490C9C4B4A401061 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ReCaptcha_Example/Pods-ReCaptcha_Example-resources.sh\"\n";
showEnvVarsInLog = 0;
};
F231B3981FEC3B7F00F82943 /* SwiftLint */ = { F231B3981FEC3B7F00F82943 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
@ -504,7 +556,7 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\" --path \"${PROJECT_DIR}/..\"\n"; shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\" --path \"${PROJECT_DIR}/..\"";
}; };
F28FACA6200E447600E14987 /* ShellScript */ = { F28FACA6200E447600E14987 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
@ -543,13 +595,11 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
F2AE8612204F3430002E28D7 /* ReCaptchaResult__Tests.swift in Sources */,
F2ECCF961EA00A5B0097B199 /* ReCaptchaWebViewManager+Helpers.swift in Sources */, F2ECCF961EA00A5B0097B199 /* ReCaptchaWebViewManager+Helpers.swift in Sources */,
F2ECCF8E1E9FE68C0097B199 /* ReCaptchaWebViewManager__Tests.swift in Sources */, F2ECCF8E1E9FE68C0097B199 /* ReCaptchaWebViewManager__Tests.swift in Sources */,
F2ECCF981EA011370097B199 /* Result+Helpers.swift in Sources */, F2ECCF981EA011370097B199 /* Result+Helpers.swift in Sources */,
F231B3971FEC325A00F82943 /* DispatchQueue__Tests.swift in Sources */, F231B3971FEC325A00F82943 /* DispatchQueue__Tests.swift in Sources */,
F231B39F1FED4A8C00F82943 /* ReCaptchaDecoder+Helper.swift in Sources */, F231B39F1FED4A8C00F82943 /* ReCaptchaDecoder+Helper.swift in Sources */,
F211C22220F7E0B100709B26 /* ReCaptcha_Endpoint__Tests.swift in Sources */,
F2E2685E1F7AEE3400CD876D /* ReCaptcha__Tests.swift in Sources */, F2E2685E1F7AEE3400CD876D /* ReCaptcha__Tests.swift in Sources */,
F2ECCF931EA009360097B199 /* ReCaptcha+Rx__Tests.swift in Sources */, F2ECCF931EA009360097B199 /* ReCaptcha+Rx__Tests.swift in Sources */,
F288E9451F9537760018688D /* ReCaptchaError+Equatable.swift in Sources */, F288E9451F9537760018688D /* ReCaptchaError+Equatable.swift in Sources */,
@ -703,7 +753,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-Example"; PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-Example";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2; SWIFT_VERSION = 4.0;
}; };
name = Debug; name = Debug;
}; };
@ -719,7 +769,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-Example"; PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-Example";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2; SWIFT_VERSION = 4.0;
}; };
name = Release; name = Release;
}; };
@ -742,7 +792,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "ReCaptcha.ReCaptcha-UITests"; PRODUCT_BUNDLE_IDENTIFIER = "ReCaptcha.ReCaptcha-UITests";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.2; SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = ReCaptcha_Example; TEST_TARGET_NAME = ReCaptcha_Example;
}; };
@ -765,7 +815,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ReCaptcha.ReCaptcha-UITests"; PRODUCT_BUNDLE_IDENTIFIER = "ReCaptcha.ReCaptcha-UITests";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2; SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = ReCaptcha_Example; TEST_TARGET_NAME = ReCaptcha_Example;
}; };
@ -788,7 +838,7 @@
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG UNIT_TESTS"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG UNIT_TESTS";
SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2; SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReCaptcha_Example.app/ReCaptcha_Example"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReCaptcha_Example.app/ReCaptcha_Example";
}; };
name = Debug; name = Debug;
@ -808,7 +858,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-Tests"; PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-Tests";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2; SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReCaptcha_Example.app/ReCaptcha_Example"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReCaptcha_Example.app/ReCaptcha_Example";
}; };
name = Release; name = Release;

View File

@ -40,8 +40,9 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES" language = ""
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables> <Testables>
<TestableReference <TestableReference
skipped = "NO"> skipped = "NO">
@ -80,6 +81,7 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 03/22/17. // Created by Flávio Caetano on 03/22/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import UIKit import UIKit
@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application( func application(
_ application: UIApplication, _ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool { ) -> Bool {
// Override point for customization after application launch. // Override point for customization after application launch.
return true return true

View File

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="17A365" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/> <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
@ -12,7 +16,7 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/> <rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2018 Flávio Caetano. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye"> <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2017 Flávio Caetano. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/> <rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait"> <device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/> <adaptation id="fullscreen"/>
</device> </device>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
@ -22,7 +22,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews> <subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RDW-bD-rSo"> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RDW-bD-rSo">
<rect key="frame" x="50" y="450" width="275" height="50"/> <rect key="frame" x="50" y="505" width="275" height="50"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="50" id="Bt8-Ou-ht2"/> <constraint firstAttribute="height" constant="50" id="Bt8-Ou-ht2"/>
</constraints> </constraints>
@ -34,89 +34,47 @@
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="jHc-GP-v1Z"> <activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="jHc-GP-v1Z">
<rect key="frame" x="177" y="323" width="20" height="20"/> <rect key="frame" x="177" y="323" width="20" height="20"/>
</activityIndicatorView> </activityIndicatorView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="249" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="o6f-cL-1PF"> <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="o6f-cL-1PF">
<rect key="frame" x="20" y="247" width="335" height="173"/> <rect key="frame" x="20" y="192" width="335" height="283"/>
<accessibility key="accessibilityConfiguration" identifier="resultLabel"/> <accessibility key="accessibilityConfiguration" identifier="resultLabel"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<segmentedControl clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="X8E-G9-9IV"> <segmentedControl clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="X8E-G9-9IV">
<rect key="frame" x="71" y="568" width="233" height="29"/> <rect key="frame" x="117" y="594" width="141" height="29"/>
<segments> <segments>
<segment title="Default Endpoint"/> <segment title="Default"/>
<segment title="Alternate"/> <segment title="Alternate"/>
</segments> </segments>
<connections> <connections>
<action selector="didPressEndpointSegmentedControl:" destination="vXZ-lx-hvc" eventType="valueChanged" id="Sdm-dO-doL"/> <action selector="didPressSegmentedControl:" destination="vXZ-lx-hvc" eventType="valueChanged" id="e5Z-W5-Q1d"/>
</connections>
</segmentedControl>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Uyt-0M-CR7">
<rect key="frame" x="77" y="616" width="221" height="31"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Force visible captcha" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="awK-8H-OCQ">
<rect key="frame" x="0.0" y="0.0" width="162" height="31"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="mGh-Ox-cFf">
<rect key="frame" x="172" y="0.0" width="51" height="31"/>
<accessibility key="accessibilityConfiguration" identifier="Switch"/>
</switch>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="awK-8H-OCQ" secondAttribute="bottom" id="0Wx-IJ-Kwg"/>
<constraint firstAttribute="trailing" secondItem="mGh-Ox-cFf" secondAttribute="trailing" id="8Xc-zN-tVW"/>
<constraint firstItem="awK-8H-OCQ" firstAttribute="top" secondItem="Uyt-0M-CR7" secondAttribute="top" id="IbZ-YP-G0R"/>
<constraint firstItem="mGh-Ox-cFf" firstAttribute="top" secondItem="Uyt-0M-CR7" secondAttribute="top" id="P27-Ua-aX7"/>
<constraint firstItem="awK-8H-OCQ" firstAttribute="leading" secondItem="Uyt-0M-CR7" secondAttribute="leading" id="fna-4f-wRD"/>
<constraint firstAttribute="bottom" secondItem="mGh-Ox-cFf" secondAttribute="bottom" id="vnT-b0-5h3"/>
<constraint firstItem="mGh-Ox-cFf" firstAttribute="leading" secondItem="awK-8H-OCQ" secondAttribute="trailing" constant="10" id="wzo-g0-VEj"/>
</constraints>
</view>
<segmentedControl clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="kq2-ci-l1u">
<rect key="frame" x="114" y="520" width="147" height="29"/>
<segments>
<segment title="Nil Locale"/>
<segment title="Chinese"/>
</segments>
<connections>
<action selector="didPressLocaleSegmentedControl:" destination="vXZ-lx-hvc" eventType="valueChanged" id="nSA-f3-8eS"/>
</connections> </connections>
</segmentedControl> </segmentedControl>
</subviews> </subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints> <constraints>
<constraint firstItem="o6f-cL-1PF" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="20" id="0dV-t0-W0Y"/> <constraint firstItem="o6f-cL-1PF" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="20" id="0dV-t0-W0Y"/>
<constraint firstAttribute="trailing" secondItem="RDW-bD-rSo" secondAttribute="trailing" constant="50" id="1Lj-Ox-Kl4"/>
<constraint firstItem="X8E-G9-9IV" firstAttribute="top" secondItem="kq2-ci-l1u" secondAttribute="bottom" constant="20" id="8ye-XO-bpK"/>
<constraint firstItem="X8E-G9-9IV" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="92w-cw-lR2"/> <constraint firstItem="X8E-G9-9IV" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="92w-cw-lR2"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="Uyt-0M-CR7" secondAttribute="bottom" constant="20" id="Bfs-p5-IBM"/> <constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="RDW-bD-rSo" secondAttribute="bottom" constant="112" id="E4K-Vp-ZL2"/>
<constraint firstItem="o6f-cL-1PF" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" priority="750" id="NMD-ir-PXe"/> <constraint firstItem="o6f-cL-1PF" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" priority="750" id="NMD-ir-PXe"/>
<constraint firstItem="RDW-bD-rSo" firstAttribute="top" secondItem="o6f-cL-1PF" secondAttribute="bottom" constant="30" id="TZe-z9-MZS"/> <constraint firstItem="RDW-bD-rSo" firstAttribute="top" secondItem="o6f-cL-1PF" secondAttribute="bottom" constant="30" id="TZe-z9-MZS"/>
<constraint firstItem="jHc-GP-v1Z" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" id="VOe-WJ-FKo"/> <constraint firstItem="jHc-GP-v1Z" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" id="VOe-WJ-FKo"/>
<constraint firstItem="jHc-GP-v1Z" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="XkT-zr-eUO"/> <constraint firstItem="jHc-GP-v1Z" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="XkT-zr-eUO"/>
<constraint firstItem="kq2-ci-l1u" firstAttribute="top" secondItem="RDW-bD-rSo" secondAttribute="bottom" constant="20" id="Y4H-6k-gDx"/>
<constraint firstAttribute="trailing" secondItem="o6f-cL-1PF" secondAttribute="trailing" constant="20" id="c74-nm-rgi"/> <constraint firstAttribute="trailing" secondItem="o6f-cL-1PF" secondAttribute="trailing" constant="20" id="c74-nm-rgi"/>
<constraint firstAttribute="trailing" secondItem="RDW-bD-rSo" secondAttribute="trailing" constant="50" id="c7q-Rw-n0F"/>
<constraint firstItem="RDW-bD-rSo" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="50" id="iXO-hP-XZ7"/> <constraint firstItem="RDW-bD-rSo" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="50" id="iXO-hP-XZ7"/>
<constraint firstItem="kq2-ci-l1u" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="ice-pp-mVe"/> <constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="X8E-G9-9IV" secondAttribute="bottom" constant="45" id="y2a-Mw-eWb"/>
<constraint firstItem="Uyt-0M-CR7" firstAttribute="top" secondItem="X8E-G9-9IV" secondAttribute="bottom" constant="20" id="nIE-QT-RpQ"/>
<constraint firstItem="Uyt-0M-CR7" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="qfG-68-ySO"/>
</constraints> </constraints>
</view> </view>
<connections> <connections>
<outlet property="endpointSegmentedControl" destination="X8E-G9-9IV" id="jAb-fU-Yu5"/>
<outlet property="label" destination="o6f-cL-1PF" id="KQV-3X-RKr"/> <outlet property="label" destination="o6f-cL-1PF" id="KQV-3X-RKr"/>
<outlet property="localeSegmentedControl" destination="kq2-ci-l1u" id="gL7-du-K6l"/> <outlet property="segmentedControl" destination="X8E-G9-9IV" id="sS0-3k-Alu"/>
<outlet property="spinner" destination="jHc-GP-v1Z" id="gRn-JW-FIK"/> <outlet property="spinner" destination="jHc-GP-v1Z" id="gRn-JW-FIK"/>
<outlet property="visibleChallengeSwitch" destination="mGh-Ox-cFf" id="R13-nD-EXL"/>
</connections> </connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="117.59999999999999" y="117.39130434782609"/>
</scene> </scene>
</scenes> </scenes>
</document> </document>

View File

@ -39,11 +39,6 @@
"idiom" : "iphone", "idiom" : "iphone",
"size" : "60x60", "size" : "60x60",
"scale" : "3x" "scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
} }
], ],
"info" : { "info" : {

View File

@ -3,10 +3,11 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 03/22/17. // Created by Flávio Caetano on 03/22/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import ReCaptcha import ReCaptcha
import Result
import RxCocoa import RxCocoa
import RxSwift import RxSwift
import UIKit import UIKit
@ -15,46 +16,28 @@ import UIKit
class ViewController: UIViewController { class ViewController: UIViewController {
private struct Constants { private struct Constants {
static let webViewTag = 123 static let webViewTag = 123
static let testLabelTag = 321
} }
private var recaptcha: ReCaptcha! private var recaptcha: ReCaptcha!
private var disposeBag = DisposeBag() private var disposeBag = DisposeBag()
private var locale: Locale?
private var endpoint = ReCaptcha.Endpoint.default
@IBOutlet private weak var label: UILabel! @IBOutlet private weak var label: UILabel!
@IBOutlet private weak var spinner: UIActivityIndicatorView! @IBOutlet private weak var spinner: UIActivityIndicatorView!
@IBOutlet private weak var localeSegmentedControl: UISegmentedControl! @IBOutlet private weak var segmentedControl: UISegmentedControl!
@IBOutlet private weak var endpointSegmentedControl: UISegmentedControl!
@IBOutlet private weak var visibleChallengeSwitch: UISwitch!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
setupReCaptcha() setupReCaptcha(endpoint: .default)
} }
@IBAction func didPressEndpointSegmentedControl(_ sender: UISegmentedControl) { @IBAction func didPressSegmentedControl(_ sender: UISegmentedControl) {
label.text = "" label.text = ""
switch sender.selectedSegmentIndex { switch sender.selectedSegmentIndex {
case 0: endpoint = .default case 0: setupReCaptcha(endpoint: .default)
case 1: endpoint = .alternate case 1: setupReCaptcha(endpoint: .alternate)
default: assertionFailure("invalid index") default: assertionFailure("invalid index")
} }
setupReCaptcha()
}
@IBAction func didPressLocaleSegmentedControl(_ sender: UISegmentedControl) {
label.text = ""
switch sender.selectedSegmentIndex {
case 0: locale = nil
case 1: locale = Locale(identifier: "zh-CN")
default: assertionFailure("invalid index")
}
setupReCaptcha()
} }
@IBAction private func didPressButton(button: UIButton) { @IBAction private func didPressButton(button: UIButton) {
@ -83,7 +66,7 @@ class ViewController: UIViewController {
.disposed(by: disposeBag) .disposed(by: disposeBag)
isEnabled isEnabled
.bind(to: endpointSegmentedControl.rx.isEnabled) .bind(to: segmentedControl.rx.isEnabled)
.disposed(by: disposeBag) .disposed(by: disposeBag)
validate validate
@ -96,19 +79,14 @@ class ViewController: UIViewController {
.disposed(by: disposeBag) .disposed(by: disposeBag)
validate validate
.map { try $0.dematerialize() }
.bind(to: label.rx.text) .bind(to: label.rx.text)
.disposed(by: disposeBag) .disposed(by: disposeBag)
visibleChallengeSwitch.rx.value
.subscribe(onNext: { [weak recaptcha] value in
recaptcha?.forceVisibleChallenge = value
})
.disposed(by: disposeBag)
} }
private func setupReCaptcha() { private func setupReCaptcha(endpoint: ReCaptcha.Endpoint) {
// swiftlint:disable:next force_try // swiftlint:disable:next force_try
recaptcha = try! ReCaptcha(endpoint: endpoint, locale: locale) recaptcha = try! ReCaptcha(endpoint: endpoint)
recaptcha.configureWebView { [weak self] webview in recaptcha.configureWebView { [weak self] webview in
webview.frame = self?.view.bounds ?? CGRect.zero webview.frame = self?.view.bounds ?? CGRect.zero
@ -116,9 +94,7 @@ class ViewController: UIViewController {
// For testing purposes // For testing purposes
// If the webview requires presentation, this should work as a way of detecting the webview in UI tests // If the webview requires presentation, this should work as a way of detecting the webview in UI tests
self?.view.viewWithTag(Constants.testLabelTag)?.removeFromSuperview()
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) let label = UILabel(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
label.tag = Constants.testLabelTag
label.accessibilityLabel = "webview" label.accessibilityLabel = "webview"
self?.view.addSubview(label) self?.view.addSubview(label)
} }

View File

@ -3,7 +3,3 @@ disabled_rules:
- nesting - nesting
- force_unwrapping - force_unwrapping
- explicit_top_level_acl - explicit_top_level_acl
- function_body_length
- identifier_name
- file_length
- type_body_length

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 21/12/17. // Created by Flávio Caetano on 21/12/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
@testable import ReCaptcha @testable import ReCaptcha
@ -20,8 +20,6 @@ class DispatchQueue__Tests: XCTestCase {
super.tearDown() super.tearDown()
} }
// MARK: Throttle
func test__Throttle_Nil_Context() { func test__Throttle_Nil_Context() {
// Execute closure called once // Execute closure called once
let exp0 = expectation(description: "did call single closure") let exp0 = expectation(description: "did call single closure")
@ -33,15 +31,14 @@ class DispatchQueue__Tests: XCTestCase {
waitForExpectations(timeout: 1) waitForExpectations(timeout: 1)
// Does not execute first closure // Does not execute first closure
let exp1 = expectation(description: "did call last closure") let exp1 = expectation(description: "")
DispatchQueue.main.throttle(deadline: .now() + 0.1) { DispatchQueue.main.throttle(deadline: .now() + 0.1) {
XCTFail("Shouldn't be called") XCTFail("Shouldn't be called")
} }
DispatchQueue.main.throttle( DispatchQueue.main.throttle(deadline: .now() + 0.1) {
deadline: .now() + 0.1, exp1.fulfill()
action: exp1.fulfill }
)
waitForExpectations(timeout: 1) waitForExpectations(timeout: 1)
} }
@ -51,11 +48,9 @@ class DispatchQueue__Tests: XCTestCase {
let exp0 = expectation(description: "did call single closure") let exp0 = expectation(description: "did call single closure")
let c0 = UUID() let c0 = UUID()
DispatchQueue.main.throttle( DispatchQueue.main.throttle(deadline: .now() + 0.1, context: c0) {
deadline: .now() + 0.1, exp0.fulfill()
context: c0, }
action: exp0.fulfill
)
waitForExpectations(timeout: 1) waitForExpectations(timeout: 1)
@ -66,132 +61,17 @@ class DispatchQueue__Tests: XCTestCase {
XCTFail("Shouldn't be called") XCTFail("Shouldn't be called")
} }
DispatchQueue.main.throttle( DispatchQueue.main.throttle(deadline: .now() + 0.1, context: c1) {
deadline: .now() + 0.1, exp1.fulfill()
context: c1, }
action: exp1.fulfill
)
// Execute in a different context // Execute in a different context
let exp2 = expectation(description: "execute on different context") let exp2 = expectation(description: "execute on different context")
let c2 = UUID() let c2 = UUID()
DispatchQueue.main.throttle( DispatchQueue.main.throttle(deadline: .now() + 0.1, context: c2) {
deadline: .now() + 0.1, exp2.fulfill()
context: c2,
action: exp2.fulfill
)
waitForExpectations(timeout: 1)
}
// MARK: Debounce
func test__Debounce_Nil_Context() {
// Does not execute sequenced closures
let exp0 = expectation(description: "did call first closure")
DispatchQueue.main.debounce(
interval: 0.1,
action: exp0.fulfill
)
DispatchQueue.main.debounce(interval: 0) {
XCTFail("Shouldn't be called")
} }
waitForExpectations(timeout: 1) waitForExpectations(timeout: 1)
// Executes closure after previous has timed out
let exp1 = expectation(description: "did call closure")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
DispatchQueue.main.debounce(
interval: 0.1,
action: exp1.fulfill
)
}
waitForExpectations(timeout: 3)
}
func test__Debounce_Context() {
// Does not execute sequenced closures
let exp0 = expectation(description: "did call first closure")
let c0 = UUID()
DispatchQueue.main.debounce(
interval: 0.1,
context: c0,
action: exp0.fulfill
)
DispatchQueue.main.debounce(interval: 0, context: c0) {
XCTFail("Shouldn't be called")
}
// Execute in a different context
let c1 = UUID()
let exp1 = expectation(description: "executes in different context")
DispatchQueue.main.debounce(
interval: 0,
context: c1,
action: exp1.fulfill
)
waitForExpectations(timeout: 1)
// Executes closure after previous has timed out
let exp2 = expectation(description: "did call closure")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
DispatchQueue.main.debounce(
interval: 0.1,
context: c0,
action: exp2.fulfill
)
}
waitForExpectations(timeout: 5)
}
// MARK: Once
func test__Once__Single_Dispatch() {
let token = 3
var dispatchCount = 0
// Does dispatch the given action
DispatchQueue.once(token: token) {
dispatchCount = 1
}
XCTAssertEqual(dispatchCount, 1)
// Does not dispatch again for the same token
DispatchQueue.once(token: token) {
dispatchCount = 2
}
XCTAssertEqual(dispatchCount, 1)
}
func test__Once__Multiple_Dispatches() {
let token1 = 4
var didDispatch1 = false
// Does dispatch the given action
DispatchQueue.once(token: token1) {
didDispatch1 = true
}
XCTAssertTrue(didDispatch1)
// Dispatch for a different token
let token2 = 6
var didDispatch2 = false
DispatchQueue.once(token: token2) {
didDispatch2 = true
}
XCTAssertTrue(didDispatch2)
} }
} }

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 13/04/17. // Created by Flávio Caetano on 13/04/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
@testable import ReCaptcha @testable import ReCaptcha

View File

@ -1,39 +0,0 @@
//
// ReCaptchaResult__Tests.swift
// ReCaptcha
//
// Created by Flávio Caetano on 06/03/18.
// Copyright © 2018 ReCaptcha. All rights reserved.
//
@testable import ReCaptcha
import XCTest
class ReCaptchaResult__Tests: XCTestCase {
func test__Get_Token() {
let token = UUID().uuidString
let result = ReCaptchaResult.token(token)
do {
let value = try result.dematerialize()
XCTAssertEqual(value, token)
}
catch let err {
XCTFail(err.localizedDescription)
}
}
func test__Get_Token__Error() {
let error = ReCaptchaError.random()
let result = ReCaptchaResult.error(error)
do {
_ = try result.dematerialize()
XCTFail("Shouldn't have completed")
}
catch let err {
XCTAssertEqual(err as? ReCaptchaError, error)
}
}
}

View File

@ -3,11 +3,12 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 13/04/17. // Created by Flávio Caetano on 13/04/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
@testable import ReCaptcha @testable import ReCaptcha
import Result
import WebKit import WebKit
import XCTest import XCTest
@ -35,7 +36,7 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
func test__Validate__Token() { func test__Validate__Token() {
let exp1 = expectation(description: "load token") let exp1 = expectation(description: "load token")
var result1: ReCaptchaResult? var result1: ReCaptchaWebViewManager.Response?
// Validate // Validate
let manager = ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey) let manager = ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey)
@ -54,12 +55,12 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
// Verify // Verify
XCTAssertNotNil(result1) XCTAssertNotNil(result1)
XCTAssertNil(result1?.error) XCTAssertNil(result1?.error)
XCTAssertEqual(result1?.token, apiKey) XCTAssertEqual(result1?.value, apiKey)
// Validate again // Validate again
let exp2 = expectation(description: "reload token") let exp2 = expectation(description: "reload token")
var result2: ReCaptchaResult? var result2: ReCaptchaWebViewManager.Response?
// Validate // Validate
manager.validate(on: presenterView) { response in manager.validate(on: presenterView) { response in
@ -73,7 +74,7 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
// Verify // Verify
XCTAssertNotNil(result2) XCTAssertNotNil(result2)
XCTAssertNil(result2?.error) XCTAssertNil(result2?.error)
XCTAssertEqual(result2?.token, apiKey) XCTAssertEqual(result2?.value, apiKey)
} }
@ -95,7 +96,7 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
func test__Validate__Message_Error() { func test__Validate__Message_Error() {
var result: ReCaptchaResult? var result: ReCaptchaWebViewManager.Response?
let exp = expectation(description: "message error") let exp = expectation(description: "message error")
// Validate // Validate
@ -104,7 +105,7 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
XCTFail("should not ask to configure the webview") XCTFail("should not ask to configure the webview")
} }
manager.validate(on: presenterView, resetOnError: false) { response in manager.validate(on: presenterView) { response in
result = response result = response
exp.fulfill() exp.fulfill()
} }
@ -114,11 +115,11 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
// Verify // Verify
XCTAssertNotNil(result) XCTAssertNotNil(result)
XCTAssertEqual(result?.error, .wrongMessageFormat) XCTAssertEqual(result?.error, .wrongMessageFormat)
XCTAssertNil(result?.token) XCTAssertNil(result?.value)
} }
func test__Validate__JS_Error() { func test__Validate__JS_Error() {
var result: ReCaptchaResult? var result: ReCaptchaWebViewManager.Response?
let exp = expectation(description: "js error") let exp = expectation(description: "js error")
// Validate // Validate
@ -127,7 +128,7 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
XCTFail("should not ask to configure the webview") XCTFail("should not ask to configure the webview")
} }
manager.validate(on: presenterView, resetOnError: false) { response in manager.validate(on: presenterView) { response in
result = response result = response
exp.fulfill() exp.fulfill()
} }
@ -137,7 +138,7 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
// Verify // Verify
XCTAssertNotNil(result) XCTAssertNotNil(result)
XCTAssertNotNil(result?.error) XCTAssertNotNil(result?.error)
XCTAssertNil(result?.token) XCTAssertNil(result?.value)
switch result!.error! { switch result!.error! {
case .unexpected(let error as NSError): case .unexpected(let error as NSError):
@ -182,62 +183,6 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
waitForExpectations(timeout: 10) waitForExpectations(timeout: 10)
} }
func test__Configure_Web_View__Called_Once() {
var count = 0
let exp0 = expectation(description: "configure webview")
// Configure WebView
let manager = ReCaptchaWebViewManager(messageBody: "{action: \"showReCaptcha\"}")
manager.configureWebView { _ in
if count < 3 {
manager.webView.evaluateJavaScript("execute();") { XCTAssertNil($1) }
}
count += 1
exp0.fulfill()
}
manager.validate(on: presenterView) { _ in
XCTFail("should not call completion")
}
waitForExpectations(timeout: 10)
let exp1 = expectation(description: "waiting for extra calls")
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: exp1.fulfill)
waitForExpectations(timeout: 2)
XCTAssertEqual(count, 1)
}
func test__Configure_Web_View__Called_Again_With_Reset() {
let exp0 = expectation(description: "configure webview 0")
let manager = ReCaptchaWebViewManager(messageBody: "{action: \"showReCaptcha\"}")
manager.validate(on: presenterView) { _ in
XCTFail("should not call completion")
}
// Configure Webview
manager.configureWebView { _ in
manager.webView.evaluateJavaScript("execute();") { XCTAssertNil($1) }
exp0.fulfill()
}
waitForExpectations(timeout: 10)
// Reset and ensure it calls again
let exp1 = expectation(description: "configure webview 1")
manager.configureWebView { _ in
manager.webView.evaluateJavaScript("execute();") { XCTAssertNil($1) }
exp1.fulfill()
}
manager.reset()
waitForExpectations(timeout: 10)
}
// MARK: Stop // MARK: Stop
func test__Stop() { func test__Stop() {
@ -265,7 +210,7 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
func test__Key_Setup() { func test__Key_Setup() {
let exp = expectation(description: "setup key") let exp = expectation(description: "setup key")
var result: ReCaptchaResult? var result: ReCaptchaWebViewManager.Response?
// Validate // Validate
let manager = ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey) let manager = ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey)
@ -282,13 +227,13 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
XCTAssertNotNil(result) XCTAssertNotNil(result)
XCTAssertNil(result?.error) XCTAssertNil(result?.error)
XCTAssertEqual(result?.token, apiKey) XCTAssertEqual(result?.value, apiKey)
} }
func test__Endpoint_Setup() { func test__Endpoint_Setup() {
let exp = expectation(description: "setup endpoint") let exp = expectation(description: "setup endpoint")
let endpoint = ReCaptcha.Endpoint.alternate.getURL(locale: nil) let endpoint = String(describing: arc4random())
var result: ReCaptchaResult? var result: ReCaptchaWebViewManager.Response?
let manager = ReCaptchaWebViewManager(messageBody: "{token: endpoint}", endpoint: endpoint) let manager = ReCaptchaWebViewManager(messageBody: "{token: endpoint}", endpoint: endpoint)
manager.configureWebView { _ in manager.configureWebView { _ in
@ -304,98 +249,6 @@ class ReCaptchaWebViewManager__Tests: XCTestCase {
XCTAssertNotNil(result) XCTAssertNotNil(result)
XCTAssertNil(result?.error) XCTAssertNil(result?.error)
XCTAssertEqual(result?.token, endpoint) XCTAssertEqual(result?.value, endpoint)
}
// MARK: Reset
func test__Reset() {
let exp1 = expectation(description: "fail on first execution")
var result1: ReCaptchaResult?
// Validate
let manager = ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey, shouldFail: true)
manager.configureWebView { _ in
XCTFail("should not ask to configure the webview")
}
// Error
manager.validate(on: presenterView, resetOnError: false) { result in
result1 = result
exp1.fulfill()
}
waitForExpectations(timeout: 10)
XCTAssertEqual(result1?.error, .wrongMessageFormat)
// Resets and tries again
let exp2 = expectation(description: "validates after reset")
var result2: ReCaptchaResult?
manager.reset()
manager.validate(on: presenterView, resetOnError: false) { result in
result2 = result
exp2.fulfill()
}
waitForExpectations(timeout: 10)
XCTAssertNil(result2?.error)
XCTAssertEqual(result2?.token, apiKey)
}
func test__Validate__Reset_On_Error() {
let exp = expectation(description: "fail on first execution")
var result: ReCaptchaResult?
// Validate
let manager = ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey, shouldFail: true)
manager.configureWebView { _ in
XCTFail("should not ask to configure the webview")
}
// Error
manager.validate(on: presenterView, resetOnError: true) { response in
result = response
exp.fulfill()
}
waitForExpectations(timeout: 10)
XCTAssertNil(result?.error)
XCTAssertEqual(result?.token, apiKey)
}
func test__Validate__Should_Skip_For_Tests() {
let exp = expectation(description: "did skip validation")
let manager = ReCaptchaWebViewManager()
manager.shouldSkipForTests = true
manager.completion = { result in
XCTAssertEqual(result.token, "")
exp.fulfill()
}
manager.validate(on: presenterView)
waitForExpectations(timeout: 1)
}
// MARK: Force Challenge Visible
func test__Force_Visible_Challenge() {
let manager = ReCaptchaWebViewManager()
// Initial value
XCTAssertFalse(manager.forceVisibleChallenge)
// Set True
manager.forceVisibleChallenge = true
XCTAssertEqual(manager.webView.customUserAgent, "Googlebot/2.1")
// Set False
manager.forceVisibleChallenge = false
XCTAssertNotEqual(manager.webView.customUserAgent?.isEmpty, false)
} }
} }

View File

@ -1,27 +0,0 @@
//
// ReCaptcha_Endpoint__.swift
// ReCaptcha
//
// Created by Flávio Caetano on 12/07/18.
// Copyright © 2018 ReCaptcha. All rights reserved.
//
@testable import ReCaptcha
import XCTest
class ReCaptcha_Endpoint__Tests: XCTestCase {
private let endpoint = ReCaptcha.Endpoint.default
private let endpointURL = "https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
// MARK: - Locale
func test__Locale__Nil() {
XCTAssertEqual(endpoint.getURL(locale: nil), endpointURL)
}
func test__Locale__Valid() {
let locale = Locale(identifier: "pt-BR")
XCTAssertEqual(endpoint.getURL(locale: locale), "\(endpointURL)&hl=pt-BR")
}
}

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 26/09/17. // Created by Flávio Caetano on 26/09/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import AppSwizzle import AppSwizzle
@ -110,17 +110,6 @@ class ReCaptcha__Tests: XCTestCase {
) )
XCTAssertEqual(config2?.apiKey, key) XCTAssertEqual(config2?.apiKey, key)
} }
func test__Force_Visible_Challenge() {
let recaptcha = ReCaptcha(manager: ReCaptchaWebViewManager())
// Initial value
XCTAssertFalse(recaptcha.forceVisibleChallenge)
// Set true
recaptcha.forceVisibleChallenge = true
XCTAssertTrue(recaptcha.forceVisibleChallenge)
}
} }

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 22/12/17. // Created by Flávio Caetano on 22/12/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import Foundation import Foundation

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 16/10/17. // Created by Flávio Caetano on 16/10/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import Foundation import Foundation

View File

@ -3,48 +3,26 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 13/04/17. // Created by Flávio Caetano on 13/04/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import Foundation import Foundation
@testable import ReCaptcha @testable import ReCaptcha
import WebKit
extension ReCaptchaWebViewManager { extension ReCaptchaWebViewManager {
private static let unformattedHTML: String! = { convenience init(messageBody: String, apiKey: String? = nil, endpoint: String? = nil) {
Bundle(for: ReCaptchaWebViewManager__Tests.self) let localhost = URL(string: "http://localhost")!
let html = Bundle(for: ReCaptchaWebViewManager__Tests.self)
.path(forResource: "mock", ofType: "html") .path(forResource: "mock", ofType: "html")
.flatMap { try? String(contentsOfFile: $0) } .flatMap { try? String(contentsOfFile: $0) }
}() .map { String(format: $0, arguments: ["message": messageBody]) }
convenience init(
messageBody: String = "",
apiKey: String? = nil,
endpoint: String? = nil,
shouldFail: Bool = false
) {
let localhost = URL(string: "http://localhost")!
let html = String(format: ReCaptchaWebViewManager.unformattedHTML, arguments: [
"message": messageBody,
"shouldFail": shouldFail.description
])
self.init( self.init(
html: html, html: html!,
apiKey: apiKey ?? String(arc4random()), apiKey: apiKey ?? String(arc4random()),
baseURL: localhost, baseURL: localhost,
endpoint: endpoint ?? localhost.absoluteString endpoint: endpoint ?? localhost.absoluteString
) )
} }
func configureWebView(_ configure: @escaping (WKWebView) -> Void) {
configureWebView = configure
}
func validate(on view: UIView, resetOnError: Bool = true, completion: @escaping (ReCaptchaResult) -> Void) {
self.shouldResetOnError = resetOnError
self.completion = completion
validate(on: view)
}
} }

View File

@ -3,20 +3,20 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 13/04/17. // Created by Flávio Caetano on 13/04/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
@testable import ReCaptcha import Result
extension ReCaptchaResult { extension Result {
var token: String? { var value: T? {
guard case .token(let value) = self else { return nil } guard case .success(let value) = self else { return nil }
return value return value
} }
var error: ReCaptchaError? { var error: Error? {
guard case .error(let error) = self else { return nil } guard case .failure(let error) = self else { return nil }
return error return error
} }
} }

View File

@ -3,30 +3,31 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 13/04/17. // Created by Flávio Caetano on 13/04/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
@testable import ReCaptcha @testable import ReCaptcha
import RxBlocking
import RxCocoa
import RxSwift import RxSwift
import XCTest import XCTest
class ReCaptcha_Rx__Tests: XCTestCase { class ReCaptcha_Rx__Tests: XCTestCase {
fileprivate var disposeBag: DisposeBag!
fileprivate var apiKey: String! fileprivate var apiKey: String!
fileprivate var presenterView: UIView! fileprivate var presenterView: UIView!
override func setUp() { override func setUp() {
super.setUp() super.setUp()
disposeBag = DisposeBag()
presenterView = UIApplication.shared.keyWindow! presenterView = UIApplication.shared.keyWindow!
apiKey = String(arc4random()) apiKey = String(arc4random())
} }
override func tearDown() { override func tearDown() {
disposeBag = nil
presenterView = nil presenterView = nil
apiKey = nil apiKey = nil
@ -35,70 +36,102 @@ class ReCaptcha_Rx__Tests: XCTestCase {
func test__Validate__Token() { func test__Validate__Token() {
let recaptcha = ReCaptcha(manager: ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey)) let manager = ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey)
recaptcha.configureWebView { _ in manager.configureWebView { _ in
XCTFail("should not ask to configure the webview") XCTFail("should not ask to configure the webview")
} }
do {
// Validate
let result = try recaptcha.rx.validate(on: presenterView)
.toBlocking()
.single()
// Verify var result: ReCaptchaWebViewManager.Response?
XCTAssertEqual(result, apiKey) let exp = expectation(description: "validate token")
}
catch let error { // Validate
XCTFail(error.localizedDescription) manager.rx.validate(on: presenterView)
} .subscribe { event in
switch event {
case .next(let value):
result = value
case .error(let error):
XCTFail(error.localizedDescription)
case .completed:
exp.fulfill()
}
}
.disposed(by: disposeBag)
waitForExpectations(timeout: 10)
// Verify
XCTAssertNotNil(result)
XCTAssertEqual(result?.value, apiKey)
XCTAssertNil(result?.error)
} }
func test__Validate__Show_ReCaptcha() { func test__Validate__Show_ReCaptcha() {
let recaptcha = ReCaptcha( let manager = ReCaptchaWebViewManager(messageBody: "{action: \"showReCaptcha\"}", apiKey: apiKey)
manager: ReCaptchaWebViewManager(messageBody: "{action: \"showReCaptcha\"}", apiKey: apiKey) let exp = expectation(description: "show recaptcha")
)
var didConfigureWebView = false manager.configureWebView { _ in
exp.fulfill()
recaptcha.configureWebView { _ in
didConfigureWebView = true
} }
do { // Validate
// Validate manager.rx.validate(on: presenterView)
_ = try recaptcha.rx.validate(on: presenterView) .timeout(2, scheduler: MainScheduler.instance)
.timeout(2, scheduler: MainScheduler.instance) .subscribe { event in
.toBlocking() switch event {
.single() case .next:
XCTFail("should not have validated")
XCTFail("should have thrown exception") case .error(let error):
} XCTAssertEqual(String(describing: error), RxError.timeout.debugDescription)
catch let error {
XCTAssertEqual(String(describing: error), RxError.timeout.debugDescription) case .completed:
XCTAssertTrue(didConfigureWebView) XCTFail("should not have completed")
} }
}
.disposed(by: disposeBag)
waitForExpectations(timeout: 10)
} }
func test__Validate__Error() { func test__Validate__Error() {
let recaptcha = ReCaptcha(manager: ReCaptchaWebViewManager(messageBody: "\"foobar\"", apiKey: apiKey)) let manager = ReCaptchaWebViewManager(messageBody: "\"foobar\"", apiKey: apiKey)
recaptcha.configureWebView { _ in manager.configureWebView { _ in
XCTFail("should not ask to configure the webview") XCTFail("should not ask to configure the webview")
} }
do {
// Validate
_ = try recaptcha.rx.validate(on: presenterView, resetOnError: false)
.toBlocking()
.single()
XCTFail("should have thrown exception") var result: ReCaptchaWebViewManager.Response?
} let exp = expectation(description: "validate token")
catch let error {
XCTAssertEqual(error as? ReCaptchaError, .wrongMessageFormat) // Validate
} manager.rx.validate(on: presenterView)
.subscribe { event in
switch event {
case .next(let value):
result = value
case .error(let error):
XCTFail(error.localizedDescription)
case .completed:
exp.fulfill()
}
}
.disposed(by: disposeBag)
waitForExpectations(timeout: 10)
// Verify
XCTAssertNotNil(result)
XCTAssertNil(result?.value)
XCTAssertNotNil(result?.error)
XCTAssertEqual(result?.error, .wrongMessageFormat)
} }
// MARK: Dispose // MARK: Dispose
@ -107,83 +140,21 @@ class ReCaptcha_Rx__Tests: XCTestCase {
let exp = expectation(description: "stop loading") let exp = expectation(description: "stop loading")
// Stop // Stop
let recaptcha = ReCaptcha(manager: ReCaptchaWebViewManager(messageBody: "{log: \"foo\"}")) let manager = ReCaptchaWebViewManager(messageBody: "{action: \"showReCaptcha\"}")
recaptcha.configureWebView { _ in manager.configureWebView { _ in
XCTFail("should not ask to configure the webview") XCTFail("should not ask to configure the webview")
} }
let disposable = recaptcha.rx.validate(on: presenterView) let disposable = manager.rx.validate(on: presenterView)
.do(onDispose: exp.fulfill)
.subscribe { _ in .subscribe { _ in
XCTFail("should not validate") XCTFail("should not validate")
} }
disposable.dispose()
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
disposable.dispose() exp.fulfill()
} }
waitForExpectations(timeout: 10) waitForExpectations(timeout: 10)
} }
// MARK: Reset
func test__Reset() {
// Validate
let recaptcha = ReCaptcha(
manager: ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey, shouldFail: true)
)
recaptcha.configureWebView { _ in
XCTFail("should not ask to configure the webview")
}
do {
// Error
_ = try recaptcha.rx.validate(on: presenterView, resetOnError: false)
.toBlocking()
.single()
}
catch let error {
XCTAssertEqual(error as? ReCaptchaError, .wrongMessageFormat)
// Resets after failure
_ = Observable<Void>.just(())
.bind(to: recaptcha.rx.reset)
}
do {
// Resets and tries again
let result = try recaptcha.rx.validate(on: presenterView, resetOnError: false)
.toBlocking()
.single()
XCTAssertEqual(result, apiKey)
}
catch let error {
XCTFail(error.localizedDescription)
}
}
func test__Validate__Reset_On_Error() {
// Validate
let recaptcha = ReCaptcha(
manager: ReCaptchaWebViewManager(messageBody: "{token: key}", apiKey: apiKey, shouldFail: true)
)
recaptcha.configureWebView { _ in
XCTFail("should not ask to configure the webview")
}
do {
// Error
let result = try recaptcha.rx.validate(on: presenterView, resetOnError: true)
.toBlocking()
.single()
XCTAssertEqual(result, apiKey)
}
catch let error {
XCTFail(error.localizedDescription)
}
}
} }

View File

@ -4,25 +4,14 @@
<script type="text/javascript"> <script type="text/javascript">
var key = "${apiKey}"; var key = "${apiKey}";
var endpoint = "${endpoint}"; var endpoint = "${endpoint}";
var shouldFail = ${shouldFail};
var post = function(value) {
window.webkit.messageHandlers.recaptcha.postMessage(value);
};
var execute = function() { var execute = function() {
if (shouldFail) { window.webkit.messageHandlers.recaptcha.postMessage(${message});
post("error"); }
}
else {
post(${message});
}
};
var reset = function() { window.onload = function() {
shouldFail = false; window.webkit.messageHandlers.recaptcha.postMessage({action: "didLoad"});
post({action: "didLoad"}); }
};
</script> </script>
</head> </head>
<body> <body>

View File

@ -23,8 +23,7 @@ class ReCaptcha_UITests: XCTestCase {
func test__Validate__Default_Endpoint() { func test__Validate__Default_Endpoint() {
let app = XCUIApplication() let app = XCUIApplication()
app.segmentedControls.buttons["Default Endpoint"].tap() app.segmentedControls.buttons["Default"].tap()
app.switches["Switch"].tap()
app.buttons["Validate"].tap() app.buttons["Validate"].tap()
verifyValidation() verifyValidation()
@ -33,7 +32,6 @@ class ReCaptcha_UITests: XCTestCase {
func test__Validate__Alternate_Endpoint() { func test__Validate__Alternate_Endpoint() {
let app = XCUIApplication() let app = XCUIApplication()
app.segmentedControls.buttons["Alternate"].tap() app.segmentedControls.buttons["Alternate"].tap()
app.switches["Switch"].tap()
app.buttons["Validate"].tap() app.buttons["Validate"].tap()
verifyValidation() verifyValidation()
@ -46,6 +44,19 @@ class ReCaptcha_UITests: XCTestCase {
let webview = app.staticTexts.element(matching: .any, identifier: "webview") let webview = app.staticTexts.element(matching: .any, identifier: "webview")
let webviewExists = webview.waitForExistence(timeout: 10) let webviewExists = webview.waitForExistence(timeout: 10)
XCTAssertTrue(webviewExists) if webviewExists {
// Did show recaptcha to the user
// Assumes endpoint and comms are working correctly
print("WEBVIEW DETECTED")
}
else {
let label = app.staticTexts.element(matching: .any, identifier: "resultLabel")
_ = label.waitForExistence(timeout: 10)
XCTAssertFalse(label.label.isEmpty)
// Did automatically resolve the challenge
// Endpoint and comms are working correctly
print("LABEL WITH CONTENT")
}
} }
} }

View File

@ -1,4 +1,4 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'fastlane', '~> 2.105.2' gem 'fastlane', '~> 2.75'
gem 'cocoapods', '~> 1.5.3' gem 'cocoapods', '~> 1.4'

View File

@ -1,7 +1,7 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
CFPropertyList (3.0.0) CFPropertyList (2.3.6)
activesupport (4.2.10) activesupport (4.2.10)
i18n (~> 0.7) i18n (~> 0.7)
minitest (~> 5.1) minitest (~> 5.1)
@ -9,15 +9,14 @@ GEM
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.5.2) addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0) public_suffix (>= 2.0.2, < 4.0)
atomos (0.1.3)
babosa (1.0.2) babosa (1.0.2)
claide (1.0.2) claide (1.0.2)
cocoapods (1.5.3) cocoapods (1.4.0)
activesupport (>= 4.0.2, < 5) activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0) claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.5.3) cocoapods-core (= 1.4.0)
cocoapods-deintegrate (>= 1.0.2, < 2.0) cocoapods-deintegrate (>= 1.0.2, < 2.0)
cocoapods-downloader (>= 1.2.0, < 2.0) cocoapods-downloader (>= 1.1.3, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0) cocoapods-stats (>= 1.0.0, < 2.0)
@ -27,61 +26,59 @@ GEM
escape (~> 0.0.4) escape (~> 0.0.4)
fourflusher (~> 2.0.1) fourflusher (~> 2.0.1)
gh_inspector (~> 1.0) gh_inspector (~> 1.0)
molinillo (~> 0.6.5) molinillo (~> 0.6.4)
nap (~> 1.0) nap (~> 1.0)
ruby-macho (~> 1.1) ruby-macho (~> 1.1)
xcodeproj (>= 1.5.7, < 2.0) xcodeproj (>= 1.5.4, < 2.0)
cocoapods-core (1.5.3) cocoapods-core (1.4.0)
activesupport (>= 4.0.2, < 6) activesupport (>= 4.0.2, < 6)
fuzzy_match (~> 2.0.4) fuzzy_match (~> 2.0.4)
nap (~> 1.0) nap (~> 1.0)
cocoapods-deintegrate (1.0.2) cocoapods-deintegrate (1.0.2)
cocoapods-downloader (1.2.1) cocoapods-downloader (1.1.3)
cocoapods-plugins (1.0.0) cocoapods-plugins (1.0.0)
nap nap
cocoapods-search (1.0.0) cocoapods-search (1.0.0)
cocoapods-stats (1.0.0) cocoapods-stats (1.0.0)
cocoapods-trunk (1.3.1) cocoapods-trunk (1.3.0)
nap (>= 0.8, < 2.0) nap (>= 0.8, < 2.0)
netrc (~> 0.11) netrc (~> 0.11)
cocoapods-try (1.1.0) cocoapods-try (1.1.0)
colored (1.2) colored (1.2)
colored2 (3.1.2) colored2 (3.1.2)
commander-fastlane (4.4.6) commander-fastlane (4.4.5)
highline (~> 1.7.2) highline (~> 1.7.2)
concurrent-ruby (1.0.5) concurrent-ruby (1.0.5)
declarative (0.0.10) declarative (0.0.10)
declarative-option (0.1.0) declarative-option (0.1.0)
domain_name (0.5.20180417) domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
dotenv (2.5.0) dotenv (2.2.1)
emoji_regex (0.1.1)
escape (0.0.4) escape (0.0.4)
excon (0.62.0) excon (0.60.0)
faraday (0.15.3) faraday (0.13.1)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6) faraday-cookie_jar (0.0.6)
faraday (>= 0.7.4) faraday (>= 0.7.4)
http-cookie (~> 1.0.0) http-cookie (~> 1.0.0)
faraday_middleware (0.12.2) faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0) faraday (>= 0.7.4, < 1.0)
fastimage (2.1.4) fastimage (2.1.1)
fastlane (2.105.2) fastlane (2.75.1)
CFPropertyList (>= 2.3, < 4.0.0) CFPropertyList (>= 2.3, < 3.0.0)
addressable (>= 2.3, < 3.0.0) addressable (>= 2.3, < 3.0.0)
babosa (>= 1.0.2, < 2.0.0) babosa (>= 1.0.2, < 2.0.0)
bundler (>= 1.12.0, < 2.0.0) bundler (>= 1.12.0, < 2.0.0)
colored colored
commander-fastlane (>= 4.4.6, < 5.0.0) commander-fastlane (>= 4.4.5, < 5.0.0)
dotenv (>= 2.1.1, < 3.0.0) dotenv (>= 2.1.1, < 3.0.0)
emoji_regex (~> 0.1)
excon (>= 0.45.0, < 1.0.0) excon (>= 0.45.0, < 1.0.0)
faraday (~> 0.9) faraday (~> 0.9)
faraday-cookie_jar (~> 0.0.6) faraday-cookie_jar (~> 0.0.6)
faraday_middleware (~> 0.9) faraday_middleware (~> 0.9)
fastimage (>= 2.1.0, < 3.0.0) fastimage (>= 2.1.0, < 3.0.0)
gh_inspector (>= 1.1.2, < 2.0.0) gh_inspector (>= 1.0.1, < 2.0.0)
google-api-client (>= 0.21.2, < 0.24.0) google-api-client (>= 0.13.1, < 0.14.0)
highline (>= 1.7.2, < 2.0.0) highline (>= 1.7.2, < 2.0.0)
json (< 3.0.0) json (< 3.0.0)
mini_magick (~> 4.5.1) mini_magick (~> 4.5.1)
@ -90,102 +87,100 @@ GEM
multipart-post (~> 2.0.0) multipart-post (~> 2.0.0)
plist (>= 3.1.0, < 4.0.0) plist (>= 3.1.0, < 4.0.0)
public_suffix (~> 2.0.0) public_suffix (~> 2.0.0)
rubyzip (>= 1.2.2, < 2.0.0) rubyzip (>= 1.1.0, < 2.0.0)
security (= 0.1.3) security (= 0.1.3)
simctl (~> 1.6.3) slack-notifier (>= 1.3, < 2.0.0)
slack-notifier (>= 2.0.0, < 3.0.0)
terminal-notifier (>= 1.6.2, < 2.0.0) terminal-notifier (>= 1.6.2, < 2.0.0)
terminal-table (>= 1.4.5, < 2.0.0) terminal-table (>= 1.4.5, < 2.0.0)
tty-screen (>= 0.6.3, < 1.0.0) tty-screen (>= 0.6.3, < 1.0.0)
tty-spinner (>= 0.8.0, < 1.0.0) tty-spinner (>= 0.7.0, < 1.0.0)
word_wrap (~> 1.0.0) word_wrap (~> 1.0.0)
xcodeproj (>= 1.6.0, < 2.0.0) xcodeproj (>= 1.5.2, < 2.0.0)
xcpretty (~> 0.3.0) xcpretty (>= 0.2.4, < 1.0.0)
xcpretty-travis-formatter (>= 0.0.3) xcpretty-travis-formatter (>= 0.0.3)
fourflusher (2.0.1) fourflusher (2.0.1)
fuzzy_match (2.0.4) fuzzy_match (2.0.4)
gh_inspector (1.1.3) gh_inspector (1.0.3)
google-api-client (0.23.9) google-api-client (0.13.6)
addressable (~> 2.5, >= 2.5.1) addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.5, < 0.7.0) googleauth (~> 0.5)
httpclient (>= 2.8.1, < 3.0) httpclient (>= 2.8.1, < 3.0)
mime-types (~> 3.0) mime-types (~> 3.0)
representable (~> 3.0) representable (~> 3.0)
retriable (>= 2.0, < 4.0) retriable (>= 2.0, < 4.0)
signet (~> 0.9) googleauth (0.6.2)
googleauth (0.6.6)
faraday (~> 0.12) faraday (~> 0.12)
jwt (>= 1.4, < 3.0) jwt (>= 1.4, < 3.0)
logging (~> 2.0)
memoist (~> 0.12) memoist (~> 0.12)
multi_json (~> 1.11) multi_json (~> 1.11)
os (>= 0.9, < 2.0) os (~> 0.9)
signet (~> 0.7) signet (~> 0.7)
highline (1.7.10) highline (1.7.10)
http-cookie (1.0.3) http-cookie (1.0.3)
domain_name (~> 0.5) domain_name (~> 0.5)
httpclient (2.8.3) httpclient (2.8.3)
i18n (0.9.5) i18n (0.9.1)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
json (2.1.0) json (2.1.0)
jwt (2.1.0) jwt (2.1.0)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
memoist (0.16.0) memoist (0.16.0)
mime-types (3.2.2) mime-types (3.1)
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812) mime-types-data (3.2016.0521)
mini_magick (4.5.1) mini_magick (4.5.1)
minitest (5.11.3) minitest (5.11.1)
molinillo (0.6.6) molinillo (0.6.4)
multi_json (1.13.1) multi_json (1.13.0)
multi_xml (0.6.0) multi_xml (0.6.0)
multipart-post (2.0.0) multipart-post (2.0.0)
nanaimo (0.2.6) nanaimo (0.2.3)
nap (1.1.0) nap (1.1.0)
naturally (2.2.0)
netrc (0.11.0) netrc (0.11.0)
os (1.0.0) os (0.9.6)
plist (3.4.0) plist (3.4.0)
public_suffix (2.0.5) public_suffix (2.0.5)
representable (3.0.4) representable (3.0.4)
declarative (< 0.1.0) declarative (< 0.1.0)
declarative-option (< 0.2.0) declarative-option (< 0.2.0)
uber (< 0.2.0) uber (< 0.2.0)
retriable (3.1.2) retriable (3.1.1)
rouge (2.0.7) rouge (2.0.7)
ruby-macho (1.2.0) ruby-macho (1.1.0)
rubyzip (1.2.2) rubyzip (1.2.1)
security (0.1.3) security (0.1.3)
signet (0.10.0) signet (0.8.1)
addressable (~> 2.3) addressable (~> 2.3)
faraday (~> 0.9) faraday (~> 0.9)
jwt (>= 1.5, < 3.0) jwt (>= 1.5, < 3.0)
multi_json (~> 1.10) multi_json (~> 1.10)
simctl (1.6.5) slack-notifier (1.5.1)
CFPropertyList
naturally
slack-notifier (2.3.2)
terminal-notifier (1.8.0) terminal-notifier (1.8.0)
terminal-table (1.8.0) terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1) unicode-display_width (~> 1.1, >= 1.1.1)
thread_safe (0.3.6) thread_safe (0.3.6)
tty-cursor (0.6.0) tty-cursor (0.5.0)
tty-screen (0.6.5) tty-screen (0.6.4)
tty-spinner (0.8.0) tty-spinner (0.7.0)
tty-cursor (>= 0.5.0) tty-cursor (>= 0.5.0)
tzinfo (1.2.5) tzinfo (1.2.4)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uber (0.1.0) uber (0.1.0)
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.7.5) unf_ext (0.0.7.4)
unicode-display_width (1.4.0) unicode-display_width (1.3.0)
word_wrap (1.0.0) word_wrap (1.0.0)
xcodeproj (1.6.0) xcodeproj (1.5.4)
CFPropertyList (>= 2.3.3, < 4.0) CFPropertyList (~> 2.3.3)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0) claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1) colored2 (~> 3.1)
nanaimo (~> 0.2.6) nanaimo (~> 0.2.3)
xcpretty (0.3.0) xcpretty (0.2.8)
rouge (~> 2.0.7) rouge (~> 2.0.7)
xcpretty-travis-formatter (1.0.0) xcpretty-travis-formatter (1.0.0)
xcpretty (~> 0.2, >= 0.0.7) xcpretty (~> 0.2, >= 0.0.7)
@ -194,8 +189,8 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
cocoapods (~> 1.5.3) cocoapods (~> 1.4)
fastlane (~> 2.105.2) fastlane (~> 2.75)
BUNDLED WITH BUNDLED WITH
1.16.1 1.16.0

View File

@ -9,7 +9,7 @@
----- -----
Add Google's [Invisible ReCaptcha v2](https://developers.google.com/recaptcha/docs/invisible) to your project. This library Add Google's [Invisible ReCaptcha](https://developers.google.com/recaptcha/docs/invisible) to your project. This library
automatically handles ReCaptcha's events and retrieves the validation token or notifies you to present the challenge if automatically handles ReCaptcha's events and retrieves the validation token or notifies you to present the challenge if
invisibility is not possible. invisibility is not possible.
@ -17,15 +17,8 @@ invisibility is not possible.
#### _Warning_ ⚠️ #### _Warning_ ⚠️
Beware that this library only works for ReCaptcha v2 Invisible keys! Make sure to check the reCAPTCHA Beware that this library only works for Invisible ReCaptcha keys! Make sure to check the Invisible reCAPTCHA option
v2 Invisible badge option when creating your [API Key](https://www.google.com/recaptcha/admin/create). when creating your [API Key](https://www.google.com/recaptcha/admin).
![ReCaptcha v2 invisible key example](https://raw.githubusercontent.com/fjcaetano/ReCaptcha/master/example-v2-key.png)
You won't be able to use a ReCaptcha v3 key because it requires server-side validation. On v3, all
challenges succeed into a token which is then validated in the server for a score. For this reason,
a frontend app can't know on its own wether or not a user is valid since the challenge will always
result in a valid token.
## Installation ## Installation
@ -49,7 +42,7 @@ extension for the ReCaptcha framework.
## Usage ## Usage
Simply add `ReCaptchaKey` and `ReCaptchaDomain` (with a protocol ex. http:// or https://) to your Info.plist and run: Simply add `ReCaptchaKey` and `ReCaptchaDomain` (with a protocol) to your Info.plist and run:
``` swift ``` swift
let recaptcha = try? ReCaptcha() let recaptcha = try? ReCaptcha()
@ -64,7 +57,7 @@ override func viewDidLoad() {
func validate() { func validate() {
recaptcha?.validate(on: view) { [weak self] (result: ReCaptchaResult) in recaptcha?.validate(on: view) { [weak self] result in
print(try? result.dematerialize()) print(try? result.dematerialize())
} }
} }
@ -74,6 +67,7 @@ You can also install the reactive subpod and use it with RxSwift:
``` swift ``` swift
recaptcha.rx.validate(on: view) recaptcha.rx.validate(on: view)
.map { try $0.dematerialize() }
.subscribe(onNext: { (token: String) in .subscribe(onNext: { (token: String) in
// Do something // Do something
}) })
@ -92,13 +86,6 @@ public enum Endpoint {
let recaptcha = try? ReCaptcha(endpoint: .alternate) // Defaults to `default` when unset let recaptcha = try? ReCaptcha(endpoint: .alternate) // Defaults to `default` when unset
``` ```
## Help Wanted
Do you love ReCaptcha and work actively on apps that use it? We'd love if you could help us keep improving it!
Feel free to message us or to start contributing right away!
## [Full Documentation](http://fjcaetano.github.io/ReCaptcha)
## License ## License
ReCaptcha is available under the MIT license. See the LICENSE file for more info. ReCaptcha is available under the MIT license. See the LICENSE file for more info.

View File

@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
F206BAB51F8D3DE900A25807 /* ReCaptcha-Carthage.h in Headers */ = {isa = PBXBuildFile; fileRef = F206BAB31F8D3DE900A25807 /* ReCaptcha-Carthage.h */; settings = {ATTRIBUTES = (Public, ); }; }; F206BAB51F8D3DE900A25807 /* ReCaptcha-Carthage.h in Headers */ = {isa = PBXBuildFile; fileRef = F206BAB31F8D3DE900A25807 /* ReCaptcha-Carthage.h */; settings = {ATTRIBUTES = (Public, ); }; };
F206BAD31F8D3E7600A25807 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F206BAD21F8D3E7600A25807 /* Result.framework */; };
F206BB1D1F8D4DBC00A25807 /* ReCaptcha_RxSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = F206BB1B1F8D4DBC00A25807 /* ReCaptcha_RxSwift.h */; settings = {ATTRIBUTES = (Public, ); }; }; F206BB1D1F8D4DBC00A25807 /* ReCaptcha_RxSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = F206BB1B1F8D4DBC00A25807 /* ReCaptcha_RxSwift.h */; settings = {ATTRIBUTES = (Public, ); }; };
F206BB221F8D4DDF00A25807 /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F206BB121F8D4D1400A25807 /* RxSwift.framework */; }; F206BB221F8D4DDF00A25807 /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F206BB121F8D4D1400A25807 /* RxSwift.framework */; };
F231B39A1FEC51C800F82943 /* DispatchQueue+Throttle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F231B3991FEC51C800F82943 /* DispatchQueue+Throttle.swift */; }; F231B39A1FEC51C800F82943 /* DispatchQueue+Throttle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F231B3991FEC51C800F82943 /* DispatchQueue+Throttle.swift */; };
@ -18,7 +19,7 @@
F24EA1E51F968403001DEC17 /* ReCaptchaError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F24EA1DB1F9683F5001DEC17 /* ReCaptchaError.swift */; }; F24EA1E51F968403001DEC17 /* ReCaptchaError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F24EA1DB1F9683F5001DEC17 /* ReCaptchaError.swift */; };
F24EA1E61F968403001DEC17 /* ReCaptcha.swift in Sources */ = {isa = PBXBuildFile; fileRef = F24EA1DE1F9683F5001DEC17 /* ReCaptcha.swift */; }; F24EA1E61F968403001DEC17 /* ReCaptcha.swift in Sources */ = {isa = PBXBuildFile; fileRef = F24EA1DE1F9683F5001DEC17 /* ReCaptcha.swift */; };
F24EA1E71F968406001DEC17 /* recaptcha.html in Resources */ = {isa = PBXBuildFile; fileRef = F24EA1E01F9683F5001DEC17 /* recaptcha.html */; }; F24EA1E71F968406001DEC17 /* recaptcha.html in Resources */ = {isa = PBXBuildFile; fileRef = F24EA1E01F9683F5001DEC17 /* recaptcha.html */; };
F2AE8614204F3B42002E28D7 /* ReCaptchaResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2AE8613204F3B41002E28D7 /* ReCaptchaResult.swift */; }; F255FBEC1F8D5654002F5FA8 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F255FBEB1F8D5654002F5FA8 /* Result.framework */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -36,6 +37,7 @@
F206BAB31F8D3DE900A25807 /* ReCaptcha-Carthage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ReCaptcha-Carthage.h"; sourceTree = "<group>"; }; F206BAB31F8D3DE900A25807 /* ReCaptcha-Carthage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ReCaptcha-Carthage.h"; sourceTree = "<group>"; };
F206BAB41F8D3DE900A25807 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; F206BAB41F8D3DE900A25807 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F206BACF1F8D3E2800A25807 /* Cartfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Cartfile; sourceTree = "<group>"; }; F206BACF1F8D3E2800A25807 /* Cartfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Cartfile; sourceTree = "<group>"; };
F206BAD21F8D3E7600A25807 /* Result.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Result.framework; path = Carthage/Build/iOS/Result.framework; sourceTree = "<group>"; };
F206BB121F8D4D1400A25807 /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/iOS/RxSwift.framework; sourceTree = "<group>"; }; F206BB121F8D4D1400A25807 /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/iOS/RxSwift.framework; sourceTree = "<group>"; };
F206BB191F8D4DBC00A25807 /* ReCaptcha_RxSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ReCaptcha_RxSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; F206BB191F8D4DBC00A25807 /* ReCaptcha_RxSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ReCaptcha_RxSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F206BB1B1F8D4DBC00A25807 /* ReCaptcha_RxSwift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReCaptcha_RxSwift.h; sourceTree = "<group>"; }; F206BB1B1F8D4DBC00A25807 /* ReCaptcha_RxSwift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReCaptcha_RxSwift.h; sourceTree = "<group>"; };
@ -48,7 +50,7 @@
F24EA1DD1F9683F5001DEC17 /* ReCaptcha+Rx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ReCaptcha+Rx.swift"; sourceTree = "<group>"; }; F24EA1DD1F9683F5001DEC17 /* ReCaptcha+Rx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ReCaptcha+Rx.swift"; sourceTree = "<group>"; };
F24EA1DE1F9683F5001DEC17 /* ReCaptcha.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReCaptcha.swift; sourceTree = "<group>"; }; F24EA1DE1F9683F5001DEC17 /* ReCaptcha.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReCaptcha.swift; sourceTree = "<group>"; };
F24EA1E01F9683F5001DEC17 /* recaptcha.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = recaptcha.html; sourceTree = "<group>"; }; F24EA1E01F9683F5001DEC17 /* recaptcha.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = recaptcha.html; sourceTree = "<group>"; };
F2AE8613204F3B41002E28D7 /* ReCaptchaResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReCaptchaResult.swift; sourceTree = "<group>"; }; F255FBEB1F8D5654002F5FA8 /* Result.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Result.framework; path = "../ReCaptcha Carthage Test/Carthage/Build/iOS/Result.framework"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -56,6 +58,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
F206BAD31F8D3E7600A25807 /* Result.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -64,6 +67,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
F206BB221F8D4DDF00A25807 /* RxSwift.framework in Frameworks */, F206BB221F8D4DDF00A25807 /* RxSwift.framework in Frameworks */,
F255FBEC1F8D5654002F5FA8 /* Result.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -104,7 +108,9 @@
F206BAD11F8D3E7600A25807 /* Frameworks */ = { F206BAD11F8D3E7600A25807 /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
F255FBEB1F8D5654002F5FA8 /* Result.framework */,
F206BB121F8D4D1400A25807 /* RxSwift.framework */, F206BB121F8D4D1400A25807 /* RxSwift.framework */,
F206BAD21F8D3E7600A25807 /* Result.framework */,
); );
name = Frameworks; name = Frameworks;
sourceTree = "<group>"; sourceTree = "<group>";
@ -141,7 +147,6 @@
F24EA1D91F9683F5001DEC17 /* ReCaptchaWebViewManager.swift */, F24EA1D91F9683F5001DEC17 /* ReCaptchaWebViewManager.swift */,
F24EA1DA1F9683F5001DEC17 /* String+Dict.swift */, F24EA1DA1F9683F5001DEC17 /* String+Dict.swift */,
F24EA1DB1F9683F5001DEC17 /* ReCaptchaError.swift */, F24EA1DB1F9683F5001DEC17 /* ReCaptchaError.swift */,
F2AE8613204F3B41002E28D7 /* ReCaptchaResult.swift */,
F231B3991FEC51C800F82943 /* DispatchQueue+Throttle.swift */, F231B3991FEC51C800F82943 /* DispatchQueue+Throttle.swift */,
F24EA1DC1F9683F5001DEC17 /* Rx */, F24EA1DC1F9683F5001DEC17 /* Rx */,
F24EA1DE1F9683F5001DEC17 /* ReCaptcha.swift */, F24EA1DE1F9683F5001DEC17 /* ReCaptcha.swift */,
@ -286,7 +291,6 @@
files = ( files = (
F24EA1E51F968403001DEC17 /* ReCaptchaError.swift in Sources */, F24EA1E51F968403001DEC17 /* ReCaptchaError.swift in Sources */,
F24EA1E21F968403001DEC17 /* ReCaptchaDecoder.swift in Sources */, F24EA1E21F968403001DEC17 /* ReCaptchaDecoder.swift in Sources */,
F2AE8614204F3B42002E28D7 /* ReCaptchaResult.swift in Sources */,
F24EA1E61F968403001DEC17 /* ReCaptcha.swift in Sources */, F24EA1E61F968403001DEC17 /* ReCaptcha.swift in Sources */,
F24EA1E31F968403001DEC17 /* ReCaptchaWebViewManager.swift in Sources */, F24EA1E31F968403001DEC17 /* ReCaptchaWebViewManager.swift in Sources */,
F24EA1E41F968403001DEC17 /* String+Dict.swift in Sources */, F24EA1E41F968403001DEC17 /* String+Dict.swift in Sources */,
@ -367,7 +371,6 @@
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
@ -420,7 +423,6 @@
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
@ -446,7 +448,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.flaviocaetano.ReCaptcha; PRODUCT_BUNDLE_IDENTIFIER = com.flaviocaetano.ReCaptcha;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2; SWIFT_VERSION = 3.0;
}; };
name = Debug; name = Debug;
}; };
@ -468,7 +470,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.flaviocaetano.ReCaptcha; PRODUCT_BUNDLE_IDENTIFIER = com.flaviocaetano.ReCaptcha;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2; SWIFT_VERSION = 3.0;
}; };
name = Release; name = Release;
}; };
@ -492,7 +494,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-RxSwift"; PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-RxSwift";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2; SWIFT_VERSION = 3.0;
}; };
name = Debug; name = Debug;
}; };
@ -516,7 +518,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-RxSwift"; PRODUCT_BUNDLE_IDENTIFIER = "com.flaviocaetano.ReCaptcha-RxSwift";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2; SWIFT_VERSION = 3.0;
}; };
name = Release; name = Release;
}; };

View File

@ -1,22 +1,20 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'ReCaptcha' s.name = 'ReCaptcha'
s.version = '1.4.2' s.version = '1.1'
s.summary = 'ReCaptcha for iOS' s.summary = 'ReCaptcha for iOS'
s.swift_version = '4.2'
s.description = <<-DESC s.description = <<-DESC
Add Google's [Invisible ReCaptcha](https://developers.google.com/recaptcha/docs/invisible) to your project. This library Add Google's [Invisible ReCaptcha](https://developers.google.com/recaptcha/docs/invisible) to your project. This library
automatically handles ReCaptcha's events and retrieves the validation token or notifies you to present the challenge if automatically handles ReCaptcha's events and retrieves the validation token or notifies you to present the challenge if
invisibility is not possible. invisibility is not possible.
DESC DESC
s.homepage = 'https://github.com/fjcaetano/ReCaptcha' s.homepage = 'https://github.com/fjcaetano/ReCaptcha'
s.license = { :type => 'MIT', :file => 'LICENSE' } s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Flávio Caetano' => 'flavio@vieiracaetano.com' } s.author = { 'Flávio Caetano' => 'flavio@vieiracaetano.com' }
s.source = { :git => 'https://github.com/fjcaetano/ReCaptcha.git', :tag => s.version.to_s } s.source = { :git => 'https://github.com/fjcaetano/ReCaptcha.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/flavio_caetano' s.social_media_url = 'https://twitter.com/flavio_caetano'
s.documentation_url = 'http://fjcaetano.github.io/ReCaptcha'
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
s.default_subspecs = 'Core' s.default_subspecs = 'Core'
@ -24,6 +22,7 @@ invisibility is not possible.
s.subspec 'Core' do |core| s.subspec 'Core' do |core|
core.source_files = 'ReCaptcha/Classes/*' core.source_files = 'ReCaptcha/Classes/*'
core.frameworks = 'WebKit' core.frameworks = 'WebKit'
core.dependency 'Result', '~> 3.0'
core.resource_bundles = { core.resource_bundles = {
'ReCaptcha' => ['ReCaptcha/Assets/**/*'] 'ReCaptcha' => ['ReCaptcha/Assets/**/*']
@ -33,6 +32,6 @@ invisibility is not possible.
s.subspec 'RxSwift' do |rx| s.subspec 'RxSwift' do |rx|
rx.source_files = 'ReCaptcha/Classes/Rx/**/*' rx.source_files = 'ReCaptcha/Classes/Rx/**/*'
rx.dependency 'ReCaptcha/Core' rx.dependency 'ReCaptcha/Core'
rx.dependency 'RxSwift', '~> 4.3' rx.dependency 'RxSwift', '~> 4.0'
end end
end end

View File

@ -2,19 +2,6 @@
<head> <head>
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<script type="text/javascript"> <script type="text/javascript">
var post = function(value) {
window.webkit.messageHandlers.recaptcha.postMessage(value);
};
console.log = function(message) {
post({log: message});
};
var showReCaptcha = function() {
console.log("showReCaptcha");
post({action: "showReCaptcha"});
};
var observeDOM = function(element, completion) { var observeDOM = function(element, completion) {
new MutationObserver(function(mutations) { new MutationObserver(function(mutations) {
mutations.forEach(function(mutationRecord) { mutations.forEach(function(mutationRecord) {
@ -25,8 +12,6 @@
}; };
var execute = function() { var execute = function() {
console.log("executing");
// Removes ReCaptcha dismissal when clicking outside div area // Removes ReCaptcha dismissal when clicking outside div area
try { try {
document.getElementsByTagName("div")[4].outerHTML = "" document.getElementsByTagName("div")[4].outerHTML = ""
@ -35,29 +20,26 @@
} }
// Listens to changes on the div element that presents the ReCaptcha challenge // Listens to changes on the div element that presents the ReCaptcha challenge
observeDOM(document.getElementsByTagName("div")[3], showReCaptcha); observeDOM(document.getElementsByTagName("div")[3], function() {
console.log({action: "showReCaptcha"});
window.webkit.messageHandlers.recaptcha.postMessage({action: "showReCaptcha"});
});
grecaptcha.execute(); grecaptcha.execute();
}; }
var onSubmit = function(token) { var onSubmit = function(token) {
console.log(token); console.log(token);
post({token: token}); window.webkit.messageHandlers.recaptcha.postMessage({token: token});
}; };
var onloadCallback = function() { var onloadCallback = function() {
console.log("did load");
grecaptcha.render('submit', { grecaptcha.render('submit', {
'sitekey' : '${apiKey}', 'sitekey' : '${apiKey}',
'callback' : onSubmit, 'callback' : onSubmit,
'size': 'invisible' 'size': 'invisible'
}); });
}; };
var reset = function() {
console.log("resetting");
grecaptcha.reset();
};
</script> </script>
</head> </head>
<body> <body>

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 21/12/17. // Created by Flávio Caetano on 21/12/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import Foundation import Foundation
@ -13,12 +13,6 @@ extension DispatchQueue {
/// Stores a throttle DispatchWorkItem instance for a given context /// Stores a throttle DispatchWorkItem instance for a given context
private static var workItems = [AnyHashable: DispatchWorkItem]() private static var workItems = [AnyHashable: DispatchWorkItem]()
/// Stores the last call times for a given context
private static var lastDebounceCallTimes = [AnyHashable: DispatchTime]()
/// Dispatched actions' token storage
private static var onceTokenStorage = Set<AnyHashable>()
/// An object representing a context if none is given /// An object representing a context if none is given
private static let nilContext = UUID() private static let nilContext = UUID()
@ -41,44 +35,4 @@ extension DispatchQueue {
DispatchQueue.workItems[context]?.cancel() DispatchQueue.workItems[context]?.cancel()
DispatchQueue.workItems[context] = worker DispatchQueue.workItems[context] = worker
} }
/**
- parameters:
- interval: The interval in which new calls will be ignored
- context: The context in which the debounce should be executed
- action: The closure to be executed
Executes a closure and ensures no other executions will be made during the interval.
*/
func debounce(interval: Double, context: AnyHashable = nilContext, action: @escaping () -> Void) {
let now = DispatchTime.now()
if let last = DispatchQueue.lastDebounceCallTimes[context], last + interval > now {
return
}
DispatchQueue.lastDebounceCallTimes[context] = now + interval
async(execute: action)
// Cleanup & release context
throttle(deadline: now + interval) {
DispatchQueue.lastDebounceCallTimes.removeValue(forKey: context)
}
}
/**
- parameters:
- token: The control token for each dispatched action
- action: The closure to be executed
Dispatch the action only once for each given token
*/
static func once(token: AnyHashable, action: () -> Void) {
guard !onceTokenStorage.contains(token) else { return }
defer { objc_sync_exit(self) }
objc_sync_enter(self)
onceTokenStorage.insert(token)
action()
}
} }

View File

@ -3,18 +3,16 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 22/03/17. // Created by Flávio Caetano on 22/03/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import Foundation import Foundation
import WebKit import WebKit
/** /** The public facade of ReCaptcha
*/ */
public class ReCaptcha { open class ReCaptcha: ReCaptchaWebViewManager {
public typealias BoolParameterClosure = (Bool) -> ()
fileprivate struct Constants { fileprivate struct Constants {
struct InfoDictKeys { struct InfoDictKeys {
static let APIKey = "ReCaptchaKey" static let APIKey = "ReCaptchaKey"
@ -25,21 +23,17 @@ public class ReCaptcha {
/// The JS API endpoint to be loaded onto the HTML file. /// The JS API endpoint to be loaded onto the HTML file.
public enum Endpoint { public enum Endpoint {
/** Google's default endpoint. Points to /** Google's default endpoint. Points to
https://www.google.com/recaptcha/api.js https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit
*/ */
case `default` case `default`
/// Alternate endpoint. Points to https://www.recaptcha.net/recaptcha/api.js /// Alternate endpoint. Points to https://www.recaptcha.net/recaptcha/api.js
case alternate case alternate
internal func getURL(locale: Locale?) -> String { fileprivate var url: String {
let localeAppendix = locale.map { "&hl=\($0.identifier)" } ?? ""
switch self { switch self {
case .default: case .default: return "https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
return "https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" + localeAppendix case .alternate: return "https://www.recaptcha.net/recaptcha/api.js?onload=onloadCallback&render=explicit"
case .alternate:
return "https://www.recaptcha.net/recaptcha/api.js?onload=onloadCallback&render=explicit"
+ localeAppendix
} }
} }
} }
@ -103,22 +97,12 @@ public class ReCaptcha {
} }
} }
/// Callback for WebView loading state changing
public var onLoadingChanged: BoolParameterClosure? {
get { return manager.onLoadingChanged }
set { manager.onLoadingChanged = newValue }
}
/// The worker that handles webview events and communication
let manager: ReCaptchaWebViewManager
/** /**
- parameters: - parameters:
- apiKey: The API key sent to the ReCaptcha init - apiKey: The API key sent to the ReCaptcha init
- infoPlistKey: The API key retrived from the application's Info.plist - infoPlistKey: The API key retrived from the application's Info.plist
- baseURL: The base URL sent to the ReCaptcha init - baseURL: The base URL sent to the ReCaptcha init
- infoPlistURL: The base URL retrieved from the application's Info.plist - infoPlistURL: The base URL retrieved from the application's Info.plist
- locale: A locale value to translate ReCaptcha into a different language
Initializes a ReCaptcha object Initializes a ReCaptcha object
@ -134,100 +118,15 @@ public class ReCaptcha {
Info.plist. Info.plist.
- Throws: Rethrows any exceptions thrown by `String(contentsOfFile:)` - Throws: Rethrows any exceptions thrown by `String(contentsOfFile:)`
*/ */
public convenience init( public init(apiKey: String? = nil, baseURL: URL? = nil, endpoint: Endpoint = .default) throws {
apiKey: String? = nil,
baseURL: URL? = nil,
endpoint: Endpoint = .default,
locale: Locale? = nil
) throws {
let infoDict = Bundle.main.infoDictionary let infoDict = Bundle.main.infoDictionary
let plistApiKey = infoDict?[Constants.InfoDictKeys.APIKey] as? String let plistApiKey = infoDict?[Constants.InfoDictKeys.APIKey] as? String
let plistDomain = (infoDict?[Constants.InfoDictKeys.Domain] as? String).flatMap(URL.init(string:)) let plistDomain = (infoDict?[Constants.InfoDictKeys.Domain] as? String).flatMap(URL.init(string:))
let config = try Config(apiKey: apiKey, infoPlistKey: plistApiKey, baseURL: baseURL, infoPlistURL: plistDomain) let config = try Config(apiKey: apiKey, infoPlistKey: plistApiKey, baseURL: baseURL, infoPlistURL: plistDomain)
super.init(html: config.html, apiKey: config.apiKey, baseURL: config.baseURL, endpoint: endpoint.url)
self.init(manager: ReCaptchaWebViewManager(
html: config.html,
apiKey: config.apiKey,
baseURL: config.baseURL,
endpoint: endpoint.getURL(locale: locale)
))
} }
/**
- parameter manager: A ReCaptchaWebViewManager instance.
Initializes ReCaptcha with the given manager
*/
init(manager: ReCaptchaWebViewManager) {
self.manager = manager
}
/**
- parameters:
- view: The view that should present the webview.
- resetOnError: If ReCaptcha should be reset if it errors. Defaults to `true`.
- completion: A closure that receives a ReCaptchaResult which may contain a valid result token.
Starts the challenge validation
*/
public func validate(on view: UIView, resetOnError: Bool = true, completion: @escaping (ReCaptchaResult) -> Void) {
manager.shouldResetOnError = resetOnError
manager.completion = completion
manager.validate(on: view)
}
/// Stops the execution of the webview
public func stop() {
manager.stop()
}
/**
- parameter configure: A closure that receives an instance of `WKWebView` for configuration.
Provides a closure to configure the webview for presentation if necessary.
If presentation is required, the webview will already be a subview of `presenterView` if one is provided. Otherwise
it might need to be added in a view currently visible.
*/
public func configureWebView(_ configure: @escaping (WKWebView) -> Void) {
manager.configureWebView = configure
}
/**
Resets the ReCaptcha.
The reset is achieved by calling `grecaptcha.reset()` on the JS API.
*/
public func reset() {
manager.reset()
}
// MARK: - Development
#if DEBUG
/// Forces the challenge widget to be explicitly displayed.
public var forceVisibleChallenge: Bool {
get { return manager.forceVisibleChallenge }
set { manager.forceVisibleChallenge = newValue }
}
/**
Allows validation stubbing for testing
When this property is set to `true`, every call to `validate()` will immediately be resolved with `.token("")`.
Use only when testing your application.
*/
public var shouldSkipForTests: Bool {
get { return manager.shouldSkipForTests }
set { manager.shouldSkipForTests = newValue }
}
#endif
} }
// MARK: - Private Methods // MARK: - Private Methods

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 22/03/17. // Created by Flávio Caetano on 22/03/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import Foundation import Foundation
@ -27,9 +27,6 @@ internal class ReCaptchaDecoder: NSObject {
/// Did finish loading resources /// Did finish loading resources
case didLoad case didLoad
/// Logs a string onto the console
case log(String)
} }
/// The closure that receives messages /// The closure that receives messages
@ -103,10 +100,6 @@ fileprivate extension ReCaptchaDecoder.Result {
} }
} }
if let message = response["log"] as? String {
return .log(message)
}
return .error(.wrongMessageFormat) return .error(.wrongMessageFormat)
} }
} }

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 22/03/17. // Created by Flávio Caetano on 22/03/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import Foundation import Foundation
@ -22,7 +22,7 @@ public enum ReCaptchaError: Error, CustomStringConvertible {
/// ReCaptchaDomain was not provided /// ReCaptchaDomain was not provided
case baseURLNotFound case baseURLNotFound
/// Received an unexpected message from javascript /// Received an unexpeted message from javascript
case wrongMessageFormat case wrongMessageFormat

View File

@ -1,38 +0,0 @@
//
// ReCaptchaWebViewManager.swift
// ReCaptcha
//
// Created by Flávio Caetano on 06/03/17.
// Copyright © 2018 ReCaptcha. All rights reserved.
//
import Foundation
/** The ReCaptcha result.
This may contain the validation token on success, or an error that may have occurred.
*/
public enum ReCaptchaResult {
/// The validation token.
case token(String)
/// An error that may have occurred.
case error(ReCaptchaError)
/**
- returns: The validation token uppon success.
Tries to unwrap the Result and retrieve the token if it's successful.
- Throws: `ReCaptchaError`
*/
public func dematerialize() throws -> String {
switch self {
case .token(let token):
return token
case .error(let error):
throw error
}
}
}

View File

@ -3,99 +3,132 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 22/03/17. // Created by Flávio Caetano on 22/03/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import Foundation import Foundation
import Result
import WebKit import WebKit
/** Handles comunications with the webview containing the ReCaptcha challenge. /** Handles comunications with the webview containing the ReCaptcha challenge.
*/ */
internal class ReCaptchaWebViewManager { open class ReCaptchaWebViewManager {
public typealias Response = Result<String, ReCaptchaError>
fileprivate struct Constants { /** The `webView` delegate object that performs execution uppon script loading
static let ExecuteJSCommand = "execute();" */
static let ResetCommand = "reset();" fileprivate class WebViewDelegate: NSObject, WKNavigationDelegate {
static let BotUserAgent = "Googlebot/2.1" struct Constants {
static let NumberOfDivsCommand = "document.getElementsByTagName(\"div\").length" /// The host that loaded requests should have
static let apiURLHost = "www.google.com"
static let MinNumberOfDivs = 5
static let NumberOfDivsFinishedLoadingAttempts = 10
// A page doesn't have enough time to load on old devices
static let NumberOfDivsLoadingDelay = 0.5
}
#if DEBUG
/// Forces the challenge to be explicitly displayed.
var forceVisibleChallenge = false {
didSet {
// Also works on iOS < 9
webView.performSelector(
onMainThread: "_setCustomUserAgent:",
with: forceVisibleChallenge ? Constants.BotUserAgent : nil,
waitUntilDone: true
)
} }
}
/// Allows validation stubbing for testing /// The parent manager
public var shouldSkipForTests = false private weak var manager: ReCaptchaWebViewManager?
#endif
/// Callback for loading state changing /// The active requests' urls
var onLoadingChanged: ReCaptcha.BoolParameterClosure? private var activeRequests = Set<String>(minimumCapacity: 0)
/// Sends the result message /// - parameter manager: The parent manager
var completion: ((ReCaptchaResult) -> Void)? init(manager: ReCaptchaWebViewManager) {
self.manager = manager
}
/// Configures the webview for display when required /**
var configureWebView: ((WKWebView) -> Void)? - parameters:
- webView: The web view invoking the delegate method.
- navigationAction: Descriptive information about the action triggering the navigation request.
- decisionHandler: The decision handler to call to allow or cancel the navigation. The argument is one of
the constants of the enumerated type WKNavigationActionPolicy.
/// The dispatch token used to ensure `configureWebView` is only called once. Decides whether to allow or cancel a navigation.
var configureWebViewDispatchToken = UUID() */
func webView(
_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy
) -> Void) {
defer { decisionHandler(.allow) }
/// If the ReCaptcha should be reset when it errors if let url = navigationAction.request.url, url.host == Constants.apiURLHost {
var shouldResetOnError = true activeRequests.insert(url.absoluteString)
}
}
/// The JS message recoder /**
fileprivate var decoder: ReCaptchaDecoder! - parameters:
- webView: The web view invoking the delegate method.
- navigationResponse: Descriptive information about the navigation response.
- decisionHandler: A block to be called when your app has decided whether to allow or cancel the navigation
/// Indicates if the script has already been loaded by the `webView` Decides whether to allow or cancel a navigation after its response is known.
fileprivate var didFinishLoading = false { // webView.isLoading does not work for WKWebview.loadHTMLString */
didSet { func webView(
if didFinishLoading && completion != nil { _ webView: WKWebView,
// User has requested for validation decidePolicyFor navigationResponse: WKNavigationResponse,
// A small delay is necessary to allow JS to wrap its operations and avoid errors. decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in ) {
self?.execute() defer { decisionHandler(.allow) }
guard let url = navigationResponse.response.url?.absoluteString,
activeRequests.remove(url) != nil, activeRequests.isEmpty else {
return
}
execute()
}
/// Flag the requests as finished and call ReCaptcha execution if necessary
func execute() {
DispatchQueue.main.throttle(deadline: .now() + 1, context: self) { [weak self] in
// Did finish loading the ReCaptcha JS source
self?.manager?.didFinishLoading = true
if self?.manager?.completion != nil {
// User has requested for validation
self?.manager?.execute()
} }
} }
} }
} }
fileprivate struct Constants {
static let ExecuteJSCommand = "execute();"
}
/// Sends the result message
fileprivate var completion: ((Response) -> Void)?
/// Configures the webview for display when required
fileprivate var configureWebView: ((WKWebView) -> Void)?
/// The JS message recoder
fileprivate var decoder: ReCaptchaDecoder!
/// Indicates if the script has already been loaded by the `webView`
fileprivate var didFinishLoading = false // webView.isLoading does not work in this case
/// The observer for `.UIWindowDidBecomeVisible` /// The observer for `.UIWindowDidBecomeVisible`
fileprivate var observer: NSObjectProtocol? fileprivate var observer: NSObjectProtocol?
/// The observer for `\WKWebView.estimatedProgress`
fileprivate var loadingObservation: NSKeyValueObservation?
/// The endpoint url being used /// The endpoint url being used
fileprivate var endpoint: String fileprivate var endpoint: String
/// The `webView` delegate implementation
fileprivate lazy var webviewDelegate: WebViewDelegate = {
WebViewDelegate(manager: self)
}()
/// The webview that executes JS code /// The webview that executes JS code
lazy var webView: WKWebView = { fileprivate lazy var webView: WKWebView = {
let webview = WKWebView( let webview = WKWebView(
frame: CGRect(x: 0, y: 0, width: 1, height: 1), frame: CGRect(x: 0, y: 0, width: 1, height: 1),
configuration: self.buildConfiguration() configuration: self.buildConfiguration()
) )
webview.navigationDelegate = self.webviewDelegate
webview.accessibilityIdentifier = "webview" webview.accessibilityIdentifier = "webview"
webview.accessibilityTraits = UIAccessibilityTraits.link webview.accessibilityTraits = UIAccessibilityTraitLink
webview.isHidden = true webview.isHidden = true
self.loadingObservation = webview.observe(\.estimatedProgress, options: [.new]) { [weak self] _, change in
self?.didFinishLoading = change.newValue == 1
}
return webview return webview
}() }()
@ -109,7 +142,6 @@ internal class ReCaptchaWebViewManager {
*/ */
init(html: String, apiKey: String, baseURL: URL, endpoint: String) { init(html: String, apiKey: String, baseURL: URL, endpoint: String) {
self.endpoint = endpoint self.endpoint = endpoint
self.decoder = ReCaptchaDecoder { [weak self] result in self.decoder = ReCaptchaDecoder { [weak self] result in
self?.handle(result: result) self?.handle(result: result)
} }
@ -121,7 +153,7 @@ internal class ReCaptchaWebViewManager {
} }
else { else {
observer = NotificationCenter.default.addObserver( observer = NotificationCenter.default.addObserver(
forName: UIWindow.didBecomeVisibleNotification, forName: .UIWindowDidBecomeVisible,
object: nil, object: nil,
queue: nil queue: nil
) { [weak self] notification in ) { [weak self] notification in
@ -131,20 +163,19 @@ internal class ReCaptchaWebViewManager {
} }
} }
/** /**
- parameter view: The view that should present the webview. - parameters:
- view: The view that should present the webview.
- completion: A closure that receives a Result<String, NSError> which may contain a valid result token.
Starts the challenge validation Starts the challenge validation
*/ */
func validate(on view: UIView) { open func validate(on view: UIView, completion: @escaping (Response) -> Void) {
onLoadingChanged?(true) self.completion = completion
#if DEBUG
guard !shouldSkipForTests else {
completion?(.token(""))
return
}
#endif
webView.isHidden = false webView.isHidden = false
webView.removeFromSuperview()
view.addSubview(webView) view.addSubview(webView)
execute() execute()
@ -152,24 +183,21 @@ internal class ReCaptchaWebViewManager {
/// Stops the execution of the webview /// Stops the execution of the webview
func stop() { open func stop() {
webView.stopLoading() webView.stopLoading()
} }
/** /**
Resets the ReCaptcha. - parameter configure: A closure that receives an instance of `WKWebView` for configuration.
The reset is achieved by calling `grecaptcha.reset()` on the JS API. Provides a closure to configure the webview for presentation if necessary.
If presentation is required, the webview will already be a subview of `presenterView` if one is provided. Otherwise
it might need to be added in a view currently visible.
*/ */
func reset() { open func configureWebView(_ configure: @escaping (WKWebView) -> Void) {
didFinishLoading = false self.configureWebView = configure
configureWebViewDispatchToken = UUID()
webView.evaluateJavaScript(Constants.ResetCommand) { [weak self] _, error in
if let error = error {
self?.decoder.send(error: .unexpected(error))
}
}
} }
} }
@ -178,7 +206,8 @@ internal class ReCaptchaWebViewManager {
/** Private methods for ReCaptchaWebViewManager /** Private methods for ReCaptchaWebViewManager
*/ */
fileprivate extension ReCaptchaWebViewManager { fileprivate extension ReCaptchaWebViewManager {
/** Executes the JS command that loads the ReCaptcha challenge after a page finished loading.
/** Executes the JS command that loads the ReCaptcha challenge.
This method has no effect if the webview hasn't finished loading. This method has no effect if the webview hasn't finished loading.
*/ */
func execute() { func execute() {
@ -187,65 +216,10 @@ fileprivate extension ReCaptchaWebViewManager {
return return
} }
evaluateExecuteWhenLoadingFinished(count: 0)
}
/**
- parameter count: Number of checks of number of divs
Executes the JS command that returns number of divs.
*/
func evaluateExecuteWhenLoadingFinished(count: Int) {
webView.evaluateJavaScript(Constants.NumberOfDivsCommand) { [weak self] (result, error) -> Void in
if let error = error {
self?.decoder.send(error: .unexpected(error))
self?.onLoadingChanged?(false)
} else {
self?.handleNumberOfDivs(result: result, count: count)
}
}
}
/**
- parameters:
- result: Result of number of divs command evaluation
- count: Number of checks of divs count
Handles number of divs command result.
*/
func handleNumberOfDivs(result: Any?, count: Int) {
if let result = result as? Int, result >= Constants.MinNumberOfDivs {
evaluateExecute()
} else {
handleInvalidNumberOfDivsResult(count: count)
}
}
/**
- parameter count: Number of checks of number of divs
Handles invalid number of divs.
*/
func handleInvalidNumberOfDivsResult(count: Int) {
if count < Constants.NumberOfDivsFinishedLoadingAttempts {
DispatchQueue.main.asyncAfter(deadline: .now() + Constants.NumberOfDivsLoadingDelay) { [weak self] in
self?.evaluateExecuteWhenLoadingFinished(count: count + 1)
}
} else {
decoder.send(error: .htmlLoadError)
onLoadingChanged?(false)
}
}
/**
Executes the JS command that loads the ReCaptcha challenge.
*/
func evaluateExecute() {
webView.evaluateJavaScript(Constants.ExecuteJSCommand) { [weak self] _, error in webView.evaluateJavaScript(Constants.ExecuteJSCommand) { [weak self] _, error in
if let error = error { if let error = error {
self?.decoder.send(error: .unexpected(error)) self?.decoder.send(error: .unexpected(error))
} }
self?.onLoadingChanged?(false)
} }
} }
@ -272,31 +246,17 @@ fileprivate extension ReCaptchaWebViewManager {
func handle(result: ReCaptchaDecoder.Result) { func handle(result: ReCaptchaDecoder.Result) {
switch result { switch result {
case .token(let token): case .token(let token):
completion?(.token(token)) completion?(.success(token))
case .error(let error): case .error(let error):
if shouldResetOnError, let view = webView.superview { completion?(.failure(error))
reset()
validate(on: view)
}
else {
completion?(.error(error))
}
case .showReCaptcha: case .showReCaptcha:
DispatchQueue.once(token: configureWebViewDispatchToken) { [weak self] in configureWebView?(webView)
guard let `self` = self else { return }
self.configureWebView?(self.webView)
}
case .didLoad: case .didLoad:
// For testing purposes // For testing purposes
didFinishLoading = true webviewDelegate.execute()
case .log(let message):
#if DEBUG
print("[JS LOG]:", message)
#endif
} }
} }

View File

@ -3,85 +3,40 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 11/04/17. // Created by Flávio Caetano on 11/04/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import RxSwift import RxSwift
import UIKit import UIKit
public enum ReCaptchaRxError: Error { /// Makes ReCaptchaWebViewManager compatible with RxSwift extensions
case baseWasReleased extension ReCaptchaWebViewManager: ReactiveCompatible {}
}
/// Makes ReCaptcha compatible with RxSwift extensions /// Provides a public extension on ReCaptchaWebViewManager that makes it reactive.
extension ReCaptcha: ReactiveCompatible {} public extension Reactive where Base: ReCaptchaWebViewManager {
/// Provides a public extension on ReCaptcha that makes it reactive.
public extension Reactive where Base: ReCaptcha {
/** /**
- parameters: - parameter view: The view that should present the webview.
- view: The view that should present the webview.
- resetOnError: If ReCaptcha should be reset if it errors. Defaults to `true`
Starts the challenge validation uppon subscription. Starts the challenge validation uppon subscription.
The stream's element is a String with the validation token. The stream's element is a `Result<String, ReCaptchaError>` that may contain a valid token.
Sends `stop()` uppon disposal. Sends `stop()` uppon disposal.
- See: `ReCaptcha.validate(on:resetOnError:completion:)` - See: `ReCaptchaWebViewManager.validate(on:completion:)`
- See: `ReCaptcha.stop()` - See: `ReCaptchaWebViewManager.stop()`
*/ */
func validate(on view: UIView, resetOnError: Bool = true) -> Observable<String> { func validate(on view: UIView) -> Observable<Base.Response> {
return Single<String>.create { [weak base] single in return Observable<Base.Response>.create { [weak base] (observer: AnyObserver<Base.Response>) in
base?.validate(on: view, resetOnError: resetOnError) { result in base?.validate(on: view) { response in
switch result { observer.onNext(response)
case .token(let token): observer.onCompleted()
single(.success(token))
case .error(let error):
single(.error(error))
}
} }
return Disposables.create { [weak base] in return Disposables.create { [weak base] in
base?.stop() base?.stop()
} }
} }
.asObservable()
}
/**
Resets the ReCaptcha.
The reset is achieved by calling `grecaptcha.reset()` on the JS API.
- See: `ReCaptcha.reset()`
*/
var reset: AnyObserver<Void> {
return AnyObserver { [weak base] event in
guard case .next = event else {
return
}
base?.reset()
}
}
/**
Observable of loading state
(will not work if someone changes onLoadingChanged variable; current onLodinglChanged will not work after subscription)
*/
var loadingObservable: Observable<Bool> {
return .create { [weak base] observer -> Disposable in
guard let base = base else {
observer.onError(ReCaptchaRxError.baseWasReleased)
return Disposables.create()
}
base.onLoadingChanged = { observer.onNext($0) }
return Disposables.create { [weak base] in base?.onLoadingChanged = nil }
}
} }
} }

View File

@ -3,7 +3,7 @@
// ReCaptcha // ReCaptcha
// //
// Created by Flávio Caetano on 10/10/17. // Created by Flávio Caetano on 10/10/17.
// Copyright © 2018 ReCaptcha. All rights reserved. // Copyright © 2017 ReCaptcha. All rights reserved.
// //
import Foundation import Foundation

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

View File

@ -10,10 +10,9 @@ default_platform :ios
platform :ios do platform :ios do
skip_docs skip_docs
devices = ["iPhone XR (~> 12)"] devices = ["iPhone X (~> 11)"]
devices << "iPhone X (~> 11)" if !Helper.is_ci?
devices << "iPhone 7 (~> 10)" if !Helper.is_ci? devices << "iPhone 7 (~> 10)" if !Helper.is_ci?
devices << "iPhone 6s (~> 9)" if !Helper.is_ci? devices << "iPhone 5s (~> 9)" if !Helper.is_ci?
desc "Runs the following lanes:\n- test\n- pod_lint\n- carthage_lint" desc "Runs the following lanes:\n- test\n- pod_lint\n- carthage_lint"
lane :ci do lane :ci do
@ -32,7 +31,6 @@ platform :ios do
swiftlint( swiftlint(
executable: "Example/Pods/Swiftlint/swiftlint", executable: "Example/Pods/Swiftlint/swiftlint",
strict: true, strict: true,
reporter: "emoji",
) )
# The problem lies in the fact (or rather: serious bug in xcodebuild) that # The problem lies in the fact (or rather: serious bug in xcodebuild) that