Skip to content

Commit

Permalink
Merge branch 'refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
gBit authored and gBit committed Mar 19, 2013
2 parents 57528c5 + e845950 commit a4eac87
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 601 deletions.
13 changes: 11 additions & 2 deletions MappingMashupApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@
8F372AF716F244C800302B80 = {
isa = PBXGroup;
children = (
8335571E16F759B600DB17D5 /* wifiIcon@2x.png */,
8335571816F754C800DB17D5 /* xmark.png */,
8F372B0916F244C800302B80 /* MappingMashupApp */,
8F372B0216F244C800302B80 /* Frameworks */,
8F372B0116F244C800302B80 /* Products */,
Expand Down Expand Up @@ -181,6 +179,7 @@
8F372B0A16F244C800302B80 /* Supporting Files */ = {
isa = PBXGroup;
children = (
8F3AD83816F90A0300BEEB3A /* Custom Images */,
8F372B0B16F244C800302B80 /* MappingMashupApp-Info.plist */,
8F372B0C16F244C800302B80 /* InfoPlist.strings */,
8F372B0F16F244C800302B80 /* main.m */,
Expand Down Expand Up @@ -249,6 +248,16 @@
name = "View Controllers";
sourceTree = "<group>";
};
8F3AD83816F90A0300BEEB3A /* Custom Images */ = {
isa = PBXGroup;
children = (
8335571E16F759B600DB17D5 /* wifiIcon@2x.png */,
8335571816F754C800DB17D5 /* xmark.png */,
);
name = "Custom Images";
path = ..;
sourceTree = "<group>";
};
B40B477616F69055006BD4CE /* Backups */ = {
isa = PBXGroup;
children = (
Expand Down
16 changes: 5 additions & 11 deletions MappingMashupApp/APIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,18 @@

@interface APIManager : NSObject

@property (strong, nonatomic) NSArray *flickrPhotosArray;
@property (strong, nonatomic) NSString *apiCall;
@property (strong, nonatomic) NSMutableArray *venuesArray;
@property (strong, nonatomic) NSMutableArray *yelpVenuesArray;
@property (strong, nonatomic) NSMutableArray *flickrPhotosArray;

@property (strong, nonatomic) id <DataSourceDelegate> delegate;


- (APIManager*)initWithFlickrSearch:(NSString*)search andLocation:(LocationManager*)userLocation;

- (APIManager*)initWithYelpSearch:(NSString*)search andLocation:(LocationManager*)userLocation;

//the getter and the setting of the json from flickr
- (void)getFlickrJSON;
- (void)setArrayOfDictsFromFlickrJSONWithResponse:(NSURLResponse*)myResponse andData:(NSData*)myData andError:(NSError*)theirError;


//the getting of the json from yelp
- (NSMutableArray*)getYelpArrayFromAPICall;
- (NSMutableArray*)searchYelpParseResults;
- (NSMutableArray*)searchFlickrParseResults;

//- (void)setArrayOfDictsFromFlickrJSONWithResponse:(NSURLResponse*)myResponse andData:(NSData*)myData andError:(NSError*)theirError;

@end
172 changes: 87 additions & 85 deletions MappingMashupApp/APIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,115 +12,61 @@

@implementation APIManager

@synthesize apiCall,flickrPhotosArray, venuesArray;
@synthesize apiCall,flickrPhotosArray, yelpVenuesArray;

#pragma mark - Custom Initializers

//api method call for flickr
- (APIManager*)initWithFlickrSearch:(NSString*)search andLocation:(LocationManager*)userLocation
{
apiCall = [NSString stringWithFormat:@"http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=bd02a7a94fbe1f4c40a1661af4cb7bbe&tags=%@&format=json&nojsoncallback=1&lat=%f&lon=%f&radius=0.5&extras=geo", search, userLocation.coordinate.latitude, userLocation.coordinate.longitude];
return self;
}

//api method call for yelp
//
// Initialize Yelp APIManager w/ custom API call
// Passes in custom search string and user's current location
//
- (APIManager*)initWithYelpSearch:(NSString*)search andLocation:(LocationManager*)userLocation
{
apiCall = [NSString stringWithFormat:@"http://api.yelp.com/business_review_search?term=%@&lat=%f&long=%f&radius=1&limit=5&ywsid=z8HZy2Hb2axZox05xfTW9w",search, userLocation.coordinate.latitude, userLocation.coordinate.longitude];
//Restricting search to 5 results for now - 3.18.13
return self;
}

//method calll for returing the dicitionaries that we are getting from the api calls
- (void) getFlickrJSON
{
NSURLRequest* flickrRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:apiCall]];

//not needed because it is the default
//flickrRequest.HTTPMethod = @"GET";

[NSURLConnection sendAsynchronousRequest:flickrRequest
queue:[NSOperationQueue mainQueue]
completionHandler:^ void (NSURLResponse* myResponse, NSData* myData, NSError* theirError)
{
[self setArrayOfDictsFromFlickrJSONWithResponse:myResponse andData:myData andError:theirError];
//[self.delegate grabArray:flickrPhotosArray];

}];
// SHOULD WE BE KICKING OFF THE SEARCHES HERE?
return self;
}

//
// Initialize Flickr APIManager w/ custom API call
// Passes in custom search string and user's current location
//
//This came from YelpMapViewController and needs to be refactored
//
//
- (NSMutableArray *)createPlacesArray:(NSArray *)placesData
- (APIManager*)initWithFlickrSearch:(NSString*)search andLocation:(LocationManager*)userLocation
{
returnedArray = [[NSMutableArray alloc] init];

for (NSDictionary *placeDictionary in placesData)
{
float placeLatitude = [[placeDictionary valueForKey:@"latitude"] floatValue];
float placeLongitude = [[placeDictionary valueForKey:@"longitude"] floatValue];
CLLocation *placeLocation = [[CLLocation alloc] initWithLatitude:placeLatitude longitude:placeLongitude];

Venue *place = [[Venue alloc] init];
place.name = [placeDictionary valueForKey:@"name"];
place.location = placeLocation;
place.yelpURL= [placeDictionary valueForKey:@"url"];

[returnedArray addObject:place];
}
return returnedArray;
apiCall = [NSString stringWithFormat:@"http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=bd02a7a94fbe1f4c40a1661af4cb7bbe&tags=%@&format=json&nojsoncallback=1&lat=%f&lon=%f&radius=0.5&extras=geo", search, userLocation.coordinate.latitude, userLocation.coordinate.longitude];
return self;
}

- (void)setArrayOfDictsFromFlickrJSONWithResponse:(NSURLResponse*)myResponse andData:(NSData*)myData andError:(NSError*)theirError
{

if (theirError)
{
NSLog(@"Flickr Error: %@", [theirError description]);
}
else
{
NSError *jsonError;
NSDictionary *myJSONDictionary = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:myData
options:NSJSONReadingAllowFragments
error:&jsonError];

flickrPhotosArray = [[myJSONDictionary valueForKey:@"photos"] valueForKey:@"photo"];
}
}
#pragma mark - Yelp Methods

- (NSMutableArray*)getYelpArrayFromAPICall
- (NSMutableArray*)searchYelpParseResults
{
YKURL *yelpURL = [YKURL URLString:apiCall];
[YKJSONRequest requestWithURL:yelpURL
finishBlock:^ void (id myData)
{
NSDictionary *jsonDictionary = (NSDictionary *)myData;
NSArray *yelpBusinessesArray = [jsonDictionary valueForKey:@"businesses"];
//
//probably delete this delegate and push it to
//createVenuesArray method
//
//[self.delegate grabArray:yelpBusinessesArray];
[self createVenuesArray:yelpBusinessesArray];
}
finishBlock:^ void (id data)
{
NSDictionary *jsonDictionary = (NSDictionary *)data;
NSArray *yelpBusinessesArray = [jsonDictionary valueForKey:@"businesses"];
[self createVenuesArray:yelpBusinessesArray];
}
failBlock:^ void (YKHTTPError *error)
{
if (error)
{
NSLog(@"Error using Yelp: %@", [error description]);
}
}];
{
if (error)
{
NSLog(@"Yelp Error: %@", [error description]);
}
}
];

// return array to view controller
return venuesArray;
return yelpVenuesArray;
}

- (void)createVenuesArray:(NSArray *)jsonArray
{
venuesArray = [[NSMutableArray alloc] init];
yelpVenuesArray = [[NSMutableArray alloc] init];

for (NSDictionary *business in jsonArray)
{
Expand All @@ -133,7 +79,63 @@ - (void)createVenuesArray:(NSArray *)jsonArray
currentVenue.location = loc;
currentVenue.yelpURL= [business valueForKey:@"url"];

[venuesArray addObject:currentVenue];
[yelpVenuesArray addObject:currentVenue];
}
}

#pragma mark - Flickr Methods

- (NSMutableArray*)searchFlickrParseResults
{
NSURLRequest *flickrRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:apiCall]];
[NSURLConnection sendAsynchronousRequest:flickrRequest
queue:[NSOperationQueue mainQueue]
completionHandler:^ void (NSURLResponse* response, NSData* data, NSError* error)
{
if (error)
{
NSLog(@"Flickr Error: %@", [error description]);
}
else
{
NSError *error;
NSDictionary *jsonDictionary = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingAllowFragments
error:&error];

flickrPhotosArray = [[jsonDictionary valueForKey:@"photos"] valueForKey:@"photo"];
//
// IS THIS GOING TO BE A PROBLEM? (INSIDE BLOCK)
//
[self createPhotosArray:flickrPhotosArray];
}
}
];
return flickrPhotosArray;
}

