// // ShareViewController.m // NewsBlur // // Created by Roy Yang on 6/21/12. // Copyright (c) 2012 NewsBlur. All rights reserved. // #import "ShareViewController.h" #import "NewsBlurAppDelegate.h" #import #import "ASIHTTPRequest.h" @implementation ShareViewController @synthesize commentField; @synthesize appDelegate; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. commentField.layer.borderWidth = 1.0f; commentField.layer.cornerRadius = 8; commentField.layer.borderColor = [[UIColor grayColor] CGColor]; } - (void)viewDidUnload { [self setCommentField:nil]; [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)dealloc { [appDelegate release]; [commentField release]; [super dealloc]; } - (IBAction)doCancelButton:(id)sender { [appDelegate hideShareView]; } - (IBAction)doToggleButton:(id)sender { UIButton *button = (UIButton *)sender; if (button.selected) { button.selected = NO; } else { button.selected = YES; } } - (IBAction)doShareThisStory:(id)sender { for (id key in appDelegate.activeStory) { NSLog(@"Key in appDelegate.activeStory is %@" , key); } NSString *urlString = [NSString stringWithFormat:@"http://%@/social/share_story", NEWSBLUR_URL]; NSString *feedIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"story_feed_id"]]; NSString *storyIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"id"]]; NSURL *url = [NSURL URLWithString:urlString]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request setPostValue:feedIdStr forKey:@"feed_id"]; [request setPostValue:storyIdStr forKey:@"story_id"]; [request setPostValue:@"Hello World" forKey:@"comments"]; [request setDelegate:self]; [request setDidFinishSelector:@selector(finishAddComment:)]; [request setDidFailSelector:@selector(requestFailed:)]; [request startAsynchronous]; } - (void)finishAddComment:(ASIHTTPRequest *)request { NSLog(@"%@", [request responseString]); NSLog(@"Successfully added."); [appDelegate hideShareView]; } - (void)requestFailed:(ASIHTTPRequest *)request { NSError *error = [request error]; NSLog(@"Error: %@", error); } @end