-
Notifications
You must be signed in to change notification settings - Fork 2
/
GravatarCommunicator.m
44 lines (32 loc) · 1.11 KB
/
GravatarCommunicator.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// GravatarCommunicator.m
// BrowseOverflow
//
// Created by Graham J Lee on 26/05/2011.
// Copyright 2011 Fuzzy Aliens Ltd. All rights reserved.
//
#import "GravatarCommunicator.h"
@implementation GravatarCommunicator
@synthesize url;
@synthesize delegate;
@synthesize receivedData;
@synthesize connection;
- (void)fetchDataForURL:(NSURL *)location {
self.url = location;
NSURLRequest *request = [NSURLRequest requestWithURL: location];
self.connection = [NSURLConnection connectionWithRequest: request delegate: self];
}
#pragma mark NSURLConnection Delegate
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[delegate communicatorReceivedData: [receivedData copy] forURL: url];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
self.receivedData = [NSMutableData data];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData: data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[delegate communicatorGotErrorForURL: url];
}
@end