Michael Mayo

laying out class structure and making notes

//
// ASICFRequest.h
// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
//
// Created by Michael Mayo on 22/12/09.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
// A (basic) class for accessing data stored on Rackspace's Cloud Files Service
// http://www.rackspacecloud.com/cloud_hosting_products/files
#import <Foundation/Foundation.h>
@interface ASICFRequest : NSObject {
}
@end
//
// ASICloudFilesCDNRequest.h
// iPhone
//
// Created by Michael Mayo on 1/6/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ASICloudFilesRequest.h"
@interface ASICloudFilesCDNRequest : ASICloudFilesRequest {
}
@end
... ...
//
// ASICFRequest.m
// ASICloudFilesCDNRequest.m
// iPhone
//
// Created by Michael Mayo on 12/22/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
// Created by Michael Mayo on 1/6/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ASICFRequest.h"
#import "ASICloudFilesCDNRequest.h"
@implementation ASICFRequest
@implementation ASICloudFilesCDNRequest
@end
... ...
//
// ASICloudFilesContainerRequest.h
// iPhone
//
// Created by Michael Mayo on 1/6/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ASICloudFilesRequest.h"
@interface ASICloudFilesContainerRequest : ASICloudFilesRequest {
NSMutableArray *containerNames;
//NSUInteger containerCount;
//NSUInteger bytesUsed;
NSUInteger limit;
NSString *marker; // last item found as the offset
NSString *format; // json or xml
// Internally used while parsing the response
NSString *currentContent;
NSString *currentElement;
//ASIS3BucketObject *currentObject;
//NSMutableArray *objects;
}
#pragma mark Constructors
// HEAD /<api version>/<account>
// 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.
+ (id)accountInfoRequest;
// GET /<api version>/<account>/<container>
// Create a request to list all containers
+ (id)listRequest;
// PUT /<api version>/<account>/<container>
+ (id)createContainerRequest:(NSString *)containerName;
// DELETE /<api version>/<account>/<container>
+ (id)deleteContainerRequest:(NSString *)containerName;
- (NSUInteger)containerCount;
- (NSUInteger)bytesUsed;
// ASICloudFilesContainerListRequest
// GET on account (for containers)
// limit
// marker (last item found as the offset)
// format - 'json' or 'xml'
// create container
// DELETE to delete
@end
... ...
//
// ASICloudFilesContainerRequest.m
// iPhone
//
// Created by Michael Mayo on 1/6/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ASICloudFilesContainerRequest.h"
@implementation ASICloudFilesContainerRequest
//ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:rackspaceCloudAuthURL]];
//NSMutableDictionary *headers = [[NSMutableDictionary alloc] initWithCapacity:2];
//[headers setObject:username forKey:@"X-Auth-User"];
//[headers setObject:apiKey forKey:@"X-Auth-Key"];
//[request setRequestHeaders:headers];
//[headers release];
//return request;
#pragma mark -
#pragma mark Constructors
+ (id)storageRequestWithMethod:(NSString *)method {
//ASICloudFilesRequest *request = [ASICloudFilesRequest storageRequest];
ASICloudFilesContainerRequest *request = [[ASICloudFilesContainerRequest alloc] initWithURL:[NSURL URLWithString:[ASICloudFilesRequest storageURL]]];
[request setRequestMethod:method];
NSMutableDictionary *headers = [[NSMutableDictionary alloc] initWithCapacity:1];
[headers setObject:[ASICloudFilesRequest authToken] forKey:@"X-Auth-Token"];
[request setRequestHeaders:headers];
[headers release];
return request;
}
// HEAD /<api version>/<account>
// 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.
+ (id)accountInfoRequest {
ASICloudFilesContainerRequest *request = [ASICloudFilesContainerRequest storageRequestWithMethod:@"HEAD"];
return request;
}
// GET /<api version>/<account>/<container>
// Create a request to list all containers
+ (id)listRequest {
ASICloudFilesContainerRequest *request = [ASICloudFilesContainerRequest storageRequestWithMethod:@"GET"];
return request;
}
// PUT /<api version>/<account>/<container>
+ (id)createContainerRequest:(NSString *)containerName {
ASICloudFilesContainerRequest *request = [ASICloudFilesContainerRequest storageRequestWithMethod:@"PUT"];
return request;
}
// DELETE /<api version>/<account>/<container>
+ (id)deleteContainerRequest:(NSString *)containerName {
ASICloudFilesContainerRequest *request = [ASICloudFilesContainerRequest storageRequestWithMethod:@"DELETE"];
return request;
}
#pragma mark -
#pragma mark Response Data
#pragma mark Account Info
- (NSUInteger)containerCount {
return [[[self responseHeaders] objectForKey:@"X-Account-Container-Count"] intValue];
}
- (NSUInteger)bytesUsed {
return [[[self responseHeaders] objectForKey:@"X-Account-Bytes-Used"] intValue];
}
#pragma mark Container List
- (NSArray *)containers {
if (containerNames) {
return containerNames;
}
containerNames = [[[NSMutableArray alloc] init] autorelease];
NSXMLParser *parser = [[[NSXMLParser alloc] initWithData:[self responseData]] autorelease];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
return containerNames;
}
#pragma mark -
#pragma mark XML Parser Delegate
/*
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
[self setCurrentElement:elementName];
if ([elementName isEqualToString:@"Contents"]) {
[self setCurrentObject:[ASIS3BucketObject objectWithBucket:[self bucket]]];
}
[self setCurrentContent:@""];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"Contents"]) {
[objects addObject:currentObject];
[self setCurrentObject:nil];
} else if ([elementName isEqualToString:@"Key"]) {
[[self currentObject] setKey:[self currentContent]];
} else if ([elementName isEqualToString:@"LastModified"]) {
[[self currentObject] setLastModified:[dateFormatter dateFromString:[self currentContent]]];
} else if ([elementName isEqualToString:@"ETag"]) {
[[self currentObject] setETag:[self currentContent]];
} else if ([elementName isEqualToString:@"Size"]) {
[[self currentObject] setSize:(unsigned long long)[[self currentContent] longLongValue]];
} else if ([elementName isEqualToString:@"ID"]) {
[[self currentObject] setOwnerID:[self currentContent]];
} else if ([elementName isEqualToString:@"DisplayName"]) {
[[self currentObject] setOwnerName:[self currentContent]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
[self setCurrentContent:[[self currentContent] stringByAppendingString:string]];
}
*/
@end
... ...
//
// ASICloudFilesObjectRequest.h
// iPhone
//
// Created by Michael Mayo on 1/6/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ASICloudFilesRequest.h"
@interface ASICloudFilesObjectRequest : ASICloudFilesRequest {
}
@end
... ...
//
// ASICloudFilesObjectRequest.m
// iPhone
//
// Created by Michael Mayo on 1/6/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ASICloudFilesObjectRequest.h"
@implementation ASICloudFilesObjectRequest
@end
... ...
//
// ASICloudFilesRequest.h
// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
//
// Created by Michael Mayo on 22/12/09.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
// A (basic) class for accessing data stored on Rackspace's Cloud Files Service
// http://www.rackspacecloud.com/cloud_hosting_products/files
//
// Cloud Files Developer Guide:
// http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf
#import <Foundation/Foundation.h>
#import "ASIHTTPRequest.h"
@interface ASICloudFilesRequest : ASIHTTPRequest {
// ASICloudFilesObjectListRequest
// GET on container (for objects)
// limit
// marker
// prefix - For a string value X, causes the results to be limited to Object names beginning with the substring X.
// path - Now issuing a GET request against the Container name coupled with the “path” query parameter of the directory to list can traverse these “directories”. GET /v1/AccountString/backups?path=photos/animals
// PUT /<api version>/<account>/<container>/<object>
// PUT operations are used to write, or overwrite, an Object's metadata and content.
// POST /<api version>/<account>/<container>/<object>
// 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).
// A POST request will delete all existing metadata added with a previous PUT/POST.
// DELETE /<api version>/<account>/<container>/<object>
// GET operations against the X-CDN-Management-Url for an account are performed to retrieve a list of existing CDN-enabled Containers
// GET /<api version>/<account>
// list containers
// list objects in a container
// cdn operations
}
+ (NSString *)storageURL;
+ (NSString *)authToken;
#pragma mark Rackspace Cloud Authentication
+ (void)authenticate;
+ (NSString *)username;
+ (void)setUsername:(NSString *)username;
+ (NSString *)apiKey;
+ (void)setApiKey:(NSString *)apiKey;
#pragma mark Constructors
+ (id)authenticationRequest;
+ (id)storageRequest;
+ (id)cdnRequest;
//+ (id)PUTRequestForFile:(NSString *)filePath withContainer:(NSString *)container path:(NSString *)path;
// Create a request to list all objects in a container
//+ (id)objectListRequestWithContainer:(NSString *)container;
// HEAD /<api version>/<account>/<container>
// HEAD operations against a storage Container are used to determine the number of Objects, and the total bytes of all Objects stored in the Container.
// The Object count and utilization are returned in the X- Container-Object-Count and X-Container-Bytes-Used headers respectively.
// HEAD /<api version>/<account>/<container>/<object>
// No response body is returned. Metadata is returned as HTTP headers. A status code of 204 (No Content) indicates success, status 404 (Not Found) is returned when the Object does not exist.
// CDN URL
// HEAD /<api version>/<account>/<container>
// HEAD operations against a CDN-enabled Container are used to determine the CDN attributes of the Container.
// PUT operations against a Container are used to CDN-enable that Container.
// POST operations against a CDN-enabled Container are used to adjust CDN attributes.
// Create a request, building an appropriate url
//+ (id)requestWithContainer:(NSString *)container path:(NSString *)path;
//
//// Create a PUT request using the file at filePath as the body
//+ (id)PUTRequestForFile:(NSString *)filePath withContainer:(NSString *)container path:(NSString *)path;
//
//// Create a PUT request using the supplied NSData as the body (set the mime-type manually with setMimeType: if necessary)
//+ (id)PUTRequestForData:(NSData *)data withContainer:(NSString *)container path:(NSString *)path;
//
//// Create a DELETE request for the object at path
//+ (id)DELETERequestWithContainer:(NSString *)container path:(NSString *)path;
// TODO: CDN toggle containers
@end
... ...
//
// ASICloudFilesRequest.m
// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
//
// Created by Michael Mayo on 22/12/09.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
// A (basic) class for accessing data stored on Rackspace's Cloud Files Service
// http://www.rackspacecloud.com/cloud_hosting_products/files
//
// Cloud Files Developer Guide:
// http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf
#import "ASICloudFilesRequest.h"
static NSString *username = nil;
static NSString *apiKey = nil;
static NSString *authToken = nil;
static NSString *storageURL = nil;
static NSString *cdnManagementURL = nil;
static NSString *rackspaceCloudAuthURL = @"https://auth.api.rackspacecloud.com/v1.0";
@implementation ASICloudFilesRequest
+ (NSString *)storageURL {
return storageURL;
}
+ (NSString *)authToken {
return authToken;
}
+ (id)authenticationRequest {
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:rackspaceCloudAuthURL]];
NSMutableDictionary *headers = [[NSMutableDictionary alloc] initWithCapacity:2];
[headers setObject:username forKey:@"X-Auth-User"];
[headers setObject:apiKey forKey:@"X-Auth-Key"];
[request setRequestHeaders:headers];
[headers release];
return request;
}
+ (id)storageRequest {
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:storageURL]];
return request;
}
+ (id)cdnRequest {
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:cdnManagementURL]];
return request;
}
+ (void)authenticate {
ASIHTTPRequest *request = [ASICloudFilesRequest authenticationRequest];
[request start];
if (![request error]) {
NSDictionary *responseHeaders = [request responseHeaders];
authToken = [responseHeaders objectForKey:@"X-Auth-Token"];
storageURL = [responseHeaders objectForKey:@"X-Storage-Url"];
cdnManagementURL = [responseHeaders objectForKey:@"X-Cdn-Management-Url"];
} else {
NSLog(@"%@",[[request error] localizedDescription]);
}
}
+ (NSString *)username {
return username;
}
+ (void)setUsername:(NSString *)newUsername {
[username release];
username = [newUsername retain];
}
+ (NSString *)apiKey {
return apiKey;
}
+ (void)setApiKey:(NSString *)newApiKey {
[apiKey release];
apiKey = [newApiKey retain];
}
@end
... ...
... ... @@ -21,7 +21,7 @@
#import "ASIInputStream.h"
// Automatically set on build
NSString *ASIHTTPRequestVersion = @"v1.2-24 2009-12-18";
NSString *ASIHTTPRequestVersion = @"v1.2-26 2010-01-07";
// We use our own custom run loop mode as CoreAnimation seems to want to hijack our threads otherwise
static CFStringRef ASIHTTPRequestRunMode = CFSTR("ASIHTTPRequest");
... ...
//
// ASICloudFilesRequestTests.h
// iPhone
//
// Created by Michael Mayo on 1/6/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ASITestCase.h"
@class ASINetworkQueue;
@interface ASICloudFilesRequestTests : NSObject {
ASINetworkQueue *networkQueue;
}
@end
... ...
//
// ASICloudFilesRequestTests.m
// iPhone
//
// Created by Michael Mayo on 1/6/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ASICloudFilesRequestTests.h"
@implementation ASICloudFilesRequestTests
@end
... ...
... ... @@ -9,6 +9,10 @@
#import "iPhoneSampleAppDelegate.h"
#import "ASIHTTPRequest.h"
#import "Reachability.h"
#import "ASICloudFilesRequest.h"
#import "ASICloudFilesContainerRequest.h"
#import "ASICloudFilesObjectRequest.h"
#import "ASICloudFilesCDNRequest.h"
@implementation iPhoneSampleAppDelegate
... ... @@ -26,6 +30,33 @@
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSLog(@"time to test Cloud Files!");
[ASICloudFilesRequest setUsername:@"greenisus"];
[ASICloudFilesRequest setApiKey:@"1c331a7a4a6eb58ca6072afe81e812d0"];
[ASICloudFilesRequest authenticate];
NSLog(@"Storage URL: %@", [ASICloudFilesRequest storageURL]);
NSLog(@"account info:");
ASICloudFilesContainerRequest *accountInfoRequest = [ASICloudFilesContainerRequest accountInfoRequest];
[accountInfoRequest start];
NSLog(@"Response status code: %i", [accountInfoRequest responseStatusCode]);
NSLog(@"Response status message: %@", [accountInfoRequest responseStatusMessage]);
NSLog(@"Container count: %i", [accountInfoRequest containerCount]);
NSLog(@"Bytes used: %i", [accountInfoRequest bytesUsed]);
NSLog(@"All headers:");
NSDictionary *headers = [accountInfoRequest responseHeaders];
NSArray *keys = [headers allKeys];
for (int i = 0; i < [keys count]; i++) {
NSString *key = [keys objectAtIndex:i];
NSLog(@"%@: %@", key, [headers objectForKey:key]);
}
// Add the tab bar controller's current view as a subview of the window
[window addSubview:[tabBarController view]];
[[tabBarController view] setFrame:CGRectMake(0,47,320,433)];
... ...
This diff was suppressed by a .gitattributes entry.
#!/bin/sh
versionString=`/opt/local/bin/git describe --tags`
versionString=`/usr/local/bin/git describe --tags`
version="`echo $versionString | sed -E 's/(v([0-9]+)\.([0-9]+))(.*)/\1/g'`"
commitNum="`echo $versionString | sed -E 's/(v([0-9]+)\.([0-9]+))\-([0-9]*)(.*)/\4/g'`"
date=`date "+%Y-%m-%d"`
... ...