Skip to content

Commit

Permalink
using BEST BUY json api
Browse files Browse the repository at this point in the history
  • Loading branch information
Benyam Solomon authored and Benyam Solomon committed Apr 23, 2012
1 parent baae25b commit f5c3fa2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
Binary file not shown.
8 changes: 1 addition & 7 deletions thankxBuddyApp/ModevUXAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

#import <UIKit/UIKit.h>

@interface ModevUXAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> {
UINavigationController *navigationController;
UITabBarController *tabBarController;

}
@interface ModevUXAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) UITabBarController *tabBarController;

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end
14 changes: 9 additions & 5 deletions thankxBuddyApp/ModevUXFirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//


#define giftsListURL [NSURL URLWithString:@"http://10.24.110.253:5000/messages"]
#define giftsListURL [NSURL URLWithString:@"http://api.remix.bestbuy.com/v1/products(manufacturer=apple)?apiKey=gcbrumxjpnwp2tg3ebhss933&format=json&sort=name.asc"]

#import "ModevUXFirstViewController.h"

Expand Down Expand Up @@ -90,12 +90,13 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
goodiesArray = [NSJSONSerialization
NSDictionary *criteria = [NSJSONSerialization
JSONObjectWithData:responseData //1

options:kNilOptions
error:&error];

goodiesArray = [criteria objectForKey:@"products"];
// NSLog(@"goodies=%@", goodiesArray);
}

Expand Down Expand Up @@ -130,12 +131,15 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

NSDictionary *items = [[NSDictionary alloc] init];
items = [goodiesArray objectAtIndex:[indexPath row]];
NSLog(@"GOODIES=%@", goodiesArray);

title = [items objectForKey:@"to"];
title = [items objectForKey:@"name"];

[cell.textLabel setText:title];
// cell.imageView.image = [items objectForKey:@"img"];
NSString *thumbnailImage = [items objectForKey:@"thumbnailImage"];

UIImage *tn = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumbnailImage]]];

cell.imageView.image = tn;

cell.textLabel.font = font;

Expand Down
2 changes: 2 additions & 0 deletions thankxBuddyApp/ModevUXSecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
UITableView *giveawaysTable;
}

@property (nonatomic, retain) UINavigationController *navigationController;

@end
24 changes: 15 additions & 9 deletions thankxBuddyApp/ModevUXSecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#define giveawaysListURL [NSURL URLWithString:@"http://10.24.110.253:5000/products"]
#define giveawaysListURL [NSURL URLWithString:@"http://api.remix.bestbuy.com/v1/products(manufacturer=motorola)?apiKey=gcbrumxjpnwp2tg3ebhss933&format=json&sort=name.asc"]

#import "ModevUXSecondViewController.h"
#import "DetailViewController.h"

@implementation ModevUXSecondViewController

@synthesize navigationController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
Expand Down Expand Up @@ -46,6 +48,7 @@ - (void)viewDidLoad
withObject:data waitUntilDone:YES];
});

navigationController = [[UINavigationController alloc] init];
}

- (void)viewDidUnload
Expand Down Expand Up @@ -84,13 +87,14 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
giveawaysArray = [NSJSONSerialization
NSDictionary *productList = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];


NSLog(@"givawayarray=%@",giveawaysArray);
giveawaysArray = [productList objectForKey:@"products"];
// NSLog(@"givawayarray=%@",giveawaysArray);
}

#pragma mark - Table view data source
Expand All @@ -116,7 +120,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

NSString *title;
Expand All @@ -126,18 +129,21 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
items = [giveawaysArray objectAtIndex:[indexPath row]];
NSLog(@"items=%@", items);

title = [items objectForKey:@"descShort"];
// title = [[giftsDict objectAtIndex:indexPath.row] objectForKey:@"title"];
title = [items objectForKey:@"name"];

[cell.textLabel setText:title];

/*
// http://10.23.28.44:5000/products
NSString *baseUrl = [[NSString alloc] initWithString:@"http://10.24.110.253:5000"];
NSString *itemUrl = [items objectForKey:@"img"];
NSString *itemUrl = [items objectForKey:@"thumbnailImage"];
NSString *theImageUrl = [[NSString alloc] initWithFormat:@"%@%@", baseUrl, itemUrl];
*/

NSString *thumbnailImage = [items objectForKey:@"thumbnailImage"];

UIImage *tn = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:theImageUrl]]];
UIImage *tn = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumbnailImage]]];

//UIImage *tn = [UIImage imageWithData:[managedObject valueForKey:@"thumbnail"]];
cell.imageView.image = tn;
Expand All @@ -157,7 +163,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.selectedItem = [giveawaysArray objectAtIndex:[indexPath row]];

// [self.navigationController pushViewController:detailViewController animated:YES];
// [navigationController pushViewController:detailViewController animated:YES];

}

Expand Down

0 comments on commit f5c3fa2

Please sign in to comment.