-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor for the new
ComposableRequest
* Update default `Client` to be an iOS device * Update README.md * Add Authenticator app to allow anyone to rely on `SwiftagramTests` * Update Followers example
- Loading branch information
Showing
70 changed files
with
3,136 additions
and
2,071 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
Examples/Authenticator/Authenticator/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
Examples/Authenticator/Authenticator/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "83.5x83.5" | ||
}, | ||
{ | ||
"idiom" : "ios-marketing", | ||
"scale" : "1x", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Examples/Authenticator/Authenticator/Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Examples/Authenticator/Authenticator/Assets.xcassets/header.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "header.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+32.2 KB
Examples/Authenticator/Authenticator/Assets.xcassets/header.imageset/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions
17
Examples/Authenticator/Authenticator/AuthenticatorApp.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// AuthenticatorApp.swift | ||
// Authenticator | ||
// | ||
// Created by Stefano Bertagno on 07/02/21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct AuthenticatorApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView().accentColor(.pink) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// ContentView.swift | ||
// Authenticator | ||
// | ||
// Created by Stefano Bertagno on 07/02/21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import Swiftagram | ||
|
||
struct ContentView: View { | ||
/// Whether it should present the login view or not. | ||
@State var isPresentingLoginView: Bool = false | ||
/// The current secret. | ||
@State var secret: Secret? | ||
|
||
/// The actual view. | ||
var body: some View { | ||
VStack(spacing: 40) { | ||
// The header. | ||
Image("header") | ||
.resizable() | ||
.scaledToFit() | ||
.frame(maxWidth: .infinity) | ||
.padding(.horizontal, 50) | ||
// Check for token. | ||
if let secret = secret, let token = secret.token { | ||
Text(token) | ||
.font(Font.headline.smallCaps()) | ||
.foregroundColor(.primary) | ||
.lineLimit(3) | ||
.fixedSize(horizontal: false, vertical: true) | ||
.onTapGesture { UIPasteboard.general.string = token } | ||
Text("(Tap to copy it in your clipboard)") | ||
.font(.caption) | ||
.fixedSize(horizontal: false, vertical: true) | ||
} else { | ||
// The disclaimer. | ||
Text.combine( | ||
Text("Please authenticate with your "), | ||
Text("Instagram").bold(), | ||
Text(" account to receive a token for "), | ||
Text("SwiftagramTests").bold() | ||
) | ||
.fixedSize(horizontal: false, vertical: true) | ||
// Login. | ||
Button(action: { isPresentingLoginView = true }) { | ||
Text("Authenticate").font(.headline) | ||
}.foregroundColor(.accentColor) | ||
} | ||
} | ||
.foregroundColor(.secondary) | ||
.multilineTextAlignment(.center) | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
.padding(.vertical) | ||
.padding(.horizontal, 50) | ||
.sheet(isPresented: $isPresentingLoginView) { LoginView(secret: $secret) } | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?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>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>UIApplicationSceneManifest</key> | ||
<dict> | ||
<key>UIApplicationSupportsMultipleScenes</key> | ||
<true/> | ||
</dict> | ||
<key>UIApplicationSupportsIndirectInputEvents</key> | ||
<true/> | ||
<key>UILaunchScreen</key> | ||
<dict/> | ||
<key>UIRequiredDeviceCapabilities</key> | ||
<array> | ||
<string>armv7</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations~ipad</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationPortraitUpsideDown</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// LoginView.swift | ||
// Authenticator | ||
// | ||
// Created by Stefano Bertagno on 07/02/21. | ||
// | ||
|
||
import SwiftUI | ||
import UIKit | ||
import WebKit | ||
|
||
import Swiftagram | ||
|
||
class LoginViewController: UIViewController { | ||
/// The completion handler. | ||
var completion: ((Secret) -> Void)? | ||
/// The web view. | ||
var webView: WKWebView? { | ||
didSet { | ||
guard let webView = webView else { return } | ||
webView.frame = view.frame | ||
view.addSubview(webView) | ||
} | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
// Authenticate. | ||
WebViewAuthenticator { | ||
self.webView = $0 | ||
}.authenticate { [weak self] in | ||
switch $0 { | ||
case .failure(let error): print(error.localizedDescription) | ||
case .success(let secret): | ||
self?.completion?(secret) | ||
self?.dismiss(animated: true, completion: nil) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// A `struct` defining a `View` used for logging in. | ||
struct LoginView: UIViewControllerRepresentable { | ||
/// The current secret. | ||
@Binding var secret: Secret? | ||
|
||
func makeUIViewController(context: Context) -> LoginViewController { | ||
let controller = LoginViewController() | ||
controller.completion = { self.secret = $0 } | ||
return controller | ||
} | ||
func updateUIViewController(_ uiViewController: LoginViewController, context: Context) { | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Examples/Authenticator/Authenticator/Preview Content/Preview Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Secret.swift | ||
// Authenticator | ||
// | ||
// Created by Stefano Bertagno on 07/02/21. | ||
// | ||
|
||
import Foundation | ||
|
||
import Swiftagram | ||
|
||
extension Secret { | ||
/// Compute the token. | ||
var token: String? { try? JSONEncoder().encode(self).base64EncodedString() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Text.swift | ||
// Authenticator | ||
// | ||
// Created by Stefano Bertagno on 07/02/21. | ||
// | ||
|
||
import Foundation | ||
|
||
import SwiftUI | ||
|
||
extension Text { | ||
/// Combine a collection of texts. | ||
/// | ||
/// - parameters: A collection of `Text`s. | ||
/// - returns: A valid `Text`. | ||
static func combine(_ texts: Text...) -> Text { | ||
combine(texts) | ||
} | ||
|
||
/// Combine a collection of texts. | ||
/// | ||
/// - parameters: A collection of `Text`s. | ||
/// - returns: A valid `Text`. | ||
static func combine(_ texts: [Text]) -> Text { | ||
guard let first = texts.first else { | ||
fatalError("`texts` should not be empty") | ||
} | ||
return texts.dropFirst().reduce(first) { $0+$1 } | ||
} | ||
} |
Oops, something went wrong.