Jamie Pinkham

added use cases in iphone sample

@@ -19,6 +19,12 @@ @@ -19,6 +19,12 @@
19 [self setRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/top_secret/"]]]; 19 [self setRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/top_secret/"]]];
20 [request setUseKeychainPersistence:[useKeychain isOn]]; 20 [request setUseKeychainPersistence:[useKeychain isOn]];
21 [request setDelegate:self]; 21 [request setDelegate:self];
  22 + [request setAuthenticationNeededBlock:^(ASIHTTPRequest *request){
  23 + NSLog(@"authentication needed");
  24 + }];
  25 + [request setProxyAuthenticationNeededBlock:^(ASIHTTPRequest *request){
  26 + NSLog(@"proxy authentication needed");
  27 + }];
22 [request setShouldPresentAuthenticationDialog:[useBuiltInDialog isOn]]; 28 [request setShouldPresentAuthenticationDialog:[useBuiltInDialog isOn]];
23 [request setDidFinishSelector:@selector(topSecretFetchComplete:)]; 29 [request setDidFinishSelector:@selector(topSecretFetchComplete:)];
24 [request setDidFailSelector:@selector(topSecretFetchFailed:)]; 30 [request setDidFailSelector:@selector(topSecretFetchFailed:)];
@@ -17,6 +17,16 @@ @@ -17,6 +17,16 @@
17 17
18 - (IBAction)fetchThreeImages:(id)sender 18 - (IBAction)fetchThreeImages:(id)sender
19 { 19 {
  20 + ASIHTTPRequestSizeBlock sizeBlock = ^(ASIHTTPRequest *request, long long size){
  21 + NSDictionary *userInfo = [request userInfo];
  22 + NSLog(@"request - %@ named = %@ download size incremented %lld", request, [userInfo valueForKey:@"name"], size);
  23 + };
  24 +
  25 + ASIHTTPRequestProgressBlock bytesBlock = ^(ASIHTTPRequest *request, unsigned long long size, unsigned long long total){
  26 + NSDictionary *userInfo = [request userInfo];
  27 + NSLog(@"request - %@ named - %@ downloaded bytes size %llu of total: %llu", request, [userInfo valueForKey:@"name"], size, total);
  28 + };
  29 +
20 [imageView1 setImage:nil]; 30 [imageView1 setImage:nil];
21 [imageView2 setImage:nil]; 31 [imageView2 setImage:nil];
22 [imageView3 setImage:nil]; 32 [imageView3 setImage:nil];
@@ -34,18 +44,27 @@ @@ -34,18 +44,27 @@
34 44
35 ASIHTTPRequest *request; 45 ASIHTTPRequest *request;
36 request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"]]; 46 request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"]];
  47 + [request setDownloadSizeIncrementedBlock:sizeBlock];
  48 + [request setBytesReceivedBlock:bytesBlock];
37 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]]; 49 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
38 [request setDownloadProgressDelegate:imageProgressIndicator1]; 50 [request setDownloadProgressDelegate:imageProgressIndicator1];
  51 + [request setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]];
39 [networkQueue addOperation:request]; 52 [networkQueue addOperation:request];
40 53
41 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"]] autorelease]; 54 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"]] autorelease];
  55 + [request setDownloadSizeIncrementedBlock:sizeBlock];
  56 + [request setBytesReceivedBlock:bytesBlock];
42 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"2.png"]]; 57 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"2.png"]];
43 [request setDownloadProgressDelegate:imageProgressIndicator2]; 58 [request setDownloadProgressDelegate:imageProgressIndicator2];
  59 + [request setUserInfo:[NSDictionary dictionaryWithObject:@"request2" forKey:@"name"]];
44 [networkQueue addOperation:request]; 60 [networkQueue addOperation:request];
45 61
46 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]] autorelease]; 62 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]] autorelease];
  63 + [request setDownloadSizeIncrementedBlock:sizeBlock];
  64 + [request setBytesReceivedBlock:bytesBlock];
47 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"3.png"]]; 65 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"3.png"]];
48 [request setDownloadProgressDelegate:imageProgressIndicator3]; 66 [request setDownloadProgressDelegate:imageProgressIndicator3];
  67 + [request setUserInfo:[NSDictionary dictionaryWithObject:@"request3" forKey:@"name"]];
