Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 28 additions & 2 deletions TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
51ED6E081BB32F90006DB93B /* APImanager.m in Sources */ = {isa = PBXBuildFile; fileRef = 51ED6E071BB32F90006DB93B /* APImanager.m */; settings = {ASSET_TAGS = (); }; };
51ED6E0B1BB4BB72006DB93B /* APIViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 51ED6E0A1BB4BB72006DB93B /* APIViewController.m */; settings = {ASSET_TAGS = (); }; };
51ED6E0E1BB4BB9C006DB93B /* APIDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 51ED6E0D1BB4BB9C006DB93B /* APIDetailViewController.m */; settings = {ASSET_TAGS = (); }; };
51ED6E111BB4BD17006DB93B /* APIResults.m in Sources */ = {isa = PBXBuildFile; fileRef = 51ED6E101BB4BD17006DB93B /* APIResults.m */; settings = {ASSET_TAGS = (); }; };
8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4A1BAF859400A92AD2 /* main.m */; };
8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */; };
8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD501BAF859400A92AD2 /* ViewController.m */; };
Expand All @@ -16,6 +20,14 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
51ED6E061BB32F90006DB93B /* APImanager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APImanager.h; sourceTree = "<group>"; };
51ED6E071BB32F90006DB93B /* APImanager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APImanager.m; sourceTree = "<group>"; };
51ED6E091BB4BB72006DB93B /* APIViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIViewController.h; sourceTree = "<group>"; };
51ED6E0A1BB4BB72006DB93B /* APIViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIViewController.m; sourceTree = "<group>"; };
51ED6E0C1BB4BB9C006DB93B /* APIDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIDetailViewController.h; sourceTree = "<group>"; };
51ED6E0D1BB4BB9C006DB93B /* APIDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIDetailViewController.m; sourceTree = "<group>"; };
51ED6E0F1BB4BD17006DB93B /* APIResults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIResults.h; sourceTree = "<group>"; };
51ED6E101BB4BD17006DB93B /* APIResults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIResults.m; sourceTree = "<group>"; };
8D7DCD461BAF859400A92AD2 /* TalkinToTheNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TalkinToTheNet.app; sourceTree = BUILT_PRODUCTS_DIR; };
8D7DCD4A1BAF859400A92AD2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand All @@ -42,7 +54,7 @@
8D7DCD3D1BAF859400A92AD2 = {
isa = PBXGroup;
children = (
8D7DCD481BAF859400A92AD2 /* TalkinToTheNet */,
8D7DCD481BAF859400A92AD2 /* General */,
8D7DCD471BAF859400A92AD2 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -55,19 +67,28 @@
name = Products;
sourceTree = "<group>";
};
8D7DCD481BAF859400A92AD2 /* TalkinToTheNet */ = {
8D7DCD481BAF859400A92AD2 /* General */ = {
isa = PBXGroup;
children = (
8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */,
8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */,
8D7DCD4F1BAF859400A92AD2 /* ViewController.h */,
8D7DCD501BAF859400A92AD2 /* ViewController.m */,
51ED6E061BB32F90006DB93B /* APImanager.h */,
51ED6E071BB32F90006DB93B /* APImanager.m */,
51ED6E0F1BB4BD17006DB93B /* APIResults.h */,
51ED6E101BB4BD17006DB93B /* APIResults.m */,
51ED6E091BB4BB72006DB93B /* APIViewController.h */,
51ED6E0A1BB4BB72006DB93B /* APIViewController.m */,
8D7DCD521BAF859400A92AD2 /* Main.storyboard */,
51ED6E0C1BB4BB9C006DB93B /* APIDetailViewController.h */,
51ED6E0D1BB4BB9C006DB93B /* APIDetailViewController.m */,
8D7DCD551BAF859400A92AD2 /* Assets.xcassets */,
8D7DCD571BAF859400A92AD2 /* LaunchScreen.storyboard */,
8D7DCD5A1BAF859400A92AD2 /* Info.plist */,
8D7DCD491BAF859400A92AD2 /* Supporting Files */,
);
name = General;
path = TalkinToTheNet;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -149,8 +170,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
51ED6E0E1BB4BB9C006DB93B /* APIDetailViewController.m in Sources */,
51ED6E081BB32F90006DB93B /* APImanager.m in Sources */,
51ED6E111BB4BD17006DB93B /* APIResults.m in Sources */,
8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */,
8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */,
51ED6E0B1BB4BB72006DB93B /* APIViewController.m in Sources */,
8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -300,6 +325,7 @@
8D7DCD5F1BAF859400A92AD2 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
16 changes: 16 additions & 0 deletions TalkinToTheNet/TalkinToTheNet/APIDetailViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// APIDetailViewController.h
// TalkinToTheNet
//
// Created by Natalia Estrella on 9/24/15.
// Copyright © 2015 Mike Kavouras. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "APIResults.h"

@interface APIDetailViewController : UIViewController

@property (nonatomic) APIResults *result;

@end
82 changes: 82 additions & 0 deletions TalkinToTheNet/TalkinToTheNet/APIDetailViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// APIDetailViewController.m
// TalkinToTheNet
//
// Created by Natalia Estrella on 9/24/15.
// Copyright © 2015 Mike Kavouras. All rights reserved.
//

#import "APIDetailViewController.h"
#import "APImanager.h"

@interface APIDetailViewController ()
@property (strong, nonatomic) IBOutlet UIImageView *detailImageView;
@property (strong, nonatomic) IBOutlet UILabel *detailNameLabel;
@property (strong, nonatomic) IBOutlet UILabel *detailAdressLabel;

@end

@implementation APIDetailViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.detailNameLabel.text = self.result.name;
self.detailAdressLabel.text = [self.result.address componentsJoinedByString:@"\n"];







//url(media=music, term=searchTerm)
NSString *urlString= [NSString stringWithFormat:@"https://api.giphy.com/v1/gifs/search?q=%@&api_key=dc6zaTOxFJmzC", self.result.name];

//encoded URL
NSString *encodingString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];


//make the request
//do somehting with the data

NSURL *url = [NSURL URLWithString:encodingString];
[APImanager GETRequestWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

if (!data) return;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:(NSData *)data options:0 error:nil];

NSString *imageURLString = [json[@"data"] firstObject][@"images"][@"original_still"][@"url"];
NSURL *imageURL = [NSURL URLWithString:imageURLString];


NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData: imageData];
self.detailImageView.image = image;
}];









}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
17 changes: 17 additions & 0 deletions TalkinToTheNet/TalkinToTheNet/APIResults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// APIResults.h
// TalkinToTheNet
//
// Created by Natalia Estrella on 9/24/15.
// Copyright © 2015 Mike Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface APIResults : NSObject