//
//
// THIS NEEDS TO BE REVIEWED TO MAKE SURE IT WORKS/EXTEND FUNCTIONALITY
//
//
- (NSMutableArray *)createPhotosArray:(NSArray *)jsonArray
{
flickrPhotosArray = [[NSMutableArray alloc] init];

for (NSDictionary *photo in jsonArray)
{
float latitude = [[photo valueForKey:@"latitude"] floatValue];
float longitude = [[photo valueForKey:@"longitude"] floatValue];
CLLocation *loc = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];

Venue *currentPhoto = [[Venue alloc] init];
currentPhoto.name = [photo valueForKey:@"name"];
currentPhoto.location = loc;
currentPhoto.yelpURL= [photo valueForKey:@"url"];

[flickrPhotosArray addObject:currentPhoto];
}
return flickrPhotosArray;
}
@end
6 changes: 4 additions & 2 deletions MappingMashupApp/DataSourceDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

@protocol DataSourceDelegate <NSObject>

//- (void)grabArray:(NSArray *)data;
// SHOULD LOCATIONMANAGER BE THE DATASOURCE DELEGATE?

-(void)addPinsToMap:(NSArray*)data;
//- (void)grabArray:(NSArray *)data;
//processYelpSearch?
//- (void)addPinsToMap:(NSArray*)data;

@end
4 changes: 0 additions & 4 deletions MappingMashupApp/FlickrMapViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
#import <MapKit/MapKit.h>
#import <CoreData/CoreData.h>
#import "DataSourceDelegate.h"
#import "AppDelegate.h"

@interface FlickrMapViewController : UIViewController <MKMapViewDelegate, DataSourceDelegate>

@property (strong, nonatomic) NSMutableArray *venuesArray;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;

-(void)addPinsToMap;

@end
Loading

0 comments on commit a4eac87

Please sign in to comment.