Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to LDConfigBuilder API #89

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8dc0169
Make sure NSStrings have copy attributers. Added nullability identifi…
Apr 26, 2017
61cb332
Removed redundant property synthesize statements.
Apr 26, 2017
d855e40
Created a custom initializer for LDConfig.
Apr 26, 2017
c79f651
Converted custom setters to class properties.
Apr 26, 2017
ff1b915
Got rid of custom setter implementations.
Apr 26, 2017
f38ba8e
Moved mobileKey and debugEnabled flags into the config object.
Apr 26, 2017
777f271
Got rid of the config builder declaration.
Apr 26, 2017
02c548d
Moved logging info from the build method into the property setter imp…
Apr 26, 2017
6806b35
Replaced use of LDConfigBuilder with the use of LDConfig.
Apr 26, 2017
5d0b06e
Updated testStartWithValidConfig.
Apr 26, 2017
8f0b614
Updated testStartWithValidConfigMultipleTimes.
Apr 26, 2017
b52c6d3
Updated testBoolVariationWithStart.
Apr 26, 2017
93b11cf
Updated testUserPersisted.
Apr 26, 2017
3f5f5cd
Updated testToggleCreatesEventWithCorrectArguments.
Apr 26, 2017
feb0e1f
Updated -testTrackWithStart.
Apr 26, 2017
4f52827
Updated -testOfflineWithStart.
Apr 26, 2017
a1a3711
Updated -testOnlineWithStart.
Apr 26, 2017
079792e
Updated -testFlushWithStart.
Apr 26, 2017
1166c3e
Updated -testUpdateUserWithStart.
Apr 26, 2017
be05509
Updated -testCurrentUserBuilderWithStart.
Apr 26, 2017
17d48da
Updated -setUp.
Apr 26, 2017
ffb9e73
Updated -setUp.
Apr 26, 2017
84bd4c6
Updated -testPollingInterval.
Apr 26, 2017
279149d
Updated -testCreateEventAfterCapacityReached.
Apr 26, 2017
8488d29
Declare -initWithMobileKey: as the designated initializer and make -i…
Apr 26, 2017
d84e66f
Removed -testConfigWithoutMobileKey calling LDConfig initalizer witho…
Apr 26, 2017
66806a1
Updated testConfigDefaultValues.
Apr 26, 2017
942db68
Updated -testConfigOverrideBaseUrl.
Apr 26, 2017
461f039
Updated -testConfigOverrideCapacity.
Apr 26, 2017
b3bff5c
Updated -testConfigOverrideConnectionTimeout.
Apr 26, 2017
097f086
Updated -testConfigOverrideFlushInterval.
Apr 26, 2017
f9abd39
Updated -testConfigOverridePollingInterval.
Apr 26, 2017
895dc18
Updated -setPollingInterval: to make sure we take into consideration …
Apr 26, 2017
e36b9c9
Updated -testConfigOverrideStreaming.
Apr 26, 2017
94a4f1a
Updated -testConfigOverrideDebug.
Apr 26, 2017
8dc27ef
Updated designated initalizer to assign default values.
Apr 26, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Darkly/LDClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
/**
* Start the client with a valid configuration and user.
*
* @param inputConfigBuilder Desired configuration for the client
* @param inputUserBuilder Desired user for the client
* @return whether the client was able to be started
* @param inputConfig Desired configuration for the client.
* @param inputUserBuilder Desired user for the client.
* @return whether the client was able to be started.
*/
- (BOOL)start:(LDConfigBuilder *)inputConfigBuilder userBuilder:(LDUserBuilder *)inputUserBuilder;
- (BOOL)start:(LDConfig *)inputConfig userBuilder:(LDUserBuilder *)inputUserBuilder;
/**
* Retrieve a feature flag value. If the configuration for this feature
* flag is retrieved from the server that value is returned, otherwise
Expand Down
6 changes: 3 additions & 3 deletions Darkly/LDClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ +(LDClient *)sharedInstance
return sharedLDClient;
}

- (BOOL)start:(LDConfigBuilder *)inputConfigBuilder userBuilder:(LDUserBuilder *)inputUserBuilder {
- (BOOL)start:(LDConfig *)inputConfig userBuilder:(LDUserBuilder *)inputUserBuilder {
DEBUG_LOGX(@"LDClient start method called");
if (!clientStarted) {
if (inputConfigBuilder) {
ldConfig = [inputConfigBuilder build];
if (inputConfig) {
ldConfig = inputConfig;
if (ldConfig) {
DarklyLogLevel logLevel = DarklyLogLevelCriticalOnly;
if ([ldConfig debugEnabled]) {
Expand Down
119 changes: 45 additions & 74 deletions Darkly/LDConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,100 +2,71 @@
// Copyright © 2015 Catamorphic Co. All rights reserved.
//

@interface LDConfig : NSObject {

}
@interface LDConfig : NSObject

@property (nonatomic) NSString* mobileKey;
@property (nonatomic) NSString* baseUrl;
@property (nonatomic) NSString* eventsUrl;
@property (nonatomic) NSNumber* capacity;
@property (nonatomic) NSNumber* connectionTimeout;
@property (nonatomic) NSNumber* flushInterval;
@property (nonatomic) NSNumber* pollingInterval;
@property (nonatomic) BOOL streaming;
@property (nonatomic) BOOL debugEnabled;

@end

@interface LDConfigBuilder : NSObject {

}
/**
This is the mobileKey retrieved from the Launch Darkly account settings.
*/
@property (nonatomic, readonly, nonnull) NSString* mobileKey;

