Skip to content

Commit

Permalink
Code spacing cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
audaciouscode committed Nov 2, 2016
1 parent ebc22cf commit 9bc4340
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 3 deletions.
8 changes: 7 additions & 1 deletion PassiveDataKit.xcodeproj/project.pbxproj
Expand Up @@ -981,7 +981,7 @@
3842F7281CDA2021007F843D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Audacious Software";
TargetAttributes = {
3842F7301CDA2021007F843D = {
Expand Down Expand Up @@ -1187,8 +1187,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -1235,8 +1237,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -1267,6 +1271,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1285,6 +1290,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
100 changes: 100 additions & 0 deletions PassiveDataKit/PDKGooglePlacesGenerator.m
Expand Up @@ -59,6 +59,22 @@ - (void) removeListener:(id<PDKDataListener>)listener {
}
}

- (void) updateOptions:(NSDictionary *) options {
if (options == nil) {
options = @{}; //!OCLINT
}

NSArray * existingListeners = [NSArray arrayWithArray:self.listeners];

for (id<PDKDataListener> listener in existingListeners) {
[self removeListener:listener];
}

for (id<PDKDataListener> listener in existingListeners) {
[self addListener:listener options:options];
}
}

- (void) addListener:(id<PDKDataListener>)listener options:(NSDictionary *) options {
if (options == nil) {
options = @{}; //!OCLINT
Expand All @@ -74,6 +90,8 @@ - (void) addListener:(id<PDKDataListener>)listener options:(NSDictionary *) opti
CLLocation * location = self.lastOptions[PDKGooglePlacesSpecificLocation];

[self transmitPlacesForLocation:location];
} else if (self.lastOptions[PDKGooglePlacesFreetextQuery] != nil) {
[self transmitPlacesForFreetextQuery:self.lastOptions[PDKGooglePlacesFreetextQuery]];
} else {
if (self.listeners.count == 1) {
[[PassiveDataKit sharedInstance] registerListener:self forGenerator:PDKLocation options:options];
Expand Down Expand Up @@ -103,6 +121,26 @@ - (NSURL *) urlForLocation:(CLLocation *) location {
return [NSURL URLWithString:urlString];
}

- (NSURL *) urlForFreetextQuery:(NSString *) query {
NSMutableString * urlString = [NSMutableString stringWithString:@"https://maps.googleapis.com/maps/api/place/textsearch/json?"];

[urlString appendFormat:@"key=%@&", self.lastOptions[PDKGooglePlacesAPIKey]];

NSMutableCharacterSet * charSet = [[NSMutableCharacterSet alloc] init];
[charSet formUnionWithCharacterSet:[NSCharacterSet URLQueryAllowedCharacterSet]];
[charSet removeCharactersInString:@"?&="];

query = [query stringByAddingPercentEncodingWithAllowedCharacters:charSet];

[urlString appendFormat:@"query=%@&", query];

if (self.lastOptions[PDKGooglePlacesType] != nil) {
[urlString appendFormat:@"type=%@&", self.lastOptions[PDKGooglePlacesType]];
}

return [NSURL URLWithString:urlString];
}

- (NSURL *) urlForPlaceId:(NSString *) placeId {
NSMutableString * urlString = [NSMutableString stringWithString:@"https://maps.googleapis.com/maps/api/place/details/json?"];

Expand Down Expand Up @@ -200,6 +238,68 @@ - (void) transmitPlacesForLocation:(CLLocation *) location {
[self.reach startMonitoring];
}

- (void) transmitPlacesForFreetextQuery:(NSString *) query {
self.reach = [PDKAFNetworkReachabilityManager managerForDomain:@"maps.googleapis.com"];

__unsafe_unretained PDKGooglePlacesGenerator * weakSelf = self;

[self.reach setReachabilityStatusChangeBlock:^(PDKAFNetworkReachabilityStatus status){
if (status == PDKAFNetworkReachabilityStatusReachableViaWWAN || status == PDKAFNetworkReachabilityStatusReachableViaWiFi)
{
PDKAFHTTPSessionManager *manager = [PDKAFHTTPSessionManager manager];

manager.responseSerializer = [PDKAFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];

[manager GET:[weakSelf urlForFreetextQuery:query].absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {

NSError * error = nil;

NSDictionary * response = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&error];

NSLog(@"response: %@", response);
NSLog(@"count: %d", (int) [response[@"results"] count]);

NSMutableDictionary * log = [NSMutableDictionary dictionary];
[log setValue:[NSDate date] forKey:@"recorded"];
[log setValue:response[@"results"] forKey:@"response"];

[PDKGooglePlacesGenerator logForReview:log];

NSMutableDictionary * data = [NSMutableDictionary dictionary];

[data setValue:response[@"results"] forKey:PDKGooglePlacesInstance];

if (self.lastOptions[PDKGooglePlacesIncludeFullDetails] != nil && [self.lastOptions[PDKGooglePlacesIncludeFullDetails] boolValue]) {
for (NSDictionary * place in response[@"results"]) {
NSData * placeData = [[NSData alloc] initWithContentsOfURL:[weakSelf urlForPlaceId:place[@"place_id"]]];

NSDictionary * placeResponse = [NSJSONSerialization JSONObjectWithData:placeData options:0 error:&error];

[data setValue:placeResponse[@"result"] forKey:place[@"place_id"]];
}
}

NSLog(@"DATA: %@", data);

for (id<PDKDataListener> listener in weakSelf.listeners) {
[listener receivedData:data forGenerator:PDKGooglePlaces];
}
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"ERROR: %@", error);
// TODO: Log failure...
}];
}

[weakSelf.reach stopMonitoring];
weakSelf.reach = nil;
}];

[self.reach startMonitoring];
}



- (void) receivedData:(NSDictionary *) data forGenerator:(PDKDataGenerator) dataGenerator {
[self transmitPlacesForLocation:[data valueForKey:PDKLocationInstance]];
}
Expand Down
9 changes: 9 additions & 0 deletions PassiveDataKit/PDKLocationGenerator.m
Expand Up @@ -101,6 +101,15 @@ - (void) removeListener:(id<PDKDataListener>)listener {
}
}

- (void) updateOptions:(NSDictionary *) options {
if (options == nil) {
options = @{}; //!OCLINT
}

NSLog(@"TODO: Update options and refresh generator!");

}


- (void) addListener:(id<PDKDataListener>)listener options:(NSDictionary *) options {
if (options == nil) {
Expand Down
3 changes: 3 additions & 0 deletions PassiveDataKit/PassiveDataKit.h
Expand Up @@ -23,6 +23,7 @@ extern NSString *const PDKLocationInstance;
extern NSString *const PDKMixpanelToken;

extern NSString *const PDKGooglePlacesSpecificLocation;
extern NSString *const PDKGooglePlacesFreetextQuery;
extern NSString *const PDKGooglePlacesAPIKey;
extern NSString *const PDKGooglePlacesType;
extern NSString *const PDKGooglePlacesRadius;
Expand All @@ -44,6 +45,8 @@ typedef NS_ENUM(NSInteger, PDKDataGenerator) {

- (void) removeListener:(id<PDKDataListener>)listener;
- (void) addListener:(id<PDKDataListener>)listener options:(NSDictionary *) options;
- (void) updateOptions:(NSDictionary *) options;

+ (UIView *) visualizationForSize:(CGSize) size;

@end
Expand Down
16 changes: 16 additions & 0 deletions PassiveDataKit/PassiveDataKit.m
Expand Up @@ -42,6 +42,7 @@ @interface PassiveDataKit ()
NSString * const PDKGooglePlacesType = @"PDKGooglePlacesType"; //!OCLINT
NSString * const PDKGooglePlacesRadius = @"PDKGooglePlacesRadius"; //!OCLINT
NSString * const PDKGooglePlacesIncludeFullDetails = @"PDKGooglePlacesIncludeFullDetails"; //!OCLINT
NSString * const PDKGooglePlacesFreetextQuery = @"PDKGooglePlacesFreetextQuery"; //!OCLINT

@implementation PassiveDataKit

Expand Down Expand Up @@ -89,6 +90,8 @@ - (BOOL) registerListener:(id<PDKDataListener>) listener forGenerator:(PDKDataGe
[dataListeners addObject:listener];

[self incrementGenerator:dataGenerator withListener:listener options:options];
} else {
[self updateGenerator:dataGenerator withOptions:options];
}

return YES;
Expand Down Expand Up @@ -146,6 +149,19 @@ - (void) incrementGenerator:(PDKDataGenerator) generator withListener:(id<PDKDat
}
}

- (void) updateGenerator:(PDKDataGenerator) generator withOptions:(NSDictionary *) options {
switch(generator) { //!OCLINT
case PDKLocation:
[[PDKLocationGenerator sharedInstance] updateOptions:options];

break;
case PDKGooglePlaces:
[[PDKGooglePlacesGenerator sharedInstance] updateOptions:options];
break;
}
}


+ (NSString *) keyForGenerator:(PDKDataGenerator) generator
{
switch(generator) { //!OCLINT
Expand Down

0 comments on commit 9bc4340

Please sign in to comment.