summaryrefslogtreecommitdiffstats
path: root/Classes/Fetcher.m
diff options
context:
space:
mode:
authormatt handler <matt.handler@gmail.com>2011-04-26 17:18:49 -0400
committermatt handler <matt.handler@gmail.com>2011-04-26 17:18:49 -0400
commit46642320901ebaaedae5618e423ebfe70f316351 (patch)
treefa4f7d55589c1057ee8e33194a71bbf7b587960a /Classes/Fetcher.m
parent9ac2c9e13eb63c2a3a5e9b5a14b079d4fc24a220 (diff)
downloadpiccast-app-46642320901ebaaedae5618e423ebfe70f316351.tar.gz
piccast-app-46642320901ebaaedae5618e423ebfe70f316351.zip
updated topics dynamic loading, added fetcher class, storing in database and not overwriting is good, need to add info to photo view controller and also sort results
Diffstat (limited to 'Classes/Fetcher.m')
-rw-r--r--Classes/Fetcher.m61
1 files changed, 61 insertions, 0 deletions
diff --git a/Classes/Fetcher.m b/Classes/Fetcher.m
new file mode 100644
index 0000000..3fe162f
--- /dev/null
+++ b/Classes/Fetcher.m
@@ -0,0 +1,61 @@
+//
+// Fetcher.m
+// PicCast
+//
+// Created by Matthew Handler on 4/26/11.
+// Copyright 2011 Earl Industries. All rights reserved.
+//
+
+#import "Fetcher.h"
+#import "PicCastAppDelegate.h"
+
+@implementation Fetcher
+
+@synthesize delegate;
+
++ (Fetcher *) initWithString:(NSString *)string andDelegate:(id<FetcherDelegate>)d {
+ Fetcher *fetcher = [[[Fetcher alloc] init] autorelease];
+ fetcher.delegate = d;
+ [fetcher setUrlAndConnect:string];
+ return fetcher;
+}
+
+- (Fetcher *) init {
+ receivedData = [[NSMutableData data] retain];
+ return self;
+}
+
+- (void) setUrlAndConnect:(NSString *)string {
+
+ NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:string]
+ cachePolicy:NSURLRequestUseProtocolCachePolicy
+ timeoutInterval:30.0];
+ if ([NSURLConnection connectionWithRequest:theRequest delegate:self]) {
+ [receivedData setLength:0];
+ } else {
+ [PicCastAppDelegate prompt:@"Error" withMessage:@"No internet connection" andButtonTitle:@"shucks" withDelegate:self];
+ }
+}
+
+- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
+ [receivedData setLength:0];
+}
+
+- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
+ [receivedData appendData:data];
+}
+
+- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
+ [delegate connection:connection failedWithError:error];
+}
+
+- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
+ [delegate connection:connection finishedWithData:receivedData];
+}
+
+- (void) dealloc {
+ [receivedData release];
+ [super dealloc];
+}
+
+@end