/**
* Provide an mobileKey to the configuration builder. This is the mobileKey
* retrieved from the Launch Darkly account settings. (Required)
*
* @param mobileKey the mobileKey for the configuration
* @return the configuration builder
The baseUrl of the Launch Darkly server. This will allow you to
switch between production and staging environments.
*/
- (LDConfigBuilder *)withMobileKey:(NSString *)mobileKey;
@property (nonatomic, copy, nullable) NSString* baseUrl;

/**
* Provide the baseUrl of the Launch Darkly server. This will allow you
* to switch between production and staging environments. (Optional)
*
* @param baseUrl the baseUrl of the server
* @return the configuration builder
The eventsUrl of the Launch Darkly server. This will allow you
to switch between production and staging environments.
*/
- (LDConfigBuilder *)withBaseUrl:(NSString *)baseUrl;
@property (nonatomic, copy, nullable) NSString* eventsUrl;

/**
* Provide the eventsUrl of the Launch Darkly server. This will allow you
* to switch between production and staging environments. (Optional)
*
* @param eventsUrl the eventsUrl of the server
* @return the configuration builder
The capacity for storing feature flag and custom events. Events
are persisted on the client and then synced to the server on a regular
basis. If there is ever a prolonged period of time between the last server
sync, the capacity defined here will determine at what points the events
are ignored and no longer stored. The default is 100.
*/
- (LDConfigBuilder *)withEventsUrl:(NSString *)eventsUrl;
@property (nonatomic, copy, nullable) NSNumber* capacity;

/**
* Provide the capacity for storing feature flag and custom events. Events
* are persisted on the client and then synced to the server on a regular
* basis. If there is ever a prolonged period of time between the last server
* sync, the capacity defined here will determine at what points the events
* are ignored and no longer stored. The default is 100. (Optional)
*
* @param capacity the number of events to store
* @return the configuration builder
The connection timeout to be used when syncing to the Launch Darkly
server. The default is 10 seconds.
*/
- (LDConfigBuilder *)withCapacity:(int)capacity;
@property (nonatomic, copy, nullable) NSNumber* connectionTimeout;

/**
* The connection timeout to be used when syncing to the Launch Darkly
* server. The default is 10 seconds. (Optional)
*
* @param connectionTimeout timeout for network connections in seconds
* @return the configuration builder
The interval at which events are synced to the server. The default
is 30 seconds for streaming mode; in polling mode, the flush interval defaults
to the polling interval. (Optional)
*/
- (LDConfigBuilder *)withConnectionTimeout:(int)connectionTimeout;
@property (nonatomic, copy, nullable) NSNumber* flushInterval;

/**
* The interval at which events are synced to the server. The default
* is 30 seconds for streaming mode; in polling mode, the flush interval defaults to the polling interval. (Optional)
*
* @param flushInterval the flush interval in seconds
* @return the configuration builder
The polling interval (in seconds) for polling mode only. An interval
less than 300 is set to the default (5 minutes).
*/
- (LDConfigBuilder *)withFlushInterval:(int)flushInterval;
@property (nonatomic, copy, nullable) NSNumber* pollingInterval;

/**
* Set the polling interval (in seconds) for polling mode only. An interval
* less than 300 is set to the default (5 minutes).
*
* @param pollingInterval the polling interval in seconds
* @return the configuration builder
Flag that enables streaming mode. When streaming is false, disable streaming
and switch to polling mode.
*/
- (LDConfigBuilder *)withPollingInterval:(int)pollingInterval;
@property (nonatomic) BOOL streaming;

