Skip to content

Commit 4b06ada

Browse files
committed
Merge branch 'master' into jae/loge
2 parents baeca1e + 7357941 commit 4b06ada

33 files changed

+468
-568
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ jobs:
3131
language: swift
3232
os: osx
3333
osx_image: xcode10.1
34-
addons:
35-
srcclr: true
3634
install: gem install cocoapods
3735
script:
3836
- pod spec lint --quick
37+
after_script:
38+
- curl -sSL https://download.sourceclear.com/ci.sh | bash
3939

4040
- &unittests
4141
stage: 'Unit Tests'

DemoObjCApp/AppDelegate.m

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#import "SamplesForAPI.h"
2121

2222
@import Optimizely;
23-
#if TARGET_OS_IOS
24-
@import Amplitude_iOS;
25-
#endif
2623

2724

2825
static NSString * const kOptimizelySdkKey = @"FCnSegiEkRry9rhVMroit4";
@@ -58,7 +55,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5855
// MARK: - Initialization Examples
5956

6057
-(void)initializeOptimizelySDKAsynchronous {
61-
self.optimizely = [[OptimizelyClient alloc] initWithSdkKey:kOptimizelySdkKey];
58+
DefaultEventDispatcher *eventDispacher = [[DefaultEventDispatcher alloc] initWithTimerInterval:1];
59+
60+
self.optimizely = [[OptimizelyClient alloc] initWithSdkKey:kOptimizelySdkKey logger:nil eventDispatcher:eventDispacher userProfileService:nil periodicDownloadInterval:@(5) defaultLogLevel:OptimizelyLogLevelDebug];
6261

6362
[self.optimizely startWithCompletion:^(NSData *data, NSError *error) {
6463
if (error == nil) {
@@ -110,7 +109,7 @@ -(void)initializeOptimizelySDKWithCustomization {
110109
eventDispatcher:nil
111110
userProfileService:nil
112111
periodicDownloadInterval:customDownloadIntervalInSecs
113-
defaultLogLevel:OptimizelyLogLevelInfo];
112+
defaultLogLevel:OptimizelyLogLevelDebug];
114113

115114
NSNumber *notifId;
116115
notifId = [self.optimizely.notificationCenter addDecisionNotificationListenerWithDecisionListener:^(NSString *type,
@@ -125,20 +124,6 @@ -(void)initializeOptimizelySDKWithCustomization {
125124
NSDictionary<NSString *,id> *attributes, NSDictionary<NSString *,id> *eventTags, NSDictionary<NSString *,id> *event) {
126125
NSLog(@"Received track notification: %@ %@ %@ %@ %@", eventKey, userId, attributes, eventTags, event);
127126

128-
129-
#if TARGET_OS_IOS
130-
// most of the third-party integrations only support iOS, so the sample code is only targeted for iOS builds
131-
132-
// Amplitude example
133-
[Amplitude.instance initializeApiKey:@"YOUR_API_KEY_HERE"];
134-
135-
NSString *propertyKey = [NSString stringWithFormat:@"[Optimizely] %@", eventKey];
136-
AMPIdentify *identify = [[AMPIdentify alloc] init];
137-
[identify set:propertyKey value:userId];
138-
// Track event (optional)
139-
NSString *eventIdentifier = [NSString stringWithFormat:@"[Optimizely] %@ - %@", eventKey, userId];
140-
[Amplitude.instance logEvent:eventIdentifier];
141-
#endif
142127
}];
143128

144129
[self.optimizely startWithCompletion:^(NSData *data, NSError *error) {

DemoObjCApp/DemoObjcApp.xcodeproj/project.pbxproj

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@
366366
6EF7498B21E404BB008B22A0 /* Frameworks */,
367367
6EF7498C21E404BB008B22A0 /* Resources */,
368368
6E4DD93B21E6708E00B0C2C7 /* Embed Frameworks */,
369-
7493B4816C0BC9BAABDE8B5B /* [CP] Embed Pods Frameworks */,
370369
);
371370
buildRules = (
372371
);
@@ -604,34 +603,6 @@
604603
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";
605604
showEnvVarsInLog = 0;
606605
};
607-
7493B4816C0BC9BAABDE8B5B /* [CP] Embed Pods Frameworks */ = {
608-
isa = PBXShellScriptBuildPhase;
609-
buildActionMask = 2147483647;
610-
files = (
611-
);
612-
inputFileListPaths = (
613-
);
614-
inputPaths = (
615-
"${PODS_ROOT}/Target Support Files/Pods-DemoObjciOS/Pods-DemoObjciOS-frameworks.sh",
616-
"${BUILT_PRODUCTS_DIR}/Amplitude-iOS/Amplitude_iOS.framework",
617-
"${BUILT_PRODUCTS_DIR}/GoogleToolboxForMac/GoogleToolboxForMac.framework",
618-
"${PODS_ROOT}/Localytics/Localytics-iOS-5.5.0/Localytics.framework",
619-
"${BUILT_PRODUCTS_DIR}/Mixpanel-swift/Mixpanel.framework",
620-
);
621-
name = "[CP] Embed Pods Frameworks";
622-
outputFileListPaths = (
623-
);
624-
outputPaths = (
625-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Amplitude_iOS.framework",
626-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleToolboxForMac.framework",
627-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Localytics.framework",
628-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mixpanel.framework",
629-
);
630-
runOnlyForDeploymentPostprocessing = 0;
631-
shellPath = /bin/sh;
632-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-DemoObjciOS/Pods-DemoObjciOS-frameworks.sh\"\n";
633-
showEnvVarsInLog = 0;
634-
};
635606
/* End PBXShellScriptBuildPhase section */
636607

637608
/* Begin PBXSourcesBuildPhase section */
@@ -642,7 +613,6 @@
642613
6E9681BA21EEB361009B7FEC /* VariationViewController.m in Sources */,
643614
6EB8456B21EE5DE3005346CC /* AppDelegate.m in Sources */,
644615
6E9681D821EFA5B2009B7FEC /* CustomLogger.m in Sources */,
645-
646616
6EFA3206227CD55E006FA572 /* SamplesForAPI.m in Sources */,
647617
6E4DD7F721E51E5500B0C2C7 /* main.m in Sources */,
648618
);

DemoObjCApp/Samples/SamplesForAPI.m

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,11 @@ +(void)run:(OptimizelyClient*)optimizely {
8383
// MARK: - isFeatureEnabled
8484

8585
{
86-
NSError *error = nil;
87-
NSNumber *enabled = [optimizely isFeatureEnabledWithFeatureKey:@"my_feature_key"
86+
BOOL enabled = [optimizely isFeatureEnabledWithFeatureKey:@"my_feature_key"
8887
userId:@"user_123"
89-
attributes:attributes
90-
error:&error];
88+
attributes:attributes];
9189

92-
if (enabled == nil) {
93-
NSLog(@"Error: %@", error);
94-
} else {
95-
NSLog(@"[isFeatureEnabled] %d", enabled.boolValue);
96-
}
90+
NSLog(@"[isFeatureEnabled] %@", enabled ? @"YES": @"NO");
9791
}
9892

9993
// MARK: - getFeatureVariable
@@ -115,15 +109,9 @@ +(void)run:(OptimizelyClient*)optimizely {
115109
// MARK: - getEnabledFeatures
116110

117111
{
118-
NSError *error = nil;
119112
NSArray *enabledFeatures = [optimizely getEnabledFeaturesWithUserId:@"user_123"
120-
attributes:attributes
121-
error:&error];
122-
if (enabledFeatures == nil) {
123-
NSLog(@"Error: %@", error);
124-
} else {
125-
NSLog(@"[getEnabledFeatures] %@", enabledFeatures);
126-
}
113+
attributes:attributes];
114+
NSLog(@"[getEnabledFeatures] %@", enabledFeatures);
127115
}
128116

129117
// MARK: - track

DemoSwiftApp/AppDelegate.swift

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
import UIKit
1818
import Optimizely
19-
#if os(iOS)
20-
import Amplitude_iOS
21-
#endif
2219

2320

2421
@UIApplicationMain
@@ -111,22 +108,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
111108
})
112109

113110
_ = optimizely.notificationCenter.addTrackNotificationListener(trackListener: { (eventKey, userId, attributes, eventTags, event) in
114-
print("Received track notification: \(eventKey) \(userId) \(String(describing: attributes)) \(String(describing: eventTags)) \(event)")
115-
116-
// most of the third-party integrations only support iOS, so the sample code is only targeted for iOS builds
117-
#if os(iOS)
118-
119-
// Amplitude example
120-
Amplitude.instance().initializeApiKey("YOUR_API_KEY_HERE")
121-
122-
let propertyKey = "[Optimizely] " + eventKey
123-
let identify = AMPIdentify()
124-
identify.set(propertyKey, value: userId as NSObject?)
125-
// Track event (optional)
126-
let eventIdentifier = "[Optimizely] " + eventKey + " - " + userId
127-
Amplitude.instance().logEvent(eventIdentifier)
128-
129-
#endif
111+
print("Received track notification: \(eventKey) \(userId) \(String(describing: attributes)) \(String(describing: eventTags)) \(event)")
130112
})
131113

132114
_ = optimizely.notificationCenter.addDatafileChangeNotificationListener(datafileListener: { (data) in
@@ -143,9 +125,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
143125

144126
if let controller = self.window?.rootViewController as? VariationViewController {
145127
//controller.showCoupon = toggle == FeatureFlagToggle.on ? true : false;
146-
if let showCoupon = try? self.optimizely.isFeatureEnabled(featureKey: "show_coupon", userId: self.userId) {
147-
controller.showCoupon = showCoupon
148-
}
128+
controller.showCoupon = self.optimizely.isFeatureEnabled(featureKey: "show_coupon",
129+
userId: self.userId)
149130
}
150131
}
151132
})
@@ -188,10 +169,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
188169
func openVariationView(variationKey: String?) {
189170
let variationViewController = storyboard.instantiateViewController(withIdentifier: "VariationViewController") as! VariationViewController
190171

191-
if let showCoupon = try? optimizely.isFeatureEnabled(featureKey: "show_coupon", userId: userId) {
192-
variationViewController.showCoupon = showCoupon
193-
}
194-
172+
variationViewController.showCoupon = optimizely.isFeatureEnabled(featureKey: "show_coupon",
173+
userId: userId)
195174
variationViewController.optimizely = optimizely
196175
variationViewController.userId = userId
197176
variationViewController.variationKey = variationKey

DemoSwiftApp/DemoSwiftApp.xcodeproj/project.pbxproj

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@
353353
252D7DEA21C8800800134A7A /* Frameworks */,
354354
252D7DEB21C8800800134A7A /* Resources */,
355355
6E4DD93321E66FB400B0C2C7 /* Embed Frameworks */,
356-
92C2F2B5620F8CA248471722 /* [CP] Embed Pods Frameworks */,
357356
);
358357
buildRules = (
359358
);
@@ -599,34 +598,6 @@
599598
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";
600599
showEnvVarsInLog = 0;
601600
};
602-
92C2F2B5620F8CA248471722 /* [CP] Embed Pods Frameworks */ = {
603-
isa = PBXShellScriptBuildPhase;
604-
buildActionMask = 2147483647;
605-
files = (
606-
);
607-
inputFileListPaths = (
608-
);
609-
inputPaths = (
610-
"${PODS_ROOT}/Target Support Files/Pods-DemoSwiftiOS/Pods-DemoSwiftiOS-frameworks.sh",
611-
"${BUILT_PRODUCTS_DIR}/Amplitude-iOS/Amplitude_iOS.framework",
612-
"${BUILT_PRODUCTS_DIR}/GoogleToolboxForMac/GoogleToolboxForMac.framework",
613-
"${PODS_ROOT}/Localytics/Localytics-iOS-5.5.0/Localytics.framework",
614-
"${BUILT_PRODUCTS_DIR}/Mixpanel-swift/Mixpanel.framework",
615-
);
616-
name = "[CP] Embed Pods Frameworks";
617-
outputFileListPaths = (
618-
);
619-
outputPaths = (
620-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Amplitude_iOS.framework",
621-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleToolboxForMac.framework",
622-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Localytics.framework",
623-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mixpanel.framework",
624-
);
625-
runOnlyForDeploymentPostprocessing = 0;
626-
shellPath = /bin/sh;
627-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-DemoSwiftiOS/Pods-DemoSwiftiOS-frameworks.sh\"\n";
628-
showEnvVarsInLog = 0;
629-
};
630601
/* End PBXShellScriptBuildPhase section */
631602

