Ben Copsey

Merge branch 'cloudfiles' into integration

Conflicts:
	Classes/ASIHTTPRequest.m
	iPhone.xcodeproj/project.pbxproj
	set_version_number.sh
  1 +//
  2 +// ASICloudFilesCDNRequest.h
  3 +//
  4 +// Created by Michael Mayo on 1/6/10.
  5 +//
  6 +
  7 +#import "ASICloudFilesRequest.h"
  8 +
  9 +@class ASICloudFilesContainerXMLParserDelegate;
  10 +
  11 +@interface ASICloudFilesCDNRequest : ASICloudFilesRequest {
  12 + NSString *accountName;
  13 + NSString *containerName;
  14 + ASICloudFilesContainerXMLParserDelegate *xmlParserDelegate;
  15 +
  16 +}
  17 +
  18 +@property (nonatomic, retain) NSString *accountName;
  19 +@property (nonatomic, retain) NSString *containerName;
  20 +@property (nonatomic, retain) ASICloudFilesContainerXMLParserDelegate *xmlParserDelegate;
  21 +
  22 +
  23 +// HEAD /<api version>/<account>/<container>
  24 +// Response:
  25 +// X-CDN-Enabled: True
  26 +// X-CDN-URI: http://cdn.cloudfiles.mosso.com/c1234
  27 +// X-CDN-TTL: 86400
  28 ++ (id)containerInfoRequest:(NSString *)containerName;
  29 +- (BOOL)cdnEnabled;
  30 +- (NSString *)cdnURI;
  31 +- (NSUInteger)cdnTTL;
  32 +
  33 +
  34 +// GET /<api version>/<account>
  35 +// limit, marker, format, enabled_only=true
  36 ++ (id)listRequest;
  37 ++ (id)listRequestWithLimit:(NSUInteger)limit marker:(NSString *)marker enabledOnly:(BOOL)enabledOnly;
  38 +- (NSArray *)containers;
  39 +
  40 +
  41 +// PUT /<api version>/<account>/<container>
  42 +// PUT operations against a Container are used to CDN-enable that Container.
  43 +// Include an HTTP header of X-TTL to specify a custom TTL.
  44 ++ (id)putRequestWithContainer:(NSString *)containerName;
  45 ++ (id)putRequestWithContainer:(NSString *)containerName ttl:(NSUInteger)ttl;
  46 +// returns: - (NSString *)cdnURI;
  47 +
  48 +// POST /<api version>/<account>/<container>
  49 +// POST operations against a CDN-enabled Container are used to adjust CDN attributes.
  50 +// The POST operation can be used to set a new TTL cache expiration or to enable/disable public sharing over the CDN.
  51 +// X-TTL: 86400
  52 +// X-CDN-Enabled: True
  53 ++ (id)postRequestWithContainer:(NSString *)containerName;
  54 ++ (id)postRequestWithContainer:(NSString *)containerName cdnEnabled:(BOOL)cdnEnabled ttl:(NSUInteger)ttl;
  55 +// returns: - (NSString *)cdnURI;
  56 +
  57 +
  58 +@end
  1 +//
  2 +// ASICloudFilesCDNRequest.m
  3 +//
  4 +// Created by Michael Mayo on 1/6/10.
  5 +//
  6 +
  7 +#import "ASICloudFilesCDNRequest.h"
  8 +#import "ASICloudFilesContainerXMLParserDelegate.h"
  9 +
  10 +
  11 +@implementation ASICloudFilesCDNRequest
  12 +
  13 +@synthesize accountName, containerName, xmlParserDelegate;
  14 +
  15 ++ (id)cdnRequestWithMethod:(NSString *)method query:(NSString *)query {
  16 + NSString *urlString = [NSString stringWithFormat:@"%@%@", [ASICloudFilesRequest cdnManagementURL], query];
  17 + ASICloudFilesCDNRequest *request = [[ASICloudFilesCDNRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
  18 + [request setRequestMethod:method];
  19 + [request addRequestHeader:@"X-Auth-Token" value:[ASICloudFilesRequest authToken]];
  20 + return request;
  21 +}
  22 +
  23 ++ (id)cdnRequestWithMethod:(NSString *)method containerName:(NSString *)containerName {
  24 + NSString *urlString = [NSString stringWithFormat:@"%@/%@", [ASICloudFilesRequest cdnManagementURL], containerName];
  25 + ASICloudFilesCDNRequest *request = [[ASICloudFilesCDNRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
  26 + [request setRequestMethod:method];
  27 + [request addRequestHeader:@"X-Auth-Token" value:[ASICloudFilesRequest authToken]];
  28 + request.containerName = containerName;
  29 + return request;
  30 +}
  31 +
  32 +#pragma mark -
  33 +#pragma mark HEAD - Container Info
  34 +
  35 ++ (id)containerInfoRequest:(NSString *)containerName {
  36 + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"HEAD" containerName:containerName];
  37 + return request;
  38 +}
  39 +
  40 +- (BOOL)cdnEnabled {
  41 + return [[[self responseHeaders] objectForKey:@"X-Cdn-Enabled"] boolValue];
  42 +}
  43 +
  44 +- (NSString *)cdnURI {
  45 + return [[self responseHeaders] objectForKey:@"X-Cdn-Uri"];
  46 +}
  47 +
  48 +- (NSUInteger)cdnTTL {
  49 + return [[[self responseHeaders] objectForKey:@"X-Ttl"] intValue];
  50 +}
  51 +
  52 +#pragma mark -
  53 +#pragma mark GET - CDN Container Lists
  54 +
  55 ++ (id)listRequest {
  56 + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"GET" query:@"?format=xml"];
  57 + return request;
  58 +}
  59 +
  60 ++ (id)listRequestWithLimit:(NSUInteger)limit marker:(NSString *)marker enabledOnly:(BOOL)enabledOnly {
  61 + NSString *query = @"?format=xml";
  62 +
  63 + if (limit > 0) {
  64 + query = [query stringByAppendingString:[NSString stringWithFormat:@"&limit=%i", limit]];
  65 + }
  66 +
  67 + if (marker) {
  68 + query = [query stringByAppendingString:[NSString stringWithFormat:@"&marker=%@", marker]];
  69 + }
  70 +
  71 + if (limit > 0) {
  72 + query = [query stringByAppendingString:[NSString stringWithFormat:@"&limit=%i", limit]];
  73 + }
  74 +
  75 + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"GET" query:query];
  76 + return request;
  77 +}
  78 +
  79 +- (NSArray *)containers {
  80 + if (xmlParserDelegate.containerObjects) {
  81 + return xmlParserDelegate.containerObjects;
  82 + }
  83 +
  84 + NSXMLParser *parser = [[[NSXMLParser alloc] initWithData:[self responseData]] autorelease];
  85 + if (xmlParserDelegate == nil) {
  86 + xmlParserDelegate = [[ASICloudFilesContainerXMLParserDelegate alloc] init];
  87 + }
  88 +
  89 + [parser setDelegate:xmlParserDelegate];
  90 + [parser setShouldProcessNamespaces:NO];
  91 + [parser setShouldReportNamespacePrefixes:NO];
  92 + [parser setShouldResolveExternalEntities:NO];
  93 + [parser parse];
  94 +
  95 + return xmlParserDelegate.containerObjects;
  96 +}
  97 +
  98 +#pragma mark -
  99 +#pragma mark PUT - CDN Enable Container
  100 +
  101 +// PUT /<api version>/<account>/<container>
  102 +// PUT operations against a Container are used to CDN-enable that Container.
  103 +// Include an HTTP header of X-TTL to specify a custom TTL.
  104 ++ (id)putRequestWithContainer:(NSString *)containerName {
  105 + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"PUT" containerName:containerName];
  106 + return request;
  107 +}
  108 +
  109 ++ (id)putRequestWithContainer:(NSString *)containerName ttl:(NSUInteger)ttl {
  110 + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"PUT" containerName:containerName];
  111 + [request addRequestHeader:@"X-Ttl" value:[NSString stringWithFormat:@"%i", ttl]];
  112 + return request;
  113 +}
  114 +
  115 +#pragma mark -
  116 +#pragma mark POST - Adjust CDN Attributes
  117 +
  118 +// POST /<api version>/<account>/<container>
  119 +// POST operations against a CDN-enabled Container are used to adjust CDN attributes.
  120 +// The POST operation can be used to set a new TTL cache expiration or to enable/disable public sharing over the CDN.
  121 +// X-TTL: 86400
  122 +// X-CDN-Enabled: True
  123 ++ (id)postRequestWithContainer:(NSString *)containerName {
  124 + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"POST" containerName:containerName];
  125 + return request;
  126 +}
  127 +
  128 ++ (id)postRequestWithContainer:(NSString *)containerName cdnEnabled:(BOOL)cdnEnabled ttl:(NSUInteger)ttl {
  129 + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"POST" containerName:containerName];
  130 + if (ttl > 0) {
  131 + [request addRequestHeader:@"X-Ttl" value:[NSString stringWithFormat:@"%i", ttl]];
  132 + }
  133 + [request addRequestHeader:@"X-Cdn-Enabled" value:cdnEnabled ? @"True" : @"False"];
  134 + return request;
  135 +}
  136 +
  137 +#pragma mark -
  138 +#pragma mark Memory Management
  139 +
  140 +-(void)dealloc {
  141 + [accountName release];
  142 + [containerName release];
  143 + [xmlParserDelegate release];
  144 + [super dealloc];
  145 +}
  146 +
  147 +@end
  1 +//
  2 +// ASICloudFilesContainer.h
  3 +//
  4 +// Created by Michael Mayo on 1/7/10.
  5 +//
  6 +
  7 +#import <Foundation/Foundation.h>
  8 +
  9 +
  10 +@interface ASICloudFilesContainer : NSObject {
  11 +
  12 + // regular container attributes
  13 + NSString *name;
  14 + NSUInteger count;
  15 + NSUInteger bytes;
  16 +
  17 + // CDN container attributes
  18 + BOOL cdnEnabled;
  19 + NSUInteger ttl;
  20 + NSString *cdnURL;
  21 + BOOL logRetention;
  22 + NSString *referrerACL;
  23 + NSString *useragentACL;
  24 +}
  25 +
  26 ++ (id)container;
  27 +
  28 +// regular container attributes
  29 +@property (nonatomic, retain) NSString *name;
  30 +@property (nonatomic) NSUInteger count;
  31 +@property (nonatomic) NSUInteger bytes;
  32 +
  33 +// CDN container attributes
  34 +@property (nonatomic) BOOL cdnEnabled;
  35 +@property (nonatomic) NSUInteger ttl;
  36 +@property (nonatomic, retain) NSString *cdnURL;
  37 +@property (nonatomic) BOOL logRetention;
  38 +@property (nonatomic, retain) NSString *referrerACL;
  39 +@property (nonatomic, retain) NSString *useragentACL;
  40 +
  41 +@end
  1 +//
  2 +// ASICloudFilesContainer.m
  3 +//
  4 +// Created by Michael Mayo on 1/7/10.
  5 +//
  6 +
  7 +#import "ASICloudFilesContainer.h"
  8 +
  9 +
  10 +@implementation ASICloudFilesContainer
  11 +
  12 +// regular container attributes
  13 +@synthesize name, count, bytes;
  14 +
  15 +// CDN container attributes
  16 +@synthesize cdnEnabled, ttl, cdnURL, logRetention, referrerACL, useragentACL;
  17 +
  18 ++ (id)container {
  19 + ASICloudFilesContainer *container = [[[self alloc] init] autorelease];
  20 + return container;
  21 +}
  22 +
  23 +-(void) dealloc {
  24 + [name release];
  25 + [super dealloc];
  26 +}
  27 +
  28 +@end
  1 +//
  2 +// ASICloudFilesContainerRequest.h
  3 +//
  4 +// Created by Michael Mayo on 1/6/10.
  5 +//
  6 +
  7 +#import "ASICloudFilesRequest.h"
  8 +
  9 +@class ASICloudFilesContainer, ASICloudFilesContainerXMLParserDelegate;
  10 +
  11 +@interface ASICloudFilesContainerRequest : ASICloudFilesRequest {
  12 +
  13 + // Internally used while parsing the response
  14 + NSString *currentContent;
  15 + NSString *currentElement;
  16 + ASICloudFilesContainer *currentObject;
  17 + ASICloudFilesContainerXMLParserDelegate *xmlParserDelegate;
  18 +}
  19 +
  20 +@property (nonatomic, retain) NSString *currentElement;
  21 +@property (nonatomic, retain) NSString *currentContent;
  22 +@property (nonatomic, retain) ASICloudFilesContainer *currentObject;
  23 +@property (nonatomic, retain) ASICloudFilesContainerXMLParserDelegate *xmlParserDelegate;
  24 +
  25 +// HEAD /<api version>/<account>
  26 +// HEAD operations against an account are performed to retrieve the number of Containers and the total bytes stored in Cloud Files for the account. This information is returned in two custom headers, X-Account-Container-Count and X-Account-Bytes-Used.
  27 ++ (id)accountInfoRequest;
  28 +- (NSUInteger)containerCount;
  29 +- (NSUInteger)bytesUsed;
  30 +
  31 +// GET /<api version>/<account>/<container>
  32 +// Create a request to list all containers
  33 ++ (id)listRequest;
  34 ++ (id)listRequestWithLimit:(NSUInteger)limit marker:(NSString *)marker;
  35 +- (NSArray *)containers;
  36 +
  37 +// PUT /<api version>/<account>/<container>
  38 ++ (id)createContainerRequest:(NSString *)containerName;
  39 +
  40 +// DELETE /<api version>/<account>/<container>
  41 ++ (id)deleteContainerRequest:(NSString *)containerName;
  42 +
  43 +@end
  1 +//
  2 +// ASICloudFilesContainerRequest.m
  3 +//
  4 +// Created by Michael Mayo on 1/6/10.
  5 +//
  6 +
  7 +#import "ASICloudFilesContainerRequest.h"
  8 +#import "ASICloudFilesContainer.h"
  9 +#import "ASICloudFilesContainerXMLParserDelegate.h"
  10 +
  11 +
  12 +@implementation ASICloudFilesContainerRequest
  13 +
  14 +@synthesize currentElement, currentContent, currentObject;
  15 +@synthesize xmlParserDelegate;
  16 +
  17 +#pragma mark -
  18 +#pragma mark Constructors
  19 +
  20 ++ (id)storageRequestWithMethod:(NSString *)method containerName:(NSString *)containerName queryString:(NSString *)queryString {
  21 + NSString *urlString;
  22 + if (containerName == nil) {
  23 + urlString = [NSString stringWithFormat:@"%@%@", [ASICloudFilesRequest storageURL], queryString];
  24 + } else {
  25 + urlString = [NSString stringWithFormat:@"%@/%@%@", [ASICloudFilesRequest storageURL], containerName, queryString];
  26 + }
  27 +
  28 + ASICloudFilesContainerRequest *request = [[ASICloudFilesContainerRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
  29 + [request setRequestMethod:method];
  30 + [request addRequestHeader:@"X-Auth-Token" value:[ASICloudFilesRequest authToken]];
  31 + return request;
  32 +}
  33 +
  34 ++ (id)storageRequestWithMethod:(NSString *)method queryString:(NSString *)queryString {
  35 + return [ASICloudFilesContainerRequest storageRequestWithMethod:method containerName:nil queryString:queryString];
  36 +}
  37 +
  38 ++ (id)storageRequestWithMethod:(NSString *)method {
  39 + return [ASICloudFilesContainerRequest storageRequestWithMethod:method queryString:@""];
  40 +}
  41 +
  42 +#pragma mark -
  43 +#pragma mark HEAD - Retrieve Container Count and Total Bytes Used
  44 +
  45 +// HEAD /<api version>/<account>
  46 +// HEAD operations against an account are performed to retrieve the number of Containers and the total bytes stored in Cloud Files for the account. This information is returned in two custom headers, X-Account-Container-Count and X-Account-Bytes-Used.
  47 ++ (id)accountInfoRequest {
  48 + ASICloudFilesContainerRequest *request = [ASICloudFilesContainerRequest storageRequestWithMethod:@"HEAD"];
  49 + return request;
  50 +}
  51 +
  52 +- (NSUInteger)containerCount {
  53 + return [[[self responseHeaders] objectForKey:@"X-Account-Container-Count"] intValue];
  54 +}
  55 +
  56 +- (NSUInteger)bytesUsed {
  57 + return [[[self responseHeaders] objectForKey:@"X-Account-Bytes-Used"] intValue];
  58 +}
  59 +
  60 +#pragma mark -
  61 +#pragma mark GET - Retrieve Container List
  62 +
  63 ++ (id)listRequestWithLimit:(NSUInteger)limit marker:(NSString *)marker {
  64 + NSString *queryString = @"?format=xml";
  65 +
  66 + if (limit > 0) {
  67 + queryString = [queryString stringByAppendingString:[NSString stringWithFormat:@"&limit=%i", limit]];
  68 + }
  69 +
  70 + if (marker != nil) {
  71 + queryString = [queryString stringByAppendingString:[NSString stringWithFormat:@"&marker=%@", marker]];
  72 + }
  73 +
  74 + ASICloudFilesContainerRequest *request = [ASICloudFilesContainerRequest storageRequestWithMethod:@"GET" queryString:queryString];
  75 + return request;
  76 +}
  77 +
  78 +// GET /<api version>/<account>/<container>
  79 +// Create a request to list all containers
  80 ++ (id)listRequest {
  81 + ASICloudFilesContainerRequest *request = [ASICloudFilesContainerRequest storageRequestWithMethod:@"GET"
  82 + queryString:@"?format=xml"];
  83 + return request;
  84 +}
  85 +
  86 +- (NSArray *)containers {
  87 + if (xmlParserDelegate.containerObjects) {
  88 + return xmlParserDelegate.containerObjects;
  89 + }
  90 +
  91 + NSXMLParser *parser = [[[NSXMLParser alloc] initWithData:[self responseData]] autorelease];
  92 + if (xmlParserDelegate == nil) {
  93 + xmlParserDelegate = [[ASICloudFilesContainerXMLParserDelegate alloc] init];
  94 + }
  95 +
  96 + [parser setDelegate:xmlParserDelegate];
  97 + [parser setShouldProcessNamespaces:NO];
  98 + [parser setShouldReportNamespacePrefixes:NO];
  99 + [parser setShouldResolveExternalEntities:NO];
  100 + [parser parse];
  101 +
  102 + return xmlParserDelegate.containerObjects;
  103 +}
  104 +
  105 +#pragma mark -
  106 +#pragma mark PUT - Create Container
  107 +
  108 +// PUT /<api version>/<account>/<container>
  109 ++ (id)createContainerRequest:(NSString *)containerName {
  110 + ASICloudFilesContainerRequest *request = [ASICloudFilesContainerRequest storageRequestWithMethod:@"PUT" containerName:containerName queryString:@""];
  111 + return request;
  112 +}
  113 +
  114 +#pragma mark -
  115 +#pragma mark DELETE - Delete Container
  116 +
  117 +// DELETE /<api version>/<account>/<container>
  118 ++ (id)deleteContainerRequest:(NSString *)containerName {
  119 + ASICloudFilesContainerRequest *request = [ASICloudFilesContainerRequest storageRequestWithMethod:@"DELETE" containerName:containerName queryString:@""];
  120 + return request;
  121 +}
  122 +
  123 +#pragma mark -
  124 +#pragma mark Memory Management
  125 +
  126 +- (void)dealloc {
  127 + [currentElement release];
  128 + [currentContent release];
  129 + [currentObject release];
  130 + [xmlParserDelegate release];
  131 + [super dealloc];
  132 +}
  133 +
  134 +@end
  1 +//
  2 +// ASICloudFilesContainerXMLParserDelegate.h
  3 +//
  4 +// Created by Michael Mayo on 1/10/10.
  5 +//
  6 +
  7 +#import "ASICloudFilesRequest.h"
  8 +
  9 +@class ASICloudFilesContainer;
  10 +
  11 +@interface ASICloudFilesContainerXMLParserDelegate : NSObject {
  12 +
  13 + NSMutableArray *containerObjects;
  14 +
  15 + // Internally used while parsing the response
  16 + NSString *currentContent;
  17 + NSString *currentElement;
  18 + ASICloudFilesContainer *currentObject;
  19 +}
  20 +
  21 +@property (nonatomic, retain) NSMutableArray *containerObjects;
  22 +
  23 +@property (nonatomic, retain) NSString *currentElement;
  24 +@property (nonatomic, retain) NSString *currentContent;
  25 +@property (nonatomic, retain) ASICloudFilesContainer *currentObject;
  26 +
  27 +@end
  1 +//
  2 +// ASICloudFilesContainerXMLParserDelegate.m
  3 +//
  4 +// Created by Michael Mayo on 1/10/10.
  5 +//
  6 +
  7 +#import "ASICloudFilesContainerXMLParserDelegate.h"
  8 +#import "ASICloudFilesContainer.h"
  9 +
  10 +
  11 +@implementation ASICloudFilesContainerXMLParserDelegate
  12 +
  13 +@synthesize containerObjects, currentElement, currentContent, currentObject;
  14 +
  15 +#pragma mark -
  16 +#pragma mark XML Parser Delegate
  17 +
  18 +- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
  19 + [self setCurrentElement:elementName];
  20 +
  21 + if ([elementName isEqualToString:@"container"]) {
  22 + [self setCurrentObject:[ASICloudFilesContainer container]];
  23 + }
  24 + [self setCurrentContent:@""];
  25 +}
  26 +
  27 +- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
  28 +
  29 + if ([elementName isEqualToString:@"name"]) {
  30 + [self currentObject].name = [self currentContent];
  31 + } else if ([elementName isEqualToString:@"count"]) {
  32 + [self currentObject].count = [[self currentContent] intValue];
  33 + } else if ([elementName isEqualToString:@"bytes"]) {
  34 + [self currentObject].bytes = [[self currentContent] intValue];
  35 + } else if ([elementName isEqualToString:@"cdn_enabled"]) {
  36 + [self currentObject].cdnEnabled = [[self currentObject] isEqual:@"True"];
  37 + } else if ([elementName isEqualToString:@"ttl"]) {
  38 + [self currentObject].ttl = [[self currentContent] intValue];
  39 + } else if ([elementName isEqualToString:@"cdn_url"]) {
  40 + [self currentObject].cdnURL = [self currentContent];
  41 + } else if ([elementName isEqualToString:@"log_retention"]) {
  42 + [self currentObject].logRetention = [[self currentObject] isEqual:@"True"];
  43 + } else if ([elementName isEqualToString:@"referrer_acl"]) {
  44 + [self currentObject].referrerACL = [self currentContent];
  45 + } else if ([elementName isEqualToString:@"useragent_acl"]) {
  46 + [self currentObject].useragentACL = [self currentContent];
  47 + } else if ([elementName isEqualToString:@"container"]) {
  48 + // we're done with this container. time to move on to the next
  49 + if (containerObjects == nil) {
  50 + containerObjects = [[NSMutableArray alloc] init];
  51 + }
  52 + [containerObjects addObject:currentObject];
  53 + [self setCurrentObject:nil];
  54 + }
  55 +}
  56 +
  57 +- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
  58 + [self setCurrentContent:[[self currentContent] stringByAppendingString:string]];
  59 +}
  60 +
  61 +#pragma mark -
  62 +#pragma mark Memory Management
  63 +
  64 +- (void)dealloc {
  65 + [containerObjects release];
  66 + [currentElement release];
  67 + [currentContent release];
  68 + [currentObject release];
  69 + [super dealloc];
  70 +}
  71 +
  72 +@end
  1 +//
  2 +// ASICloudFilesObject.h
  3 +//
  4 +// Created by Michael Mayo on 1/7/10.
  5 +//
  6 +
  7 +#import <Foundation/Foundation.h>
  8 +
  9 +
  10 +@interface ASICloudFilesObject : NSObject {
  11 + NSString *name;
  12 + NSString *hash;
  13 + NSUInteger bytes;
  14 + NSString *contentType;
  15 + NSDate *lastModified;
  16 + NSData *data;
  17 + NSMutableDictionary *metadata;
  18 +}
  19 +
  20 +@property (nonatomic, retain) NSString *name;
  21 +@property (nonatomic, retain) NSString *hash;
  22 +@property (nonatomic) NSUInteger bytes;
  23 +@property (nonatomic, retain) NSString *contentType;
  24 +@property (nonatomic, retain) NSDate *lastModified;
  25 +@property (nonatomic, retain) NSData *data;
  26 +@property (nonatomic, retain) NSMutableDictionary *metadata;
  27 +
  28 ++ (id)object;
  29 +
  30 +@end
  1 +//
  2 +// ASICloudFilesObject.m
  3 +//
  4 +// Created by Michael Mayo on 1/7/10.
  5 +//
  6 +
  7 +#import "ASICloudFilesObject.h"
  8 +
  9 +
  10 +@implementation ASICloudFilesObject
  11 +
  12 +@synthesize name, hash, bytes, contentType, lastModified, data, metadata;
  13 +
  14 ++ (id)object {
  15 + ASICloudFilesObject *object = [[[self alloc] init] autorelease];
  16 + return object;
  17 +}
  18 +
  19 +-(void)dealloc {
  20 + [name release];
  21 + [hash release];
  22 + [contentType release];
  23 + [lastModified release];
  24 + [data release];
  25 + [metadata release];
  26 + [super dealloc];
  27 +}
  28 +
  29 +@end
  1 +//
  2 +// ASICloudFilesObjectRequest.h
  3 +//
  4 +// Created by Michael Mayo on 1/6/10.
  5 +//
  6 +
  7 +#import "ASICloudFilesRequest.h"
  8 +
  9 +@class ASICloudFilesObject;
  10 +
  11 +@interface ASICloudFilesObjectRequest : ASICloudFilesRequest {
  12 +
  13 + NSString *accountName;
  14 + NSString *containerName;
  15 +
  16 + // Internally used while parsing the response
  17 + NSString *currentContent;
  18 + NSString *currentElement;
  19 + ASICloudFilesObject *currentObject;
  20 + NSMutableArray *objects;
  21 +
  22 +}
  23 +
  24 +@property (nonatomic, retain) NSString *accountName;
  25 +@property (nonatomic, retain) NSString *containerName;
  26 +@property (nonatomic, retain) NSString *currentElement;
  27 +@property (nonatomic, retain) NSString *currentContent;
  28 +@property (nonatomic, retain) ASICloudFilesObject *currentObject;
  29 +
  30 +
  31 +// HEAD /<api version>/<account>/<container>
  32 +// HEAD operations against an account are performed to retrieve the number of Containers and the total bytes stored in Cloud Files for the account. This information is returned in two custom headers, X-Account-Container-Count and X-Account-Bytes-Used.
  33 ++ (id)containerInfoRequest:(NSString *)containerName;
  34 +- (NSUInteger)containerObjectCount;
  35 +- (NSUInteger)containerBytesUsed;
  36 +
  37 +// HEAD /<api version>/<account>/<container>/<object>
  38 +// to get metadata
  39 ++ (id)objectInfoRequest:(NSString *)containerName objectPath:(NSString *)objectPath;
  40 +- (NSArray *)objects;
  41 +
  42 ++ (id)listRequestWithContainer:(NSString *)containerName;
  43 ++ (id)listRequestWithContainer:(NSString *)containerName limit:(NSUInteger)limit marker:(NSString *)marker prefix:(NSString *)prefix path:(NSString *)path;
  44 +
  45 +// Conditional GET headers: If-Match • If-None-Match • If-Modified-Since • If-Unmodified-Since
  46 +// HTTP Range header: “Range: bytes=0-5” • “Range: bytes=-5” • “Range: bytes=32-“
  47 ++ (id)getObjectRequestWithContainer:(NSString *)containerName objectPath:(NSString *)objectPath;
  48 +- (ASICloudFilesObject *)object;
  49 +
  50 +// PUT /<api version>/<account>/<container>/<object>
  51 +// PUT operations are used to write, or overwrite, an Object's metadata and content.
  52 +// The Object can be created with custom metadata via HTTP headers identified with the “X-Object-Meta-” prefix.
  53 ++ (id)putObjectRequestWithContainer:(NSString *)containerName object:(ASICloudFilesObject *)object;
  54 ++ (id)putObjectRequestWithContainer:(NSString *)containerName objectPath:(NSString *)objectPath contentType:(NSString *)contentType objectData:(NSData *)objectData metadata:(NSDictionary *)metadata etag:(NSString *)etag;
  55 +
  56 +// POST /<api version>/<account>/<container>/<object>
  57 +// POST operations against an Object name are used to set and overwrite arbitrary key/value metadata. You cannot use the POST operation to change any of the Object's other headers such as Content-Type, ETag, etc. It is not used to upload storage Objects (see PUT).
  58 +// A POST request will delete all existing metadata added with a previous PUT/POST.
  59 ++ (id)postObjectRequestWithContainer:(NSString *)containerName object:(ASICloudFilesObject *)object;
  60 ++ (id)postObjectRequestWithContainer:(NSString *)containerName objectPath:(NSString *)objectPath metadata:(NSDictionary *)metadata;
  61 +
  62 +// DELETE /<api version>/<account>/<container>/<object>
  63 ++ (id)deleteObjectRequestWithContainer:(NSString *)containerName objectPath:(NSString *)objectPath;
  64 +
  65 +@end