/**
* Enable streaming mode for flags. When streaming is false, disable streaming and switch to polling mode. (Optional)
*
* @param streamingEnabled Whether streaming is enabled or not
* @return the configuration builder
Flat that enables debug mode to allow things such as logging.
*/
- (LDConfigBuilder *)withStreaming:(BOOL)streamingEnabled;
@property (nonatomic) BOOL debugEnabled;

/**
* Enable debug mode to allow things such as logging. (Optional)
*
* @param debugEnabled Whether debugging is enabled or not
* @return the configuration builder
Initializes an LDConfig object with the provided mobile key.
@param mobileKey The mobileKey retrieved from the Launch Darkly account settings.
@return An instance of LDConfig object.
*/
- (LDConfigBuilder *)withDebugEnabled:(BOOL)debugEnabled;
- (instancetype _Nonnull)initWithMobileKey:(nonnull NSString *)mobileKey NS_DESIGNATED_INITIALIZER;

-(LDConfig *)build;
- (instancetype _Nonnull )init NS_UNAVAILABLE;

@end
184 changes: 69 additions & 115 deletions Darkly/LDConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,149 +5,103 @@
#import "LDConfig.h"
#import "LDUtil.h"

@implementation LDConfig

@synthesize mobileKey, baseUrl, eventsUrl, capacity, connectionTimeout, flushInterval, pollingInterval, streaming, debugEnabled;

@end

@interface LDConfigBuilder() {
NSString *mobileKey;
NSString *baseUrl;
NSString *eventsUrl;
NSNumber *capacity;
NSNumber *connectionTimeout;
NSNumber *flushInterval;
NSNumber *pollingInterval;
BOOL streaming;
BOOL debugEnabled;
}

@interface LDConfig()
@property (nonatomic, copy, nonnull) NSString* mobileKey;
@end

@implementation LDConfigBuilder

- (id)init {
self = [super init];
streaming = YES;
return self;
}

- (LDConfigBuilder *)withMobileKey:(NSString *)inputMobileKey
{
mobileKey = inputMobileKey;
return self;
}

- (LDConfigBuilder *)withBaseUrl:(NSString *)inputBaseUrl
{
baseUrl = inputBaseUrl;
return self;
}

-(LDConfigBuilder *)withEventsUrl:(NSString *)inputEventsUrl{
eventsUrl = inputEventsUrl;
return self;
}

- (LDConfigBuilder *)withCapacity:(int)inputCapacity
{
capacity = [NSNumber numberWithInt:inputCapacity];
return self;
}

- (LDConfigBuilder *)withConnectionTimeout:(int)inputConnectionTimeout
{
connectionTimeout = [NSNumber numberWithInt:inputConnectionTimeout];
return self;
}
@implementation LDConfig

