Skip to content

Commit

Permalink
cleanup whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
neilrahilly committed Oct 18, 2012
1 parent 13c6a18 commit 32eeddc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion HelloMixpanel/HelloMixpanel/ViewController.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (IBAction)trackEvent:(id)sender - (IBAction)trackEvent:(id)sender
{ {
Mixpanel *mixpanel = [Mixpanel sharedInstance]; Mixpanel *mixpanel = [Mixpanel sharedInstance];
[mixpanel track:@"Player Create" properties:[NSDictionary dictionaryWithObjectsAndKeys: [mixpanel track:@"Player Create" properties:[NSDictionary dictionaryWithObjectsAndKeys:
[self.genderControl titleForSegmentAtIndex:self.genderControl.selectedSegmentIndex], @"gender", [self.genderControl titleForSegmentAtIndex:self.genderControl.selectedSegmentIndex], @"gender",
[self.weaponControl titleForSegmentAtIndex:self.weaponControl.selectedSegmentIndex], @"weapon", [self.weaponControl titleForSegmentAtIndex:self.weaponControl.selectedSegmentIndex], @"weapon",
nil]]; nil]];
Expand Down
88 changes: 44 additions & 44 deletions Mixpanel/Mixpanel.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -179,19 +179,19 @@ + (NSString *)uniqueDeviceString


+ (NSString *)calculateHMACSHA1withString:(NSString *)str andKey:(NSString *)key + (NSString *)calculateHMACSHA1withString:(NSString *)str andKey:(NSString *)key
{ {
const char *cStr = [str UTF8String]; const char *cStr = [str UTF8String];
const char *cSecretStr = [key UTF8String]; const char *cSecretStr = [key UTF8String];
unsigned char digest[CC_SHA1_DIGEST_LENGTH]; unsigned char digest[CC_SHA1_DIGEST_LENGTH];
memset((void *)digest, 0x0, CC_SHA1_DIGEST_LENGTH); memset((void *)digest, 0x0, CC_SHA1_DIGEST_LENGTH);
CCHmac(kCCHmacAlgSHA1, cSecretStr, strlen(cSecretStr), cStr, strlen(cStr), digest); CCHmac(kCCHmacAlgSHA1, cSecretStr, strlen(cSecretStr), cStr, strlen(cStr), digest);
return [NSString stringWithFormat: return [NSString stringWithFormat:
@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
digest[0], digest[1], digest[2], digest[3], digest[0], digest[1], digest[2], digest[3],
digest[4], digest[5], digest[6], digest[7], digest[4], digest[5], digest[6], digest[7],
digest[8], digest[9], digest[10], digest[11], digest[8], digest[9], digest[10], digest[11],
digest[12], digest[13], digest[14], digest[15], digest[12], digest[13], digest[14], digest[15],
digest[16], digest[17], digest[18], digest[19] digest[16], digest[17], digest[18], digest[19]
]; ];
} }


+ (NSString *)encodeAPIData:(NSArray *)array + (NSString *)encodeAPIData:(NSArray *)array
Expand Down Expand Up @@ -241,7 +241,7 @@ + (id)sharedInstance
if (sharedInstance == nil) { if (sharedInstance == nil) {
NSLog(@"%@ warning sharedInstance called before sharedInstanceWithToken:", self); NSLog(@"%@ warning sharedInstance called before sharedInstanceWithToken:", self);
} }
return sharedInstance; return sharedInstance;
} }


- (id)initWithToken:(NSString *)apiToken andFlushInterval:(NSUInteger)flushInterval - (id)initWithToken:(NSString *)apiToken andFlushInterval:(NSUInteger)flushInterval
Expand Down Expand Up @@ -284,7 +284,7 @@ - (NSString *)defaultDistinctId


- (void)track:(NSString *)event - (void)track:(NSString *)event
{ {
[self track:event properties:nil]; [self track:event properties:nil];
} }


- (void)track:(NSString *)event properties:(NSDictionary *)properties - (void)track:(NSString *)event properties:(NSDictionary *)properties
Expand All @@ -303,16 +303,16 @@ - (void)track:(NSString *)event properties:(NSDictionary *)properties
if (self.distinctId) { if (self.distinctId) {
[p setObject:self.distinctId forKey:@"distinct_id"]; [p setObject:self.distinctId forKey:@"distinct_id"];
} }
[p addEntriesFromDictionary:self.superProperties]; [p addEntriesFromDictionary:self.superProperties];
if (properties) { if (properties) {
[p addEntriesFromDictionary:properties]; [p addEntriesFromDictionary:properties];
} }


[Mixpanel assertPropertyTypes:properties]; [Mixpanel assertPropertyTypes:properties];


NSDictionary *e = [NSDictionary dictionaryWithObjectsAndKeys:event, @"event", [NSDictionary dictionaryWithDictionary:p], @"properties", nil]; NSDictionary *e = [NSDictionary dictionaryWithObjectsAndKeys:event, @"event", [NSDictionary dictionaryWithDictionary:p], @"properties", nil];
DebugLog(@"%@ queueing event: %@", self, e); DebugLog(@"%@ queueing event: %@", self, e);
[self.eventsQueue addObject:e]; [self.eventsQueue addObject:e];
} }


#pragma mark * Super property methods #pragma mark * Super property methods
Expand Down Expand Up @@ -412,19 +412,19 @@ - (void)flush


