Browse files

add setSharedServicePath: and setRequestServicePath: to point to Amaz…

…on S3-compatible services.
  • Loading branch information...
1 parent 0220174 commit 7a65c246ce0d2fe1a8d0a4cb7049043d71962320 Tim Burks committed Sep 23, 2010
View
4 Classes/S3/ASIS3BucketRequest.m
@@ -30,14 +30,14 @@ - (id)initWithURL:(NSURL *)newURL
+ (id)requestWithBucket:(NSString *)bucket
{
- ASIS3BucketRequest *request = [[[self alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.s3.amazonaws.com",bucket]]] autorelease];
+ ASIS3BucketRequest *request = [[[self alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.%@",bucket,[self servicePath]]]] autorelease];
[request setBucket:bucket];
return request;
}
+ (id)requestWithBucket:(NSString *)bucket subResource:(NSString *)subResource
{
- ASIS3BucketRequest *request = [[[self alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.s3.amazonaws.com/?%@",bucket,subResource]]] autorelease];
+ ASIS3BucketRequest *request = [[[self alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.%@/?%@",bucket,[self servicePath],subResource]]] autorelease];
[request setBucket:bucket];
[request setSubResource:subResource];
return request;
View
4 Classes/S3/ASIS3ObjectRequest.m
@@ -22,7 +22,7 @@ - (ASIHTTPRequest *)HEADRequest
+ (id)requestWithBucket:(NSString *)bucket key:(NSString *)key
{
NSString *path = [ASIS3Request stringByURLEncodingForS3Path:key];
- ASIS3ObjectRequest *request = [[[self alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.s3.amazonaws.com%@",bucket,path]]] autorelease];
+ ASIS3ObjectRequest *request = [[[self alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.%@%@",bucket,[self servicePath],path]]] autorelease];
[request setBucket:bucket];
[request setKey:key];
return request;
@@ -31,7 +31,7 @@ + (id)requestWithBucket:(NSString *)bucket key:(NSString *)key
+ (id)requestWithBucket:(NSString *)bucket key:(NSString *)key subResource:(NSString *)subResource
{
NSString *path = [ASIS3Request stringByURLEncodingForS3Path:key];
- ASIS3ObjectRequest *request = [[[self alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.s3.amazonaws.com%@?%@",bucket,path,subResource]]] autorelease];
+ ASIS3ObjectRequest *request = [[[self alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.%@%@?%@",bucket,[self servicePath],path,subResource]]] autorelease];
[request setSubResource:subResource];
[request setBucket:bucket];
[request setKey:key];
View
13 Classes/S3/ASIS3Request.h
@@ -36,6 +36,9 @@ typedef enum _ASIS3ErrorType {
// Your S3 secret access key. Set it on the request, or set it globally using [ASIS3Request setSharedSecretAccessKey:]
NSString *secretAccessKey;
+ // The path to the service you wish to use. Defaults to Amazon's S3 service.
+ NSString *requestServicePath;
+
// The string that will be used in the HTTP date header. Generally you'll want to ignore this and let the class add the current date for you, but the accessor is used by the tests
NSString *dateString;
@@ -68,7 +71,16 @@ typedef enum _ASIS3ErrorType {
+ (void)setSharedAccessKey:(NSString *)newAccessKey;
+ (NSString *)sharedSecretAccessKey;
+ (void)setSharedSecretAccessKey:(NSString *)newAccessKey;
+
+#pragma mark service path
+
+// Get and set the global service path, this defaults to Amazon S3 but can be pointed to compatible services.
++ (NSString *)sharedServicePath;
++ (void)setSharedServicePath:(NSString *)newServicePath;
+// Returns the service path to be used for this request.
+- (NSString *)servicePath;
+
# pragma mark helpers
// Returns a date formatter than can be used to parse a date from S3
@@ -87,6 +99,7 @@ typedef enum _ASIS3ErrorType {
@property (retain) NSString *dateString;
@property (retain) NSString *accessKey;
@property (retain) NSString *secretAccessKey;
+@property (retain) NSString *requestServicePath;
@property (retain) NSString *accessPolicy;
@property (retain) NSString *currentXMLElementContent;
@property (retain) NSMutableArray *currentXMLElementStack;
View
28 Classes/S3/ASIS3Request.m
@@ -16,6 +16,7 @@
static NSString *sharedAccessKey = nil;
static NSString *sharedSecretAccessKey = nil;
+static NSString *sharedServicePath = nil;
// Private stuff
@interface ASIS3Request ()
@@ -40,6 +41,7 @@ - (void)dealloc
[dateString release];
[accessKey release];
[secretAccessKey release];
+ [requestServicePath release];
[accessPolicy release];
[super dealloc];
}
@@ -179,6 +181,7 @@ - (id)copyWithZone:(NSZone *)zone
ASIS3Request *newRequest = [super copyWithZone:zone];
[newRequest setAccessKey:[self accessKey]];
[newRequest setSecretAccessKey:[self secretAccessKey]];
+ [newRequest setRequestServicePath:[self requestServicePath]];
[newRequest setAccessPolicy:[self accessPolicy]];
return newRequest;
}
@@ -208,6 +211,30 @@ + (void)setSharedSecretAccessKey:(NSString *)newAccessKey
sharedSecretAccessKey = [newAccessKey retain];
}
+#pragma mark Service path
+
+- (NSString *)servicePath
+{
+ if (requestServicePath) {
+ return requestServicePath;
+ } else if (sharedServicePath) {
+ return sharedServicePath;
+ } else {
+ return @"s3.amazonaws.com";
+ }
+}
+
++ (NSString *)sharedServicePath
+{
+ return sharedServicePath;
+}
+
++ (void)setSharedServicePath:(NSString *)newServicePatn
+{
+ [sharedServicePath release];
+ sharedServicePath = [newServicePatn retain];
+}
+
#pragma mark helpers
@@ -278,6 +305,7 @@ + (NSData *)HMACSHA1withKey:(NSString *)key forString:(NSString *)string
@synthesize dateString;
@synthesize accessKey;
@synthesize secretAccessKey;
+@synthesize requestServicePath;
@synthesize currentXMLElementContent;
@synthesize currentXMLElementStack;
@synthesize accessPolicy;
View
2 Classes/S3/ASIS3ServiceRequest.m
@@ -21,7 +21,7 @@ @implementation ASIS3ServiceRequest
+ (id)serviceRequest
{
- return [[[self alloc] initWithURL:[NSURL URLWithString:@"http://s3.amazonaws.com"]] autorelease];
+ return [[[self alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [self servicePath]]]] autorelease];
}

0 comments on commit 7a65c24

Please sign in to comment.