This diff is collapsed. Click to expand it.
  1 +//
  2 +// ASICloudFilesRequest.h
  3 +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
  4 +//
  5 +// Created by Michael Mayo on 22/12/09.
  6 +// mike.mayo@rackspace.com or mike@overhrd.com
  7 +// twitter.com/greenisus
  8 +// Copyright 2009 All-Seeing Interactive. All rights reserved.
  9 +//
  10 +// A class for accessing data stored on the Rackspace Cloud Files Service
  11 +// http://www.rackspacecloud.com/cloud_hosting_products/files
  12 +//
  13 +// Cloud Files Developer Guide:
  14 +// http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf
  15 +
  16 +#import <Foundation/Foundation.h>
  17 +#import "ASIHTTPRequest.h"
  18 +
  19 +
  20 +@interface ASICloudFilesRequest : ASIHTTPRequest {
  21 +}
  22 +
  23 ++ (NSString *)storageURL;
  24 ++ (NSString *)cdnManagementURL;
  25 ++ (NSString *)authToken;
  26 +
  27 +#pragma mark Rackspace Cloud Authentication
  28 +
  29 ++ (id)authenticationRequest;
  30 ++ (void)authenticate;
  31 ++ (NSString *)username;
  32 ++ (void)setUsername:(NSString *)username;
  33 ++ (NSString *)apiKey;
  34 ++ (void)setApiKey:(NSString *)apiKey;
  35 +
  36 +// helper to parse dates in the format returned by Cloud Files
  37 +-(NSDate *)dateFromString:(NSString *)dateString;
  38 +
  39 +
  40 +@end
  1 +//
  2 +// ASICloudFilesRequest.m
  3 +// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
  4 +//
  5 +// Created by Michael Mayo on 22/12/09.
  6 +// Copyright 2009 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +// A class for accessing data stored on Rackspace's Cloud Files Service
  9 +// http://www.rackspacecloud.com/cloud_hosting_products/files
  10 +//
  11 +// Cloud Files Developer Guide:
  12 +// http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf
  13 +
  14 +#import "ASICloudFilesRequest.h"
  15 +
  16 +static NSString *username = nil;
  17 +static NSString *apiKey = nil;
  18 +static NSString *authToken = nil;
  19 +static NSString *storageURL = nil;
  20 +static NSString *cdnManagementURL = nil;
  21 +static NSString *rackspaceCloudAuthURL = @"https://auth.api.rackspacecloud.com/v1.0";
  22 +
  23 +@implementation ASICloudFilesRequest
  24 +
  25 +#pragma mark -
  26 +#pragma mark Attributes and Service URLs
  27 +
  28 ++ (NSString *)authToken {
  29 + return authToken;
  30 +}
  31 +
  32 ++ (NSString *)storageURL {
  33 + return storageURL;
  34 +}
  35 +
  36 ++ (NSString *)cdnManagementURL {
  37 + return cdnManagementURL;
  38 +}
  39 +
  40 +#pragma mark -
  41 +#pragma mark Authentication
  42 +
  43 ++ (id)authenticationRequest {
  44 + ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:rackspaceCloudAuthURL]];
  45 + [request addRequestHeader:@"X-Auth-User" value:username];
  46 + [request addRequestHeader:@"X-Auth-Key" value:apiKey];
  47 + return request;
  48 +}
  49 +
  50 ++ (void)authenticate {
  51 + ASIHTTPRequest *request = [ASICloudFilesRequest authenticationRequest];
  52 + [request start];
  53 +
  54 + if (![request error]) {
  55 + NSDictionary *responseHeaders = [request responseHeaders];
  56 + authToken = [responseHeaders objectForKey:@"X-Auth-Token"];
  57 + storageURL = [responseHeaders objectForKey:@"X-Storage-Url"];
  58 + cdnManagementURL = [responseHeaders objectForKey:@"X-Cdn-Management-Url"];
  59 + }
  60 +}
  61 +
  62 ++ (NSString *)username {
  63 + return username;
  64 +}
  65 +
  66 ++ (void)setUsername:(NSString *)newUsername {
  67 + [username release];
  68 + username = [newUsername retain];
  69 +}
  70 +
  71 ++ (NSString *)apiKey {
  72 + return apiKey;
  73 +}
  74 +
  75 ++ (void)setApiKey:(NSString *)newApiKey {
  76 + [apiKey release];
  77 + apiKey = [newApiKey retain];
  78 +}
  79 +
  80 +#pragma mark -
  81 +#pragma mark Date Parser
  82 +
  83 +-(NSDate *)dateFromString:(NSString *)dateString {
  84 + NSDateFormatter *format = [[NSDateFormatter alloc] init];
  85 + // example: 2009-11-04T19:46:20.192723
  86 + [format setDateFormat:@"yyyy-MM-dd'T'H:mm:ss"];
  87 + NSDate *date = [format dateFromString:dateString];
  88 + [format release];
  89 +
  90 + return date;
  91 +}
  92 +
  93 +@end
  1 +//
  2 +// ASICloudFilesRequestTests.h
  3 +//
  4 +// Created by Michael Mayo on 1/6/10.
  5 +//
  6 +
  7 +#import "ASITestCase.h"
  8 +
  9 +@class ASINetworkQueue;
  10 +
  11 +@interface ASICloudFilesRequestTests : ASITestCase {
  12 + ASINetworkQueue *networkQueue;
  13 + float progress;
  14 +}
  15 +
  16 +@property (retain,nonatomic) ASINetworkQueue *networkQueue;
  17 +
  18 +@end
This diff is collapsed. Click to expand it.
@@ -23,9 +23,7 @@ @@ -23,9 +23,7 @@
23 [super dealloc]; 23 [super dealloc];
24 } 24 }
25 25
26 -  
27 - (void)applicationDidFinishLaunching:(UIApplication *)application { 26 - (void)applicationDidFinishLaunching:(UIApplication *)application {
28 -  
29 // Add the tab bar controller's current view as a subview of the window 27 // Add the tab bar controller's current view as a subview of the window
30 [window addSubview:[tabBarController view]]; 28 [window addSubview:[tabBarController view]];
31 [[tabBarController view] setFrame:CGRectMake(0,47,320,433)]; 29 [[tabBarController view] setFrame:CGRectMake(0,47,320,433)];