- (void)flushEvents - (void)flushEvents
{ {
if ([self.eventsQueue count] == 0 || self.eventsConnection != nil) { if ([self.eventsQueue count] == 0 || self.eventsConnection != nil) {
DevLog(@"%@ no events to flush", self); DevLog(@"%@ no events to flush", self);
return; return;
} else if ([self.eventsQueue count] > 50) { } else if ([self.eventsQueue count] > 50) {
self.eventsBatch = [self.eventsQueue subarrayWithRange:NSMakeRange(0, 50)]; self.eventsBatch = [self.eventsQueue subarrayWithRange:NSMakeRange(0, 50)];
} else { } else {
self.eventsBatch = [NSArray arrayWithArray:self.eventsQueue]; self.eventsBatch = [NSArray arrayWithArray:self.eventsQueue];
} }


NSString *data = [Mixpanel encodeAPIData:self.eventsBatch]; NSString *data = [Mixpanel encodeAPIData:self.eventsBatch];
NSString *postBody = [NSString stringWithFormat:@"ip=1&data=%@", data]; NSString *postBody = [NSString stringWithFormat:@"ip=1&data=%@", data];


self.eventsConnection = [self apiConnectionWithEndpoint:@"/track/" andBody:postBody]; self.eventsConnection = [self apiConnectionWithEndpoint:@"/track/" andBody:postBody];


DevLog(@"%@ flushing %u of %u queued events: %@", self, self.eventsBatch.count, self.eventsQueue.count, self.eventsQueue); DevLog(@"%@ flushing %u of %u queued events: %@", self, self.eventsBatch.count, self.eventsQueue.count, self.eventsQueue);


Expand Down Expand Up @@ -455,7 +455,7 @@ - (void)flushPeople
- (void)updateNetworkActivityIndicator - (void)updateNetworkActivityIndicator
{ {
BOOL visible = self.showNetworkActivityIndicator && (self.eventsConnection || self.peopleConnection); BOOL visible = self.showNetworkActivityIndicator && (self.eventsConnection || self.peopleConnection);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:visible]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:visible];
} }


#pragma mark * Persistence #pragma mark * Persistence
Expand Down Expand Up @@ -541,9 +541,9 @@ - (void)unarchiveEvents
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
self.eventsQueue = nil; self.eventsQueue = nil;
} }
if (!self.eventsQueue) { if (!self.eventsQueue) {
self.eventsQueue = [NSMutableArray array]; self.eventsQueue = [NSMutableArray array];
} }
} }


- (void)unarchivePeople - (void)unarchivePeople
Expand Down Expand Up @@ -677,32 +677,32 @@ - (void)applicationWillEnterForeground:(NSNotificationCenter *)notification
{ {
[self unarchive]; [self unarchive];
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
if (&UIBackgroundTaskInvalid) { if (&UIBackgroundTaskInvalid) {
if (self.taskId != UIBackgroundTaskInvalid) { if (self.taskId != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:self.taskId]; [[UIApplication sharedApplication] endBackgroundTask:self.taskId];
} }
self.taskId = UIBackgroundTaskInvalid; self.taskId = UIBackgroundTaskInvalid;
} }
#endif #endif
} }


- (void)applicationWillTerminate:(NSNotification *)notification - (void)applicationWillTerminate:(NSNotification *)notification
{ {
DevLog(@"%@ application will terminate", self); DevLog(@"%@ application will terminate", self);
[self archive]; [self archive];
} }


- (void)endTaskIfInBackground - (void)endTaskIfInBackground
{ {
// if the os version allows background tasks, the app supports them, and we're in one, end it // if the os version allows background tasks, the app supports them, and we're in one, end it


#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
if (&UIBackgroundTaskInvalid && [[UIApplication sharedApplication] respondsToSelector:@selector(endBackgroundTask:)] && if (&UIBackgroundTaskInvalid && [[UIApplication sharedApplication] respondsToSelector:@selector(endBackgroundTask:)] &&
self.taskId != UIBackgroundTaskInvalid && self.eventsConnection == nil && self.peopleConnection == nil) { self.taskId != UIBackgroundTaskInvalid && self.eventsConnection == nil && self.peopleConnection == nil) {


[[UIApplication sharedApplication] endBackgroundTask:self.taskId]; [[UIApplication sharedApplication] endBackgroundTask:self.taskId];
self.taskId = UIBackgroundTaskInvalid; self.taskId = UIBackgroundTaskInvalid;
} }
#endif #endif
} }


Expand All @@ -722,12 +722,12 @@ - (NSURLConnection *)apiConnectionWithEndpoint:(NSString *)endpoint andBody:(NSS
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response
{ {
DevLog(@"%@ http status code: %d", self, [response statusCode]); DevLog(@"%@ http status code: %d", self, [response statusCode]);
if ([response statusCode] != 200) { if ([response statusCode] != 200) {
// TODO better failure message here // TODO better failure message here
NSLog(@"%@ http error: %@", self, [NSHTTPURLResponse localizedStringForStatusCode:[response statusCode]]); NSLog(@"%@ http error: %@", self, [NSHTTPURLResponse localizedStringForStatusCode:[response statusCode]]);
} else if (connection == self.eventsConnection) { } else if (connection == self.eventsConnection) {
self.eventsResponseData = [NSMutableData data]; self.eventsResponseData = [NSMutableData data];
} else if (connection == self.peopleConnection) { } else if (connection == self.peopleConnection) {
self.peopleResponseData = [NSMutableData data]; self.peopleResponseData = [NSMutableData data];
} }
} }
Expand All @@ -743,7 +743,7 @@ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data


- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{ {
NSLog(@"%@ network failure: %@", self, error); NSLog(@"%@ network failure: %@", self, error);
if (connection == self.eventsConnection) { if (connection == self.eventsConnection) {
self.eventsBatch = nil; self.eventsBatch = nil;
self.eventsResponseData = nil; self.eventsResponseData = nil;
Expand Down

0 comments on commit 32eeddc

Please sign in to comment.