49 [networkQueue addOperation:request]; 68 [networkQueue addOperation:request];
50 69
51 [networkQueue go]; 70 [networkQueue go];
@@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
19 { 19 {
20 20
21 NSURL *url = [NSURL URLWithString:[urlField text]]; 21 NSURL *url = [NSURL URLWithString:[urlField text]];
  22 + NSMutableData *recievedData = [NSMutableData data];
22 // Create a request 23 // Create a request
23 // You don't normally need to retain a synchronous request, but we need to in this case because we'll need it later if we reload the table data 24 // You don't normally need to retain a synchronous request, but we need to in this case because we'll need it later if we reload the table data
24 [self setRequest:[ASIHTTPRequest requestWithURL:url]]; 25 [self setRequest:[ASIHTTPRequest requestWithURL:url]];
@@ -26,6 +27,34 @@ @@ -26,6 +27,34 @@
26 //Customise our user agent, for no real reason 27 //Customise our user agent, for no real reason
27 [request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"]; 28 [request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
28 29
  30 + [request setStartedBlock:^(ASIHTTPRequest *aRequest){
  31 + NSLog(@"started!");
  32 + }];
  33 + [request setHeadersReceivedBlock:^(ASIHTTPRequest *aRequest){
  34 + NSLog(@"headers recieved");
  35 + }];
  36 +
  37 + [request setBytesReceivedBlock:^(ASIHTTPRequest *aRequest, unsigned long long length, unsigned long long total){
  38 + NSLog(@"bytes received:%llu of total: %llu", length, total);
  39 + }];
  40 +
  41 + [request setDownloadSizeIncrementedBlock:^(ASIHTTPRequest *aRequest, long long length){
  42 + NSLog(@"download size incremented:%lld", length);
  43 + }];
  44 +
  45 + [request setDataReceivedBlock:^(ASIHTTPRequest *aRequest, NSData *data){
  46 + [recievedData appendData:data];
  47 + NSLog(@"data - %@", recievedData);
  48 + }];
  49 +
  50 + [request setCompletionBlock:^(ASIHTTPRequest *aRequest){
  51 + if ([aRequest error]) {
  52 + NSLog(@"error from block");
  53 + } else if ([aRequest responseString]) {
  54 + NSLog(@"finish from block");
  55 + }
  56 + }];
  57 +
29 // Start the request 58 // Start the request
30 [request startSynchronous]; 59 [request startSynchronous];
31 60
@@ -20,10 +20,17 @@ @@ -20,10 +20,17 @@
20 [request setPostValue:@"test" forKey:@"value2"]; 20 [request setPostValue:@"test" forKey:@"value2"];
21 [request setPostValue:@"test" forKey:@"value3"]; 21 [request setPostValue:@"test" forKey:@"value3"];
22 [request setTimeOutSeconds:20]; 22 [request setTimeOutSeconds:20];
23 - [request setUploadProgressDelegate:progressIndicator]; 23 + [request setBytesSentBlock:^(ASIHTTPRequest *request, unsigned long long length, unsigned long long total){
  24 + NSLog(@"sent %llu bytes of %llu total", length, total);
  25 + }];
  26 +
  27 + [request setUploadSizeIncrementedBlock:^(ASIHTTPRequest *request, long long length){
  28 + NSLog(@"upload size incremented = %lld",length);
  29 + }];
  30 + /*[request setUploadProgressDelegate:progressIndicator];
24 [request setDelegate:self]; 31 [request setDelegate:self];
25 [request setDidFailSelector:@selector(uploadFailed:)]; 32 [request setDidFailSelector:@selector(uploadFailed:)];
26 - [request setDidFinishSelector:@selector(uploadFinished:)]; 33 + [request setDidFinishSelector:@selector(uploadFinished:)];*/
27 34
28 //Create a 256KB file 35 //Create a 256KB file
29 NSData *data = [[[NSMutableData alloc] initWithLength:256*1024] autorelease]; 36 NSData *data = [[[NSMutableData alloc] initWithLength:256*1024] autorelease];