@property (nonatomic) NSString *name;
@property (nonatomic) NSArray *address;


@end
13 changes: 13 additions & 0 deletions TalkinToTheNet/TalkinToTheNet/APIResults.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// APIResults.m
// TalkinToTheNet
//
// Created by Natalia Estrella on 9/24/15.
// Copyright © 2015 Mike Kavouras. All rights reserved.
//

#import "APIResults.h"

@implementation APIResults

@end
13 changes: 13 additions & 0 deletions TalkinToTheNet/TalkinToTheNet/APIViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// APIViewController.h
// TalkinToTheNet
//
// Created by Natalia Estrella on 9/24/15.
// Copyright © 2015 Mike Kavouras. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface APIViewController : UIViewController

@end
139 changes: 139 additions & 0 deletions TalkinToTheNet/TalkinToTheNet/APIViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
//
// APIViewController.m
// TalkinToTheNet
//
// Created by Natalia Estrella on 9/24/15.
// Copyright © 2015 Mike Kavouras. All rights reserved.
//

#import "APIViewController.h"
#import "APImanager.h"
#import "APIResults.h"
#import "APIDetailViewController.h"



@interface APIViewController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *searchTextField;
@property (strong, nonatomic) IBOutlet UITableView *tableView;

@property (strong, nonatomic) NSMutableArray *searchResults;
@end

@implementation APIViewController

-(void) viewDidLoad {
[super viewDidLoad];

self.tableView.dataSource = self;
self.tableView.delegate = self;

self. searchTextField.delegate = self;
}
-(void)makeFoursquareResquest:(NSString *)searchTerm
callbacKBlock:(void(^)())block{

//search term (from parameter)

//url(media=music, term=searchTerm)
NSString *urlString= [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/search?client_id=FHAENKZF2HR2UU4JZ23CSSYGXABP3SGMNIKU5QMK4GEP1OXU&client_secret=Q43OVAQPHPZW1PKBYB05YKURVRIOKZUFMEN3ND3UEH5CJAKI&v=20130815&ll=40.7,-74&query=%@", searchTerm];

//encoded URL
NSString *encodingString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

NSLog(@"%@", encodingString);

//make the request
//do somehting with the data

NSURL *url = [NSURL URLWithString:encodingString];
[APImanager GETRequestWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

if (data !=nil) {

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:(NSData *)data options:0 error:nil];
NSLog(@"%@", json);

// NSArray *results = [json objectForKey:@"results"];



self.searchResults = [[NSMutableArray alloc] init];

for (NSDictionary *venue in json[@"response"][@"venues"]) {

NSString *name = venue[@"name"];
NSArray *address = venue[@"location"][@"formattedAddress"];


APIResults *searchObject = [[APIResults alloc] init];


searchObject.name = name;
searchObject.address = address;

[self.searchResults addObject:searchObject];

}
block ();
}

}];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.searchResults.count;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath];

APIResults *currentResult = self.searchResults[indexPath.row];
cell.textLabel.text = currentResult.name;
cell.detailTextLabel.text = currentResult.address.firstObject;


return cell;
}

- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
[self performSegueWithIdentifier:@"DetailSegue" sender:self.searchResults[indexPath.row]];
}

#pragma mark - text field delegate

//user tapped return
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
//dimiss the keyboard and lose focus
[self.view endEditing:YES];


//make an API request
[self makeFoursquareResquest:textField.text callbacKBlock:^{
[self.tableView reloadData];
}];

return YES;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.


APIDetailViewController *detailVC = [segue destinationViewController];

detailVC.result = sender;



}


@end
16 changes: 16 additions & 0 deletions TalkinToTheNet/TalkinToTheNet/APImanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// APImanager.h
// API_II
//
// Created by Natalia Estrella on 9/20/15.
// Copyright © 2015 Natalia Estrella. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface APImanager : NSObject

+ (void)GETRequestWithURL:(NSURL *)URL
completionHandler:(void(^)(NSData *data, NSURLResponse *response, NSError *error)) completionHandler ;

@end
Loading