Permalink
Browse files

fix property type assertions. add network indicator toggle

  • Loading branch information...
1 parent 8bf2c26 commit 4c9cbb0cfe02485b5986c1a9c9cd16d37e3d4a1a @neilrahilly neilrahilly committed Oct 4, 2012
Showing with 66 additions and 34 deletions.
  1. +29 −13 HelloMixpanel/HelloMixpanelTests/HelloMixpanelTests.m
  2. +28 −10 Mixpanel/Mixpanel.h
  3. +9 −11 Mixpanel/Mixpanel.m
View
42 HelloMixpanel/HelloMixpanelTests/HelloMixpanelTests.m
@@ -71,22 +71,33 @@ - (BOOL)mixpanelWillFlush:(Mixpanel *)mixpanel
return NO;
}
-- (void)testJSONSerializer {
+- (NSDictionary *)allPropertyTypes
+{
NSNumber *number = [NSNumber numberWithInt:3];
-
+
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];
NSDate *date = [dateFormatter dateFromString:@"2012-09-28 19:14:36 PDT"];
[dateFormatter release];
- NSDictionary *test = [NSDictionary dictionaryWithObjectsAndKeys:
- @"yello", @"string",
- number, @"number",
- date, @"date",
- nil];
-
+ NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"v" forKey:@"k"];
+ NSArray *array = [NSArray arrayWithObject:@"1"];
+ NSNull *null = [NSNull null];
+
+ return [NSDictionary dictionaryWithObjectsAndKeys:
+ @"yello", @"string",
+ number, @"number",
+ date, @"date",
+ dictionary, @"dictionary",
+ array, @"array",
+ null, @"null",
+ nil];
+}
+
+- (void)testJSONSerializer {
+ NSDictionary *test = [self allPropertyTypes];
NSString *json = [[MPCJSONSerializer serializer] serializeArray:[NSArray arrayWithObject:test] error:nil];
- STAssertEqualObjects(json, @"[{\"date\":\"2012-09-29T02:14:36\",\"number\":3,\"string\":\"yello\"}]", @"json serializer failed");
+ STAssertEqualObjects(json, @"[{\"date\":\"2012-09-29T02:14:36\",\"array\":[\"1\"],\"null\":null,\"dictionary\":{\"k\":\"v\"},\"number\":3,\"string\":\"yello\"}]", @"json serializer failed");
}
- (void)testIdentify
@@ -182,10 +193,15 @@ - (void)testSuperProperties
- (void)testAssertPropertyTypes
{
NSDictionary *p = [NSDictionary dictionaryWithObject:[NSURL URLWithString:@"http://www.google.com/"] forKey:@"URL"];
- STAssertThrows([self.mixpanel track:@"e1" properties:p], @"track allowed unsupported property type");
- STAssertThrows([self.mixpanel registerSuperProperties:p], @"register super properties allowed unsupported property type");
- STAssertThrows([self.mixpanel registerSuperPropertiesOnce:p], @"register super properties once allowed unsupported property type");
- STAssertThrows([self.mixpanel registerSuperPropertiesOnce:p defaultValue:@"v"], @"register super properties once with default allowed unsupported property type");
+ STAssertThrows([self.mixpanel track:@"e1" properties:p], @"property type should not be allowed");
+ STAssertThrows([self.mixpanel registerSuperProperties:p], @"property type should not be allowed");
+ STAssertThrows([self.mixpanel registerSuperPropertiesOnce:p], @"property type should not be allowed");
+ STAssertThrows([self.mixpanel registerSuperPropertiesOnce:p defaultValue:@"v"], @"property type should not be allowed");
+ p = [self allPropertyTypes];
+ STAssertNoThrow([self.mixpanel track:@"e1" properties:p], @"property type should be allowed");
+ STAssertNoThrow([self.mixpanel registerSuperProperties:p], @"property type should be allowed");
+ STAssertNoThrow([self.mixpanel registerSuperPropertiesOnce:p], @"property type should be allowed");
+ STAssertNoThrow([self.mixpanel registerSuperPropertiesOnce:p defaultValue:@"v"], @"property type should be allowed");
}
- (void)testReset
View
38 Mixpanel/Mixpanel.h
@@ -106,6 +106,17 @@
/*!
@property
+
+ @abstract
+ Controls whether to show spinning network activity indicator when flushing data to the Mixpanel servers.
+
+ @discussion
+ Defaults to YES.
+ */
+@property(nonatomic,assign) BOOL showNetworkActivityIndicator;
+
+/*!
+ @property
@abstract
Gets and sets the a MixpanelDelegate object that can be used to assert
@@ -191,7 +202,9 @@
@discussion
Properties will allow you to segment your events in your Mixpanel reports.
Property keys must be <code>NSString</code> objects and values must be
- <code>NSString</code> or <code>NSNumber</code> objects.
+ <code>NSString</code>, <code>NSNumber</code>, <code>NSNull</code>,
+ <code><NSDate</code>, <code>NSArray</code> or <code>NSDictionary</code>
+ objects.
@param event event name
@param properties properties dictionary
@@ -207,8 +220,9 @@
@discussion
Super properties, once registered, are automatically sent as properties for
all event tracking calls. They save you having to maintain and add a common
- set of properties to your events. Property keys must be <code>NSString</code>
- objects and values must be <code>NSString</code> or <code>NSNumber</code>
+ set of properties to your events. Property keys must be <code>NSString</code> objects and values must be
+ <code>NSString</code>, <code>NSNumber</code>, <code>NSNull</code>,
+ <code><NSDate</code>, <code>NSArray</code> or <code>NSDictionary</code>
objects.
@param properties properties dictionary
@@ -224,7 +238,9 @@
@discussion
Property keys must be <code>NSString</code> objects and values must be
- <code>NSString</code> or <code>NSNumber</code> objects.
+ <code>NSString</code>, <code>NSNumber</code>, <code>NSNull</code>,
+ <code><NSDate</code>, <code>NSArray</code> or <code>NSDictionary</code>
+ objects.
@param properties properties dictionary
*/
@@ -239,9 +255,9 @@
@discussion
Property keys must be <code>NSString</code> objects and values must be
- <code>NSString</code> or <code>NSNumber</code> objects. The defaultValue
- object must be either an <code>NSString</code> or <code>NSNumber</code>
- object.
+ <code>NSString</code>, <code>NSNumber</code>, <code>NSNull</code>,
+ <code><NSDate</code>, <code>NSArray</code> or <code>NSDictionary</code>
+ objects.
@param properties properties dictionary
@param defaultValue overwrite existing properties that have this value
@@ -393,9 +409,11 @@
Convenience method for setting a single property in Mixpanel People.
@discussion
- The property name must be an NSString and the property value should be
- NSString, NSNumber, NSArray, NSDate, or NSNull.
-
+ Property keys must be <code>NSString</code> objects and values must be
+ <code>NSString</code>, <code>NSNumber</code>, <code>NSNull</code>,
+ <code><NSDate</code>, <code>NSArray</code> or <code>NSDictionary</code>
+ objects.
+
@param property property name
@param object property value
*/
View
20 Mixpanel/Mixpanel.m
@@ -214,8 +214,11 @@ + (void)assertPropertyTypes:(NSDictionary *)properties
for (id v in [properties allValues]) {
NSAssert([v isKindOfClass:[NSString class]] ||
[v isKindOfClass:[NSNumber class]] ||
- [v isKindOfClass:[NSDate class]],
- @"%@ track property values should be NSString, NSNumber or NSDate. found: %@", self, v);
+ [v isKindOfClass:[NSNull class]] ||
+ [v isKindOfClass:[NSDate class]] ||
+ [v isKindOfClass:[NSArray class]] ||
+ [v isKindOfClass:[NSDictionary class]],
+ @"%@ property values must be NSString, NSNumber, NSNull, NSDate, NSArray or NSDictionary. found: %@", self, v);
}
}
@@ -247,6 +250,7 @@ - (id)initWithToken:(NSString *)apiToken andFlushInterval:(NSUInteger)flushInter
self.apiToken = apiToken;
self.flushInterval = flushInterval;
+ self.showNetworkActivityIndicator = YES;
self.serverURL = @"https://api.mixpanel.com";
self.distinctId = [self defaultDistinctId];
@@ -442,7 +446,8 @@ - (void)flushPeople
- (void)updateNetworkActivityIndicator
{
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:(self.eventsConnection || self.peopleConnection)];
+ BOOL visible = self.showNetworkActivityIndicator && (self.eventsConnection || self.peopleConnection);
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:visible];
}
#pragma mark * Persistence
@@ -869,14 +874,7 @@ - (void)addPushDeviceToken:(NSData *)deviceToken
- (void)set:(NSDictionary *)properties
{
NSAssert(properties != nil, @"properties must not be nil");
- for (id v in [properties allValues]) {
- NSAssert([v isKindOfClass:[NSString class]] ||
- [v isKindOfClass:[NSNumber class]] ||
- [v isKindOfClass:[NSDate class]] ||
- [v isKindOfClass:[NSArray class]] ||
- [v isKindOfClass:[NSDictionary class]],
- @"%@ set property values should be NSString, NSNumber, NSDate, NSArray or NSDictionary. found: %@", self, v);
- }
+ [Mixpanel assertPropertyTypes:properties];
[self addPeopleRecordToQueueWithAction:@"$set" andProperties:properties];
}

0 comments on commit 4c9cbb0

Please sign in to comment.