Ben Copsey

Added PUTRequestForData:etc to ASIS3Request

Closes gh-14.

Also fixed unit tests for S3 on Mac, continued fallout from that setDoubleValue: debacle
@@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
21 #import "ASIInputStream.h" 21 #import "ASIInputStream.h"
22 22
23 // Automatically set on build 23 // Automatically set on build
24 -NSString *ASIHTTPRequestVersion = @"v1.2-23 2009-12-18"; 24 +NSString *ASIHTTPRequestVersion = @"v1.2-24 2009-12-18";
25 25
26 // We use our own custom run loop mode as CoreAnimation seems to want to hijack our threads otherwise 26 // We use our own custom run loop mode as CoreAnimation seems to want to hijack our threads otherwise
27 static CFStringRef ASIHTTPRequestRunMode = CFSTR("ASIHTTPRequest"); 27 static CFStringRef ASIHTTPRequestRunMode = CFSTR("ASIHTTPRequest");
@@ -69,6 +69,9 @@ typedef enum _ASIS3ErrorType { @@ -69,6 +69,9 @@ typedef enum _ASIS3ErrorType {
69 // Create a PUT request using the file at filePath as the body 69 // Create a PUT request using the file at filePath as the body
70 + (id)PUTRequestForFile:(NSString *)filePath withBucket:(NSString *)bucket path:(NSString *)path; 70 + (id)PUTRequestForFile:(NSString *)filePath withBucket:(NSString *)bucket path:(NSString *)path;
71 71
  72 +// Create a PUT request using the supplied NSData as the body (set the mime-type manually with setMimeType: if necessary)
  73 ++ (id)PUTRequestForData:(NSData *)data withBucket:(NSString *)bucket path:(NSString *)path;
  74 +
72 // Create a DELETE request for the object at path 75 // Create a DELETE request for the object at path
73 + (id)DELETERequestWithBucket:(NSString *)bucket path:(NSString *)path; 76 + (id)DELETERequestWithBucket:(NSString *)bucket path:(NSString *)path;
74 77
@@ -37,6 +37,14 @@ static NSString *sharedSecretAccessKey = nil; @@ -37,6 +37,14 @@ static NSString *sharedSecretAccessKey = nil;
37 return request; 37 return request;
38 } 38 }
39 39
  40 ++ (id)PUTRequestForData:(NSData *)data withBucket:(NSString *)bucket path:(NSString *)path
  41 +{
  42 + ASIS3Request *request = [self requestWithBucket:bucket path:path];
  43 + [request appendPostData:data];
  44 + [request setRequestMethod:@"PUT"];
  45 + return request;
  46 +}
  47 +
40 + (id)PUTRequestForFile:(NSString *)filePath withBucket:(NSString *)bucket path:(NSString *)path 48 + (id)PUTRequestForFile:(NSString *)filePath withBucket:(NSString *)bucket path:(NSString *)path
41 { 49 {
42 ASIS3Request *request = [self requestWithBucket:bucket path:path]; 50 ASIS3Request *request = [self requestWithBucket:bucket path:path];
@@ -220,6 +220,35 @@ static NSString *bucket = @""; @@ -220,6 +220,35 @@ static NSString *bucket = @"";
220 220
221 success = [[[request error] localizedDescription] isEqualToString:@"The specified key does not exist."]; 221 success = [[[request error] localizedDescription] isEqualToString:@"The specified key does not exist."];
222 GHAssertTrue(success, @"Got the wrong error message"); 222 GHAssertTrue(success, @"Got the wrong error message");
  223 +
  224 + // PUT some data
  225 + NSData *data = [@"Hello" dataUsingEncoding:NSUTF8StringEncoding];
  226 + request = [ASIS3Request PUTRequestForData:data withBucket:bucket path:path];
  227 + [request setMimeType:@"text/plain"];
  228 + [request setSecretAccessKey:secretAccessKey];
  229 + [request setAccessKey:accessKey];
  230 + [request start];
  231 + success = [[request responseString] isEqualToString:@""];
  232 + GHAssertTrue(success,@"Failed to PUT data to S3");
  233 +
  234 + // GET the data to check it uploaded properly
  235 + request = [ASIS3Request requestWithBucket:bucket path:path];
  236 + [request setSecretAccessKey:secretAccessKey];
  237 + [request setAccessKey:accessKey];
  238 + [request start];
  239 + success = [[request responseString] isEqualToString:@"Hello"];
  240 + GHAssertTrue(success,@"Failed to GET the correct data from S3");
  241 +
  242 + // clean up (Delete it)
  243 + request = [ASIS3Request requestWithBucket:bucket path:path];
  244 + [request setSecretAccessKey:secretAccessKey];
  245 + [request setRequestMethod:@"DELETE"];
  246 + [request setAccessKey:accessKey];
  247 + [request start];
  248 + success = [[request responseString] isEqualToString:@""];
  249 + GHAssertTrue(success,@"Failed to DELETE the file from S3");
  250 +
  251 +
223 } 252 }
224 253
225 // Will upload a file to S3, gzipping it before uploading 254 // Will upload a file to S3, gzipping it before uploading
@@ -463,7 +492,13 @@ static NSString *bucket = @""; @@ -463,7 +492,13 @@ static NSString *bucket = @"";
463 [[self networkQueue] go]; 492 [[self networkQueue] go];
464 493
465 } 494 }
466 - 495 +
  496 +// Will be called on Mac OS
  497 +- (void)setDoubleValue:(double)newProgress;
  498 +{
  499 + progress = (float)newProgress;
  500 +}
  501 +
467 - (void)setProgress:(float)newProgress; 502 - (void)setProgress:(float)newProgress;
468 { 503 {
469 progress = newProgress; 504 progress = newProgress;