Skip to content

Commit

Permalink
Write up ported class
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 committed Dec 3, 2024
1 parent 97cfe7e commit e6822a5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 26 deletions.
2 changes: 2 additions & 0 deletions FirebaseABTesting/Sources/ABTExperimentPayload.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#import "FirebaseABTesting/Sources/Private/ABTExperimentPayload.h"

#import "FirebaseABTesting/Sources/Public/FirebaseABTesting/FIRExperimentController.h"

static NSString *const kExperimentPayloadKeyExperimentID = @"experimentId";
static NSString *const kExperimentPayloadKeyVariantID = @"variantId";

Expand Down
11 changes: 2 additions & 9 deletions FirebaseABTesting/Sources/Private/ABTExperimentPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN
#import "FirebaseABTesting/Sources/Public/FirebaseABTesting/FIRExperimentController.h"

/// Policy for handling the case where there's an overflow of experiments for an installation
/// instance.
typedef NS_ENUM(int32_t, ABTExperimentPayloadExperimentOverflowPolicy) {
ABTExperimentPayloadExperimentOverflowPolicyUnrecognizedValue = 999,
ABTExperimentPayloadExperimentOverflowPolicyUnspecified = 0,
ABTExperimentPayloadExperimentOverflowPolicyDiscardOldest = 1,
ABTExperimentPayloadExperimentOverflowPolicyIgnoreNewest = 2,
};
NS_ASSUME_NONNULL_BEGIN

@interface ABTExperimentLite : NSObject
@property(nonatomic, readonly, copy) NSString *experimentId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@

#import <Foundation/Foundation.h>

#import "FIRLifecycleEvents.h"

@class ABTExperimentPayload;

// Forward declaration to avoid importing into the module header
typedef NS_ENUM(int32_t, ABTExperimentPayloadExperimentOverflowPolicy);
/// Policy for handling the case where there's an overflow of experiments for an installation
/// instance.
typedef NS_ENUM(int32_t, ABTExperimentPayloadExperimentOverflowPolicy) {
ABTExperimentPayloadExperimentOverflowPolicyUnrecognizedValue = 999,
ABTExperimentPayloadExperimentOverflowPolicyUnspecified = 0,
ABTExperimentPayloadExperimentOverflowPolicyDiscardOldest = 1,
ABTExperimentPayloadExperimentOverflowPolicyIgnoreNewest = 2,
};

NS_ASSUME_NONNULL_BEGIN

@class FIRLifecycleEvents;

/// The default experiment overflow policy, that is to discard the experiment with the oldest start
/// time when users start the experiment on the web console.
extern const ABTExperimentPayloadExperimentOverflowPolicy FIRDefaultExperimentOverflowPolicy;
Expand Down
1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Sources/FIRRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigFetch.h"
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigExperiment.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigRealtime.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
#import "FirebaseRemoteConfig/Sources/RCNPersonalization.h"
Expand Down
1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Sources/RCNConfigFetch.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#import "FirebaseInstallations/Source/Library/Private/FirebaseInstallationsInternal.h"
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigExperiment.h"

#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"

Expand Down
14 changes: 6 additions & 8 deletions FirebaseRemoteConfig/SwiftNew/ConfigExperiment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import FirebaseABTesting
import Foundation

/// Handles experiment information update and persistence.
/*@objc(RCNConfigExperiment)*/ open class ConfigExperiment: NSObject {
@objc(RCNConfigExperiment) public class ConfigExperiment: NSObject {
private static let experimentMetadataKeyLastStartTime = "last_experiment_start_time"
private static let serviceOrigin = "frc"

Expand All @@ -28,19 +28,17 @@ import Foundation
private let experimentStartTimeDateFormatter: DateFormatter

/// Designated initializer;
public init(DBManager: ConfigDBManager?,
experimentController controller: ExperimentController?) {
@objc public init(DBManager: ConfigDBManager?,
experimentController controller: ExperimentController?) {
experimentPayloads = []
experimentMetadata = [:]
activeExperimentPayloads = []
experimentStartTimeDateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)
// Locale needs to be hardcoded. See
// https://developer.apple.com/library/ios/#qa/qa1480/_index.html for more details.
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
// TODO(ncooke3): Trace back and see why timeZone is set twice.
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
return dateFormatter
}()
Expand Down Expand Up @@ -98,7 +96,7 @@ import Foundation
}

/// Update/Persist experiment information from config fetch response.
open func updateExperiments(withResponse response: [[String: Any]]?) {
@objc public func updateExperiments(withResponse response: [[String: Any]]?) {
// Cache fetched experiment payloads.
experimentPayloads.removeAll()
dbManager?.deleteExperimentTable(forKey: ConfigConstants.experimentTableKeyPayload)
Expand All @@ -121,7 +119,7 @@ import Foundation
}

/// Update experiments to Firebase Analytics when `activateWithCompletion:` happens.
open func updateExperiments(handler: (((any Error)?) -> Void)? = nil) {
@objc public func updateExperiments(handler: (((any Error)?) -> Void)? = nil) {
let lifecycleEvent = LifecycleEvents()

// Get the last experiment start time prior to the latest payload.
Expand All @@ -134,7 +132,7 @@ import Foundation
withServiceOrigin: Self.serviceOrigin,
events: lifecycleEvent,
policy: .discardOldest,
lastStartTime: lastStartTime,
lastStartTime: lastStartTime ?? 0,
payloads: experimentPayloads,
completionHandler: handler
)
Expand Down
4 changes: 2 additions & 2 deletions FirebaseRemoteConfig/Tests/Unit/RCNConfigExperimentTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

@import FirebaseRemoteConfig;

#import "FirebaseRemoteConfig/Sources/RCNConfigExperiment.h"

#import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h"
#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigDefines.h"
Expand All @@ -31,6 +29,8 @@

#import "Interop/Analytics/Public/FIRAnalyticsInterop.h"

#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"

// Surface the internal FIRExperimentController initializer.
@interface FIRExperimentController ()
- (instancetype)initWithAnalytics:(nullable id<FIRAnalyticsInterop>)analytics;
Expand Down
1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Tests/Unit/RCNRemoteConfigTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigFetch.h"
#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigExperiment.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigRealtime.h"

#import "FirebaseRemoteConfig/Tests/Unit/RCNTestUtilities.h"
Expand Down

0 comments on commit e6822a5

Please sign in to comment.