OSDN Git Service

The first working revision.
[dirac/master.git] / Dirac / DiracURLLoader.m
1 //
2 //  DiracURLLoader.m
3 //  Dirac
4 //
5 //  Created by Ichi Kanaya on 11/04/21.
6 //  Copyright 2011 大阪大学. All rights reserved.
7 //
8
9 #import "DiracURLLoader.h"
10
11
12 @implementation DiracURLLoader
13
14 @synthesize connection;
15 @synthesize data;
16
17 - (id)init {
18     self = [super init];
19     if (self) {
20         // Initialization code here.
21     }    
22     return self;
23 }
24
25 - (void)dealloc {
26     [connection release];
27     [data release];
28     [super dealloc];
29 }
30
31 - (void)connection: (NSURLConnection *)connection didReceiveResponse: (NSURLResponse *)response {
32     self.data = [NSMutableData data];
33 }
34
35 - (void)connection: (NSURLConnection *)connection didReceiveData: (NSData *)receiveData {
36     [self.data appendData:receiveData];
37 }
38
39 - (void)connectionDidFinishLoading: (NSURLConnection *)connection {
40     [[NSNotificationCenter defaultCenter] postNotificationName: @"connectionDidFinishNotification" 
41                                                         object: self];
42 }
43
44 - (void)connection: (NSURLConnection *)connection didFailWithError: (NSError *)error {
45     [[NSNotificationCenter defaultCenter] postNotificationName: @"connectionDidFailWithError" 
46                                                         object: self];
47 }
48
49 - (void)loadFromUrl: (NSString *)url method: (NSString *) method {
50     NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: url]];
51     [req setHTTPMethod: method];
52     self.connection = [NSURLConnection connectionWithRequest: req delegate: self];
53 }
54
55
56
57 @end