Skip to content

Commit

Permalink
Converted AppLinkResolverRequestBuilder to Swift
Browse files Browse the repository at this point in the history
Reviewed By: samodom

Differential Revision: D40146097

fbshipit-source-id: 59f19687c711947e992081e66c902a298b0135af
  • Loading branch information
Pablo Brizuela Guardado authored and facebook-github-bot committed Oct 6, 2022
1 parent 65fb722 commit 43cfd8b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ extension AppLinkResolver: DependentAsType {
static var configuredDependencies: TypeDependencies?

static var defaultDependencies: TypeDependencies? = TypeDependencies(
requestBuilder: _AppLinkResolverRequestBuilder(),
requestBuilder: AppLinkResolverRequestBuilder(),
clientTokenProvider: Settings.shared,
accessTokenProvider: AccessToken.self
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

#if !os(tvOS)

/**
Class responsible for generating the appropriate GraphRequest for a given set of urls
*/
final class AppLinkResolverRequestBuilder: NSObject, _AppLinkResolverRequestBuilding {

private enum IdiomField: String {
case ios
case iphone
case ipad
case appLinks = "app_links"
}

private let userInterfaceIdiom: UIUserInterfaceIdiom
private var uiSpecificFields: [String] {
var fields = [IdiomField.ios.rawValue]

if let idiomSpecificField = getIdiomSpecificField() {
fields.append(idiomSpecificField)
}

return fields
}

init(userInterfaceIdiom: UIUserInterfaceIdiom = UIDevice.current.userInterfaceIdiom) {
self.userInterfaceIdiom = userInterfaceIdiom
}

func request(for urls: [URL]) -> GraphRequestProtocol {
let fields = uiSpecificFields.joined(separator: ",")
let encodedURLs = getEncodedURLs(urls).joined(separator: ",")

let path = "?fields=\(IdiomField.appLinks.rawValue).fields(\(fields))&ids=\(encodedURLs)"
return GraphRequest(
graphPath: path,
parameters: nil,
flags: [.doNotInvalidateTokenOnError, .disableErrorRecovery]
)
}

func getIdiomSpecificField() -> String? {
switch userInterfaceIdiom {
case .pad: return IdiomField.ipad.rawValue
case .phone: return IdiomField.iphone.rawValue
default: return nil
}
}

private func getEncodedURLs(_ urls: [URL]) -> [String] {
urls.compactMap {
$0.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
}
}
}

#endif

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion FBSDKCoreKit/FBSDKCoreKit/include/FBSDKCoreKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#import <FBSDKCoreKit/FBSDKAppLinkNavigationBlock.h>
#import <FBSDKCoreKit/FBSDKAppLinkNavigationType.h>
#import <FBSDKCoreKit/FBSDKAppLinkProtocol.h>
#import <FBSDKCoreKit/FBSDKAppLinkResolverRequestBuilder.h>
#import <FBSDKCoreKit/FBSDKAppLinkResolverRequestBuilding.h>
#import <FBSDKCoreKit/FBSDKAppLinkResolving.h>
#import <FBSDKCoreKit/FBSDKAppLinksBlock.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#import "FBSDKAppEventsNumberParser.h"
#import "FBSDKAppEventsUtility+Testing.h"
#import "FBSDKAppLinkNavigation+Testing.h"
#import "FBSDKAppLinkResolverRequestBuilder.h"
#import "FBSDKAppLinkUtility+Testing.h"
#import "FBSDKAppURLSchemeProviding.h"
#import "FBSDKApplicationLifecycleNotifications.h"
Expand Down Expand Up @@ -114,11 +113,6 @@ NS_ASSUME_NONNULL_BEGIN

// Categories needed to expose private methods to Swift

// Needed to expose this private method to AppLinkResolverRequestBuilderTests
@interface FBSDKAppLinkResolverRequestBuilder (FBSDKAppLinkResolverTests)
- (instancetype)initWithUserInterfaceIdiom:(UIUserInterfaceIdiom)userInterfaceIdiom;
@end

// Needed to expose private methods to the ServerConfigurationFixtures class
@interface FBSDKServerConfiguration (ServerConfigurationFixtures)
- (nullable NSDictionary<NSString *, id> *)dialogConfigurations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
* LICENSE file in the root directory of this source tree.
*/

@testable import FBSDKCoreKit

final class AppLinkResolverRequestBuilderTests: XCTestCase {

func testAsksForPhoneDataOnPhone() {
let builder = _AppLinkResolverRequestBuilder(userInterfaceIdiom: .phone)
let builder = AppLinkResolverRequestBuilder(userInterfaceIdiom: .phone)
let request = builder.request(for: [])
let askedForPhone = request.graphPath.contains("iphone")
XCTAssertTrue(askedForPhone)
}

func testAsksForPadDataOnPad() {
let builder = _AppLinkResolverRequestBuilder(userInterfaceIdiom: .pad)
let builder = AppLinkResolverRequestBuilder(userInterfaceIdiom: .pad)
let request = builder.request(for: [])
let askedForPad = request.graphPath.contains("ipad")
XCTAssertTrue(askedForPad)
Expand Down

0 comments on commit 43cfd8b

Please sign in to comment.