Browse files

Uploading almost done

  • Loading branch information...
1 parent e029d50 commit 0a495885e757f43a30f9fe4e17d4efcd75851452 @soffes committed Aug 29, 2010
View
2 Classes/CloudAppCredentials.h
@@ -9,6 +9,6 @@
@interface CloudAppCredentials : RMUploadCredentials
@property (copy) NSString *email;
-@property (copy) NSString *digest;
+@property (copy) NSString *password;
@end
View
16 Classes/CloudAppCredentials.m
@@ -9,17 +9,17 @@
#import "CloudAppCredentials.h"
NSString *const CloudAppCredentialsEmailKey = @"email";
-NSString *const CloudAppCredentialsDigestKey = @"digest";
+NSString *const CloudAppCredentialsPasswordKey = @"password";
@implementation CloudAppCredentials
@synthesize email;
-@synthesize digest;
+@synthesize password;
+ (NSSet *)_propertyKeys {
return [NSSet setWithObjects:
CloudAppCredentialsEmailKey,
- CloudAppCredentialsDigestKey,
+ CloudAppCredentialsPasswordKey,
nil];
}
@@ -30,7 +30,7 @@ + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
if ([key isEqualToString:RMUploadCredentialsDirtyKey]) {
[keyPaths unionSet:[NSSet setWithObjects:
CloudAppCredentialsEmailKey,
- CloudAppCredentialsDigestKey,
+ CloudAppCredentialsPasswordKey,
nil]];
}
@@ -48,8 +48,8 @@ - (id)initWithPropertyListRepresentation:(id)values {
self.email = [values valueForKey:CloudAppCredentialsEmailKey];
}
- if ([values valueForKey:CloudAppCredentialsDigestKey] != nil) {
- self.digest = [values valueForKey:CloudAppCredentialsDigestKey];
+ if ([values valueForKey:CloudAppCredentialsPasswordKey] != nil) {
+ self.password = [values valueForKey:CloudAppCredentialsPasswordKey];
}
}
return self;
@@ -64,8 +64,8 @@ - (id)propertyListRepresentation {
[plist setObject:self.email forKey:CloudAppCredentialsEmailKey];
}
- if (self.digest != nil) {
- [plist setObject:self.digest forKey:CloudAppCredentialsDigestKey];
+ if (self.password != nil) {
+ [plist setObject:self.password forKey:CloudAppCredentialsPasswordKey];
}
return plist;
View
10 Classes/CloudAppCredentialsViewController.m
@@ -27,9 +27,7 @@ @implementation CloudAppCredentialsViewController
#pragma mark NSObject
- (id)init {
- if ((self = [super initWithNibName:@"CredentialsView" bundle:[NSBundle bundleWithIdentifier:CloudAppBundleIdentifier]])) {
-
- }
+ self = [super initWithNibName:@"CredentialsView" bundle:[NSBundle bundleWithIdentifier:CloudAppBundleIdentifier]];
return self;
}
@@ -61,8 +59,8 @@ - (IBAction)nextStage:(id)sender {
[self _cancelRequest];
_request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://my.cl.ly/items?per_page=1"]];
- [_request addRequestHeader:@"Accept" value:@"application/json"];
_request.delegate = self;
+ [_request addRequestHeader:@"Accept" value:@"application/json"];
[_request startAsynchronous];
[self setAuthenticating:YES];
@@ -114,10 +112,10 @@ - (void)requestFinished:(ASIHTTPRequest *)request {
}
NSString *email = [[[self loginEmailField] stringValue] lowercaseString];
- NSString *digest = [ASIHTTPRequest base64forData:[[NSString stringWithFormat:@"%@:%@", email, [[self loginPasswordField] stringValue]] dataUsingEncoding:NSUTF8StringEncoding]];
+ NSString *password = [[self loginPasswordField] stringValue];
[self.representedObject setEmail:email];
- [self.representedObject setDigest:digest];
+ [self.representedObject setPassword:password];
[self setAuthenticating:NO];
[[NSNotificationCenter defaultCenter] postNotificationName:RMUploadPresetConfigurationViewControllerDidCompleteNotificationName object:self];
View
5 Classes/CloudAppPreset.m
@@ -46,10 +46,7 @@ - (id)propertyListRepresentation {
- (NSSet *)acceptedTypes {
- NSMutableSet *acceptedtypes = [[super acceptedTypes] mutableCopy];
- [acceptedtypes addObject:(id)kUTTypeJPEG];
- [acceptedtypes addObject:(id)kUTTypePNG];
- return acceptedtypes;
+ return [NSSet setWithObject:(id)kUTTypeItem];
}
@end
View
4 Classes/CloudAppPresetViewController.m
@@ -11,9 +11,7 @@
@implementation CloudAppPresetViewController
- (id)init {
- if ((self = [super initWithNibName:@"PresetView" bundle:[NSBundle bundleWithIdentifier:CloudAppBundleIdentifier]])) {
-
- }
+ self = [super initWithNibName:@"PresetView" bundle:[NSBundle bundleWithIdentifier:CloudAppBundleIdentifier]];
return self;
}
View
3 Classes/CloudAppUploadTask.h
@@ -7,11 +7,12 @@
//
#import "ASIHTTPRequestDelegate.h"
+#import "ASIProgressDelegate.h"
@class ASIHTTPRequest;
@class ASIFormDataRequest;
-@interface CloudAppUploadTask : RMUploadTask <ASIHTTPRequestDelegate> {
+@interface CloudAppUploadTask : RMUploadTask <ASIHTTPRequestDelegate, ASIProgressDelegate> {
RMUploadPreset *_destination;
id _uploadInfo;
View
71 Classes/CloudAppUploadTask.m
@@ -14,7 +14,6 @@
@interface CloudAppUploadTask (PrivateMethods)
- (void)_cancelRequest:(ASIHTTPRequest *)aRequest;
- (void)_failWithError:(NSError *)error;
-- (void)_postCompletionNotification;
@end
@@ -23,8 +22,9 @@ @implementation CloudAppUploadTask
#pragma mark NSObject
- (void)dealloc {
- [self _cancelRequest:_cloudRequest];
- [self _cancelRequest:_s3Request];
+ // TODO: uncomment these once we're sure we aren't causing bad access
+// [self _cancelRequest:_cloudRequest];
+// [self _cancelRequest:_s3Request];
[_destination release];
[_uploadInfo release];
[super dealloc];
@@ -43,13 +43,12 @@ - (id)initWithPreset:(RMUploadPreset *)destination uploadInfo:(id)uploadInfo {
- (void)upload {
- NSString *digest = [(CloudAppCredentials *)[_destination authentication] digest];
+ NSLog(@"[CloudApp.uploader] Start upload");
[self _cancelRequest:_cloudRequest];
_cloudRequest = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://my.cl.ly/items/new"]];
_cloudRequest.delegate = self;
- [_cloudRequest addRequestHeader:@"Authentication" value:[NSString stringWithFormat:@"Basic %@", digest]];\
[_cloudRequest addRequestHeader:@"Accept" value:@"application/json"];
[_cloudRequest startAsynchronous];
}
@@ -64,14 +63,16 @@ - (void)cancel {
[self _cancelRequest:_s3Request];
_s3Request = nil;
- [self _postCompletionNotification];
+ // TODO: Show canceled
+ [[NSNotificationCenter defaultCenter] postNotificationName:RMUploadTaskDidCompleteNotificationName object:self];
}
#pragma mark Private Methods
- (void)_cancelRequest:(ASIHTTPRequest *)aRequest {
aRequest.delegate = nil;
+ aRequest.uploadProgressDelegate = nil;
[aRequest cancel];
[aRequest release];
}
@@ -85,14 +86,22 @@ - (void)_failWithError:(NSError *)error {
}
-- (void)_postCompletionNotification {
- [[NSNotificationCenter defaultCenter] postNotificationName:RMUploadTaskDidCompleteNotificationName object:self];
-}
+#pragma mark ASIHTTPRequestDelegate
+- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request {
+ if ([request authenticationRetryCount] == 0) {
+ CloudAppCredentials *credentials = (CloudAppCredentials *)[_destination authentication];
+ [request applyCredentials:[NSDictionary dictionaryWithObjectsAndKeys:credentials.email, kCFHTTPAuthenticationUsername, credentials.password, kCFHTTPAuthenticationPassword, nil]];
+ [request retryUsingSuppliedCredentials];
+ } else {
+ [request cancelAuthentication];
+ }
+}
-#pragma mark ASIHTTPRequestDelegate
- (void)requestFinished:(ASIHTTPRequest *)request {
+ NSLog(@"[CloudApp.uploader] request finished: %@", request);
+
// Getting upload data finished
if (request == _cloudRequest) {
if ([_cloudRequest responseStatusCode] != 200) {
@@ -103,28 +112,62 @@ - (void)requestFinished:(ASIHTTPRequest *)request {
[self _failWithError:error];
}
+ // S3 Data
NSDictionary *s3Info = [[_cloudRequest responseString] JSONValue];
- NSLog(@"S3 info: %@", s3Info);
+ NSDictionary *params = [s3Info objectForKey:@"params"];
// Clean up
[self _cancelRequest:_cloudRequest];
_cloudRequest = nil;
+
+ // Start S3 request
+ _s3Request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:[s3Info objectForKey:@"url"]]];
+ _s3Request.delegate = self;
+ _s3Request.uploadProgressDelegate = self;
+ _s3Request.shouldUseRFC2616RedirectBehaviour = YES;
+ for (NSString *param in params) {
+ [_s3Request setPostValue:[params objectForKey:param] forKey:param];
+ }
+ NSString *filePath = [(NSURL *)[_uploadInfo valueForKey:RMUploadFileURLKey] path];
+ [_s3Request addFile:filePath forKey:@"file"];
+
+ [_s3Request startAsynchronous];
}
// Upload to S3 finished
else {
// Clean up
[self _cancelRequest:_s3Request];
_s3Request = nil;
+
+ NSLog(@"[CloudApp.uploader] Complete: %@", [_s3Request responseHeaders]);
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSURL URLWithString:@"http://google.com"], RMUploadTaskResourceLocationKey,
+ nil];
+ [[NSNotificationCenter defaultCenter] postNotificationName:RMUploadTaskDidFinishTransactionNotificationName object:self userInfo:userInfo];
+ [[NSNotificationCenter defaultCenter] postNotificationName:RMUploadTaskDidCompleteNotificationName object:self];
}
-
- [self _postCompletionNotification];
}
- (void)requestFailed:(ASIHTTPRequest *)request {
+ NSLog(@"[CloudApp.uploader] request failed: %@", [request error]);
[self _failWithError:[request error]];
-// [self _cancelRequest:request];
}
+
+#pragma mark ASIProgressDelegate
+
+// TODO: Fix this. Ugh.
+
+//- (void)setDoubleValue:(double)newProgress {
+// NSLog(@"[CloudApp.uploader] setting progress: %f", newProgress);
+// NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+// [NSNumber numberWithDouble:newProgress], RMUploadTaskProgressCurrentKey,
+// [NSNumber numberWithDouble:1.0], RMUploadTaskProgressTotalKey,
+// nil];
+// [[NSNotificationCenter defaultCenter] postNotificationName:RMUploadTaskDidReceiveProgressNotificationName object:self userInfo:userInfo];
+// NSLog(@"[CloudApp] set progress: %f", newProgress);
+//}
+
@end
View
2 CloudApp.xcodeproj/project.pbxproj
@@ -216,8 +216,8 @@
B2E46189122AB8BA00A915F8 /* Vendor */ = {
isa = PBXGroup;
children = (
- B2CCDA4C122AE77300D42CE0 /* JSON */,
B2E4618A122AB8BA00A915F8 /* ASIHTTPRequest */,
+ B2CCDA4C122AE77300D42CE0 /* JSON */,
);
path = Vendor;
sourceTree = "<group>";
View
2 Resources/Info.plist
@@ -27,7 +27,7 @@
<key>RMUploadPluginBundleMinimumFrameworkBundleVersion</key>
<string>1</string>
<key>RMUploadPluginServiceHost</key>
- <string>f.cl.ly</string>
+ <string>my.cl.ly</string>
<key>RMUploadPluginServiceUseSSL</key>
<string>NO</string>
</dict>

0 comments on commit 0a49588

Please sign in to comment.