- (LDConfigBuilder *)withFlushInterval:(int)inputFlushInterval
{
flushInterval = [NSNumber numberWithInt:inputFlushInterval];
return self;
}
- (instancetype)initWithMobileKey:(NSString *)mobileKey {
if (!(self = [super init])) {
return nil;
}

- (LDConfigBuilder *)withPollingInterval:(int)inputPollingInterval
{
pollingInterval = [NSNumber numberWithInt:MAX(inputPollingInterval, kMinimumPollingInterval)];
return self;
}
self.mobileKey = mobileKey;
self.streaming = YES;
self.capacity = [NSNumber numberWithInt:kCapacity];
self.connectionTimeout = [NSNumber numberWithInt:kConnectionTimeout];
self.flushInterval = [NSNumber numberWithInt:kDefaultFlushInterval];
self.pollingInterval = [NSNumber numberWithInt:kDefaultPollingInterval];
self.baseUrl = kBaseUrl;
self.eventsUrl = kEventsUrl;

- (LDConfigBuilder *)withStreaming:(BOOL)inputStreamingEnabled
{
streaming = inputStreamingEnabled;
return self;
}

- (LDConfigBuilder *)withDebugEnabled:(BOOL)inputDebugEnabled
{
debugEnabled = inputDebugEnabled;
return self;
- (void)setMobileKey:(NSString *)mobileKey {
_mobileKey = [mobileKey copy];
DEBUG_LOG(@"Set LDConfig mobileKey: %@", mobileKey);
}

-(LDConfig *)build
{
DEBUG_LOGX(@"LDConfigBuilder build method called");
LDConfig *config = [[LDConfig alloc] init];
if (mobileKey) {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with mobileKey: %@", mobileKey);
[config setMobileKey:mobileKey];
} else {
DEBUG_LOGX(@"LDConfigBuilder requires an MobileKey");
return nil;
}
- (void)setBaseUrl:(NSString *)baseUrl {
if (baseUrl) {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with baseUrl: %@", baseUrl);
[config setBaseUrl:baseUrl];
DEBUG_LOG(@"Set LDConfig baseUrl: %@", baseUrl);
_baseUrl = [baseUrl copy];
} else {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with default baseUrl: %@", kBaseUrl);
[config setBaseUrl:kBaseUrl];
DEBUG_LOG(@"Set LDConfig default baseUrl: %@", kBaseUrl);
_baseUrl = kBaseUrl;
}
}

- (void)setEventsUrl:(NSString *)eventsUrl {
if (eventsUrl) {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with eventsUrl: %@", eventsUrl);
[config setEventsUrl:eventsUrl];
DEBUG_LOG(@"Set LDConfig eventsUrl: %@", eventsUrl);
_eventsUrl = [eventsUrl copy];
} else {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with default eventsUrl: %@", kEventsUrl);
[config setEventsUrl:kEventsUrl];
DEBUG_LOG(@"Set LDConfig default eventsUrl: %@", kEventsUrl);
_eventsUrl = kEventsUrl;
}
}

- (void)setCapacity:(NSNumber *)capacity {
if (capacity) {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with capacity: %@", capacity);
[config setCapacity:capacity];
DEBUG_LOG(@"Set LDConfig capacity: %@", capacity);
_capacity = capacity;

} else {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with default capacity: %d", kCapacity);
[config setCapacity:[NSNumber numberWithInt:kCapacity]];
DEBUG_LOG(@"Set LDConfig default capacity: %d", kCapacity);
_capacity = [NSNumber numberWithInt:kCapacity];
}
}

- (void)setConnectionTimeout:(NSNumber *)connectionTimeout {
if (connectionTimeout) {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with timeout: %@", connectionTimeout);
[config setConnectionTimeout:connectionTimeout];
DEBUG_LOG(@"Set LDConfig timeout: %@", connectionTimeout);
_connectionTimeout = connectionTimeout;
} else {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with default timeout: %d", kConnectionTimeout);
[config setConnectionTimeout:[NSNumber numberWithInt:kConnectionTimeout]];
DEBUG_LOG(@"Set LDConfig default timeout: %d", kConnectionTimeout);
_connectionTimeout = [NSNumber numberWithInt:kConnectionTimeout];
}
}

- (void)setFlushInterval:(NSNumber *)flushInterval {
if (flushInterval) {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with flush interval: %@", flushInterval);
[config setFlushInterval:flushInterval];
DEBUG_LOG(@"Set LDConfig flush interval: %@", flushInterval);
_flushInterval = flushInterval;
} else {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with default flush interval: %d", kDefaultFlushInterval);
[config setFlushInterval:[NSNumber numberWithInt:kDefaultFlushInterval]];
DEBUG_LOG(@"Set LDConfig default flush interval: %d", kDefaultFlushInterval);
_flushInterval = [NSNumber numberWithInt:kDefaultFlushInterval];
}
}

- (void)setPollingInterval:(NSNumber *)pollingInterval {
if (pollingInterval) {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with polling interval: %@", pollingInterval);
[config setPollingInterval:pollingInterval];
DEBUG_LOG(@"Set LDConfig polling interval: %@", pollingInterval);
_pollingInterval = [NSNumber numberWithInt:MAX(pollingInterval.intValue, kMinimumPollingInterval)];
} else {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with default polling interval: %d", kDefaultPollingInterval);
[config setPollingInterval:[NSNumber numberWithInt:kDefaultPollingInterval]];
}

DEBUG_LOG(@"LDConfigBuilder building LDConfig with streaming enabled: %d", streaming);
[config setStreaming:streaming];

if (debugEnabled) {
DEBUG_LOG(@"LDConfigBuilder building LDConfig with debug enabled: %d", debugEnabled);
[config setDebugEnabled:debugEnabled];
DEBUG_LOG(@"Set LDConfig default polling interval: %d", kDefaultPollingInterval);
_pollingInterval = [NSNumber numberWithInt:kDefaultPollingInterval];
}
return config;
}

- (void)setStreaming:(BOOL)streaming {
_streaming = streaming;
DEBUG_LOG(@"Set LDConfig streaming enabled: %d", streaming);
}

- (void)setDebugEnabled:(BOOL)debugEnabled {
_debugEnabled = debugEnabled;
DEBUG_LOG(@"Set LDConfig debug enabled: %d", debugEnabled);
}

@end
Loading