632603
/* Begin PBXSourcesBuildPhase section */

DemoSwiftApp/Samples/SamplesForAPI.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ class SamplesForAPI {
7171

7272
// MARK: - isFeatureEnabled
7373

74-
do {
75-
let enabled = try optimizely.isFeatureEnabled(featureKey: "my_feature_key",
74+
let enabled = optimizely.isFeatureEnabled(featureKey: "my_feature_key",
7675
userId: "user_123",
7776
attributes: attributes)
78-
print("[isFeatureEnabled] \(enabled)")
79-
} catch {
80-
print(error)
81-
}
77+
print("[isFeatureEnabled] \(enabled)")
8278

8379
// MARK: - getFeatureVariable
8480

@@ -94,12 +90,8 @@ class SamplesForAPI {
9490

9591
// MARK: - getEnabledFeatures
9692

97-
do {
98-
let enabledFeatures = try optimizely.getEnabledFeatures(userId: "user_123", attributes: attributes)
99-
print("[getEnabledFeatures] \(enabledFeatures)")
100-
} catch {
101-
print(error)
102-
}
93+
let enabledFeatures = optimizely.getEnabledFeatures(userId: "user_123", attributes: attributes)
94+
print("[getEnabledFeatures] \(enabledFeatures)")
10395

10496
// MARK: - track
10597

OptimizelySDK/Customization/DefaultEventDispatcher.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
2828
static let MAX_FAILURE_COUNT = 3
2929

3030
// default timerInterval
31-
open var timerInterval:TimeInterval = 60 * 5 // every five minutes
31+
var timerInterval:TimeInterval = 60 * 5 // every five minutes
3232
// default batchSize.
3333
// attempt to send events in batches with batchSize number of events combined
34-
open var batchSize:Int = 10
34+
var batchSize:Int = 10
3535
// start trimming the front of the queue when we get to over maxQueueSize
3636
// TODO: implement
37-
open var maxQueueSize:Int = 3000
37+
var maxQueueSize:Int = 30000
3838

3939
lazy var logger = HandlerRegistryService.shared.injectLogger()
4040
var backingStore:DataStoreType = .file
@@ -47,9 +47,8 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
4747
// timer as a atomic property.
4848
var timer:AtomicProperty<Timer> = AtomicProperty<Timer>()
4949

50-
public init(batchSize:Int = 10, maxQueueSize:Int = 3000, backingStore:DataStoreType = .file, dataStoreName:String = "OPTEventQueue", timerInterval:TimeInterval = 60*5 ) {
51-
self.batchSize = batchSize
52-
self.maxQueueSize = maxQueueSize
50+
public init(batchSize:Int = 10, backingStore:DataStoreType = .file, dataStoreName:String = "OPTEventQueue", timerInterval:TimeInterval = 60*5 ) {
51+
self.batchSize = batchSize > 0 ? batchSize : 1
5352
self.backingStore = backingStore
5453
self.backingStoreName = dataStoreName
5554
self.timerInterval = timerInterval
@@ -112,9 +111,17 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
112111

113112
}
114113
while let eventsToSend:[EventForDispatch] = self.dataStore.getFirstItems(count:self.batchSize) {
114+
let actualEventsSize = eventsToSend.count
115115
var eventToSend = eventsToSend.batch()
116116
if let _ = eventToSend {
117117
// we merged the event and ready for batch
118+
// if the bacth size is not equal to the actual event size,
119+
// then setup the batchSizeHolder to be the size of the event.
120+
if actualEventsSize != self.batchSize {
121+
batchSizeHolder = actualEventsSize
122+
self.batchSize = actualEventsSize
123+
sendCount = actualEventsSize - 1
124+
}
118125
}
119126
else {
120127
failedBatch()
@@ -168,7 +175,7 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
168175
}
169176
}
170177
else {
171-
// batch worked
178+
// batch had batchSize items
172179
}
173180
}
174181
// our send is done.
@@ -182,7 +189,7 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
182189

183190
}
184191

185-
func sendEvent(event: EventForDispatch, completionHandler: @escaping DispatchCompletionHandler) {
192+
open func sendEvent(event: EventForDispatch, completionHandler: @escaping DispatchCompletionHandler) {
186193
let config = URLSessionConfiguration.ephemeral
187194
let session = URLSession(configuration: config)
188195
var request = URLRequest(url: event.url)

OptimizelySDK/Extensions/OptimizelyClient+Extension.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,32 @@ extension OptimizelyClient {
4242
// sdk keys without having to be created for every key.
4343
HandlerRegistryService.shared.registerBinding(binder:Binder<OPTDatafileHandler>(service: OPTDatafileHandler.self).singetlon().reInitializeStrategy(strategy: .reUse).to(factory: type(of:datafileHandler).init).using(instance: datafileHandler).sdkKey(key: sdkKey))
4444
}
45+
46+
/// Optimizely Manager
47+
///
48+
/// - Parameters:
49+
/// - sdkKey: sdk key
50+
/// - logger: custom Logger
51+
/// - eventDispatcher: custom EventDispatcher (optional)
52+
/// - userProfileService: custom UserProfileService (optional)
53+
/// - periodicDownloadInterval: custom interval for periodic background datafile download (optional. default = 10 * 60 secs)
54+
/// - defaultLogLevel: default log level (optional. default = .info)
55+
public convenience init(sdkKey: String,
56+
logger: OPTLogger? = nil,
57+
eventDispatcher: OPTEventDispatcher? = nil,
58+
userProfileService: OPTUserProfileService? = nil,
59+
periodicDownloadInterval:Int? = nil,
60+
defaultLogLevel: OptimizelyLogLevel? = nil) {
61+
let interval = periodicDownloadInterval ?? 10 * 60
62+
63+
64+
self.init(sdkKey: sdkKey, logger: logger, eventDispatcher: eventDispatcher, userProfileService: userProfileService, defaultLogLevel: defaultLogLevel)
65+
66+
if let handler = datafileHandler as? DefaultDatafileHandler, interval > 0 {
67+
handler.setTimer(sdkKey: sdkKey, interval: interval)
68+
}
69+
70+
71+
}
72+
4573
}

0 commit comments

Comments
 (0)