Showing
5 changed files
with
20 additions
and
12 deletions
| @@ -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.6-5 2010-03-16"; | 24 | +NSString *ASIHTTPRequestVersion = @"v1.6-6 2010-03-16"; |
| 25 | 25 | ||
| 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
| 27 | 27 |
| @@ -56,7 +56,6 @@ | @@ -56,7 +56,6 @@ | ||
| 56 | //Builds a query string out of the list parameters we supplied | 56 | //Builds a query string out of the list parameters we supplied |
| 57 | - (void)createQueryString; | 57 | - (void)createQueryString; |
| 58 | 58 | ||
| 59 | - | ||
| 60 | // Returns a date formatter than can be used to parse a date from S3 | 59 | // Returns a date formatter than can be used to parse a date from S3 |
| 61 | + (NSDateFormatter *)dateFormatter; | 60 | + (NSDateFormatter *)dateFormatter; |
| 62 | 61 |
| @@ -149,7 +149,7 @@ static NSDateFormatter *dateFormatter = nil; | @@ -149,7 +149,7 @@ static NSDateFormatter *dateFormatter = nil; | ||
| 149 | } else if ([elementName isEqualToString:@"Key"]) { | 149 | } else if ([elementName isEqualToString:@"Key"]) { |
| 150 | [[self currentObject] setKey:[self currentContent]]; | 150 | [[self currentObject] setKey:[self currentContent]]; |
| 151 | } else if ([elementName isEqualToString:@"LastModified"]) { | 151 | } else if ([elementName isEqualToString:@"LastModified"]) { |
| 152 | - [[self currentObject] setLastModified:[dateFormatter dateFromString:[self currentContent]]]; | 152 | + [[self currentObject] setLastModified:[[ASIS3BucketRequest dateFormatter] dateFromString:[self currentContent]]]; |
| 153 | } else if ([elementName isEqualToString:@"ETag"]) { | 153 | } else if ([elementName isEqualToString:@"ETag"]) { |
| 154 | [[self currentObject] setETag:[self currentContent]]; | 154 | [[self currentObject] setETag:[self currentContent]]; |
| 155 | } else if ([elementName isEqualToString:@"Size"]) { | 155 | } else if ([elementName isEqualToString:@"Size"]) { |
| @@ -42,7 +42,6 @@ | @@ -42,7 +42,6 @@ | ||
| 42 | // See the S3 REST API docs for more information about the parameters you can pass | 42 | // See the S3 REST API docs for more information about the parameters you can pass |
| 43 | + (id)requestWithBucket:(NSString *)bucket key:(NSString *)key subResource:(NSString *)subResource; | 43 | + (id)requestWithBucket:(NSString *)bucket key:(NSString *)key subResource:(NSString *)subResource; |
| 44 | 44 | ||
| 45 | - | ||
| 46 | // Create a PUT request using the file at filePath as the body | 45 | // Create a PUT request using the file at filePath as the body |
| 47 | + (id)PUTRequestForFile:(NSString *)filePath withBucket:(NSString *)bucket key:(NSString *)key; | 46 | + (id)PUTRequestForFile:(NSString *)filePath withBucket:(NSString *)bucket key:(NSString *)key; |
| 48 | 47 |
| @@ -36,14 +36,14 @@ static NSString *bucket = @""; | @@ -36,14 +36,14 @@ static NSString *bucket = @""; | ||
| 36 | 36 | ||
| 37 | @implementation ASIS3RequestTests | 37 | @implementation ASIS3RequestTests |
| 38 | 38 | ||
| 39 | + | ||
| 39 | - (void)testASIS3ServiceRequest | 40 | - (void)testASIS3ServiceRequest |
| 40 | { | 41 | { |
| 41 | -// ASIS3ServiceRequest *request = [ASIS3ServiceRequest serviceRequest]; | 42 | + ASIS3ServiceRequest *request = [ASIS3ServiceRequest serviceRequest]; |
| 42 | -// [request setSecretAccessKey:secretAccessKey]; | 43 | + [request setSecretAccessKey:secretAccessKey]; |
| 43 | -// [request setAccessKey:accessKey]; | 44 | + [request setAccessKey:accessKey]; |
| 44 | -// [request startSynchronous]; | 45 | + [request startSynchronous]; |
| 45 | -// NSLog(@"%@",[request responseString]); | 46 | + GHAssertNil([request error],@"Failed to fetch the list of buckets from S3"); |
| 46 | -// GHAssertNil([request error],@"Failed to fetch the list of buckets from S3"); | ||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | // All these tests are based on Amazon's examples at: http://docs.amazonwebservices.com/AmazonS3/2006-03-01/ | 49 | // All these tests are based on Amazon's examples at: http://docs.amazonwebservices.com/AmazonS3/2006-03-01/ |
| @@ -150,6 +150,7 @@ static NSString *bucket = @""; | @@ -150,6 +150,7 @@ static NSString *bucket = @""; | ||
| 150 | 150 | ||
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | + | ||
| 153 | // To run this test, uncomment and fill in your S3 access details | 154 | // To run this test, uncomment and fill in your S3 access details |
| 154 | - (void)testREST | 155 | - (void)testREST |
| 155 | { | 156 | { |
| @@ -204,9 +205,8 @@ static NSString *bucket = @""; | @@ -204,9 +205,8 @@ static NSString *bucket = @""; | ||
| 204 | success = [[request responseString] isEqualToString:@""]; | 205 | success = [[request responseString] isEqualToString:@""]; |
| 205 | GHAssertTrue(success,@"Got a response body for a HEAD request"); | 206 | GHAssertTrue(success,@"Got a response body for a HEAD request"); |
| 206 | 207 | ||
| 207 | - // Get a list of files | 208 | + // Test listing the objects in this bucket |
| 208 | ASIS3BucketRequest *listRequest = [ASIS3BucketRequest requestWithBucket:bucket]; | 209 | ASIS3BucketRequest *listRequest = [ASIS3BucketRequest requestWithBucket:bucket]; |
| 209 | - [listRequest setPrefix:@"test"]; | ||
| 210 | [listRequest setSecretAccessKey:secretAccessKey]; | 210 | [listRequest setSecretAccessKey:secretAccessKey]; |
| 211 | [listRequest setAccessKey:accessKey]; | 211 | [listRequest setAccessKey:accessKey]; |
| 212 | [listRequest startSynchronous]; | 212 | [listRequest startSynchronous]; |
| @@ -214,6 +214,16 @@ static NSString *bucket = @""; | @@ -214,6 +214,16 @@ static NSString *bucket = @""; | ||
| 214 | success = [[listRequest bucketObjects] count]; | 214 | success = [[listRequest bucketObjects] count]; |
| 215 | GHAssertTrue(success,@"The file didn't show up in the list"); | 215 | GHAssertTrue(success,@"The file didn't show up in the list"); |
| 216 | 216 | ||
| 217 | + // Test again with a prefix query | ||
| 218 | + listRequest = [ASIS3BucketRequest requestWithBucket:bucket]; | ||
| 219 | + [listRequest setPrefix:@"test"]; | ||
| 220 | + [listRequest setSecretAccessKey:secretAccessKey]; | ||
| 221 | + [listRequest setAccessKey:accessKey]; | ||
| 222 | + [listRequest startSynchronous]; | ||
| 223 | + GHAssertNil([listRequest error],@"Failed to download a list from S3"); | ||
| 224 | + success = [[listRequest bucketObjects] count]; | ||
| 225 | + GHAssertTrue(success,@"The file didn't show up in the list"); | ||
| 226 | + | ||
| 217 | // DELETE the file | 227 | // DELETE the file |
| 218 | request = [ASIS3ObjectRequest requestWithBucket:bucket key:key]; | 228 | request = [ASIS3ObjectRequest requestWithBucket:bucket key:key]; |
| 219 | [request setSecretAccessKey:secretAccessKey]; | 229 | [request setSecretAccessKey:secretAccessKey]; |
-
Please register or login to post a comment