Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Upgraded Dropbox SDK to v1.0
Browse files Browse the repository at this point in the history
Closes #56, closes #57
  • Loading branch information
chuckbjones authored and ginatrapani committed Nov 10, 2011
1 parent 5e4918c commit e4df7e9
Show file tree
Hide file tree
Showing 100 changed files with 376 additions and 6,250 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -12,6 +12,7 @@ build/*

xcuserdata
dropbox.plist
DropboxApiKey.h

todo.txt-touch-ios.xcodeproj/xcuserdata/*
todo.txt-touch-ios.xcodeproj/project.xcworkspace/xcuserdata/*
todo.txt-touch-ios.xcodeproj/project.xcworkspace/xcuserdata/*
3 changes: 2 additions & 1 deletion Classes/DropboxRemoteClient.h
Expand Up @@ -49,7 +49,7 @@

#import <Foundation/Foundation.h>
#import "RemoteClient.h"
#import "DropboxSDK.h"
#import <DropboxSDK/DropboxSDK.h>
#import "TestFlight.h"

@interface DropboxRemoteClient : NSObject<RemoteClient> {
Expand All @@ -66,5 +66,6 @@
- (void) pullTodo;
- (void) pushTodo:(NSString*)path;
- (BOOL) isAvailable;
- (BOOL) handleOpenURL:(NSURL *)url;

@end
55 changes: 26 additions & 29 deletions Classes/DropboxRemoteClient.m
Expand Up @@ -51,8 +51,10 @@
#import "Network.h"
#import "TaskIo.h"
#import "TestFlight.h"
#import "DropboxApiKey.h"
#import "Util.h"

@interface DropboxRemoteClient () <DBSessionDelegate, DBRestClientDelegate, DBLoginControllerDelegate>
@interface DropboxRemoteClient () <DBSessionDelegate, DBRestClientDelegate>
@end

@implementation DropboxRemoteClient
Expand All @@ -65,21 +67,13 @@ - (NSString*) todoTxtTmpFile {
@"todo.txt", nil]];
}

- (NSDictionary*) getApiKey {
NSBundle* bundle = [NSBundle mainBundle];
NSString* plistPath = [bundle pathForResource:@"dropbox" ofType:@"plist"];
return [[[NSDictionary alloc] initWithContentsOfFile:plistPath] autorelease];
}

- (id) init {
self = [super init];
if (self) {
NSDictionary *apiKey = [self getApiKey];
NSString* consumerKey = [apiKey objectForKey:@"dropbox_consumer_key"];
NSString* consumerSecret = [apiKey objectForKey:@"dropbox_consumer_secret"];

DBSession* session =
[[DBSession alloc] initWithConsumerKey:consumerKey consumerSecret:consumerSecret];
[[DBSession alloc] initWithAppKey:str(DROPBOX_APP_KEY)
appSecret:str(DROPBOX_APP_SECRET)
root:kDBRootDropbox];
session.delegate = self;
[DBSession setSharedSession:session];
[session release];
Expand All @@ -97,7 +91,7 @@ - (BOOL) authenticate {
}

- (void) deauthenticate {
[[DBSession sharedSession] unlink];
[[DBSession sharedSession] unlinkAll];
[[NSFileManager defaultManager]
removeItemAtPath:[self todoTxtTmpFile]
error:nil];
Expand All @@ -108,9 +102,7 @@ - (BOOL) isAuthenticated {
}

- (void) presentLoginControllerFromController:(UIViewController*)parentViewController {
DBLoginController* controller = [[DBLoginController new] autorelease];
controller.delegate = self;
[controller presentFromController:parentViewController];
[[DBSession sharedSession] link];
}

- (DBRestClient*)restClient {
Expand Down Expand Up @@ -146,6 +138,7 @@ - (void) pushTodo:(NSString*)path {

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *remotePath = [defaults stringForKey:@"file_location_preference"];
//FIXME: set parent rev?
[self.restClient uploadFile:@"todo.txt" toPath:remotePath fromPath:path];
}

Expand Down Expand Up @@ -192,25 +185,29 @@ - (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)err
#pragma mark -
#pragma mark DBSessionDelegate methods

- (void)sessionDidReceiveAuthorizationFailure:(DBSession*)session {
- (void)sessionDidReceiveAuthorizationFailure:(DBSession *)session userId:(NSString *)userId {
//TODO: signal login failure
}


#pragma mark -
#pragma mark DBLoginControllerDelegate methods

- (void)loginControllerDidLogin:(DBLoginController*)controller {
// call RemoteClientDelegate method
if (self.delegate && [self.delegate respondsToSelector:@selector(remoteClient:loginControllerDidLogin:)]) {
[self.delegate remoteClient:self loginControllerDidLogin:YES];
}
}

- (void)loginControllerDidCancel:(DBLoginController*)controller {
if (self.delegate && [self.delegate respondsToSelector:@selector(remoteClient:loginControllerDidLogin:)]) {
[self.delegate remoteClient:self loginControllerDidLogin:NO];
}
- (BOOL) handleOpenURL:(NSURL *)url {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"App linked successfully!");
// call RemoteClientDelegate method
if (self.delegate && [self.delegate respondsToSelector:@selector(remoteClient:loginControllerDidLogin:)]) {
[self.delegate remoteClient:self loginControllerDidLogin:YES];
}
} else {
if (self.delegate && [self.delegate respondsToSelector:@selector(remoteClient:loginControllerDidLogin:)]) {
[self.delegate remoteClient:self loginControllerDidLogin:NO];
}
}
return YES;
}
return NO;
}

@end
1 change: 1 addition & 0 deletions Classes/RemoteClient.h
Expand Up @@ -66,6 +66,7 @@ typedef enum {
- (void) pullTodo;
- (void) pushTodo:(NSString*)path;
- (BOOL) isAvailable;
- (BOOL) handleOpenURL:(NSURL *)url;

@required
@property (nonatomic, assign) id<RemoteClientDelegate> delegate;
Expand Down
4 changes: 4 additions & 0 deletions Classes/Util.h
Expand Up @@ -49,6 +49,10 @@

#import <Foundation/Foundation.h>

// str(x) converts a preprocessor macro to an NSString literal
// see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
#define str(x) @_str(x)
#define _str(x) #x

@interface Util : NSObject {

Expand Down
12 changes: 12 additions & 0 deletions Classes/todo_txt_touch_iosAppDelegate.m
Expand Up @@ -321,6 +321,18 @@ - (void)remoteClient:(id<RemoteClient>)client loginControllerDidLogin:(BOOL)succ
}
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([remoteClientManager.currentClient handleOpenURL:url]) {
if ([remoteClientManager.currentClient isAuthenticated]) {
NSLog(@"App linked successfully!");
// At this point you can start making API calls
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}

#pragma mark -
#pragma mark Memory management

Expand Down
Binary file added DropboxSDK.framework/DropboxSDK
Binary file not shown.
Expand Up @@ -10,6 +10,7 @@
#import "DBQuota.h"

@interface DBAccountInfo : NSObject <NSCoding> {
NSString* email;
NSString* country;
NSString* displayName;
DBQuota* quota;
Expand All @@ -19,6 +20,7 @@

- (id)initWithDictionary:(NSDictionary*)dict;

@property (nonatomic, readonly) NSString* email;
@property (nonatomic, readonly) NSString* country;
@property (nonatomic, readonly) NSString* displayName;
@property (nonatomic, readonly) DBQuota* quota;
Expand Down
10 changes: 10 additions & 0 deletions DropboxSDK.framework/Headers/DBDefines.h
@@ -0,0 +1,10 @@
//
// DBDefines.h
// DropboxSDK
//
// Created by Brian Smith on 8/8/11.
// Copyright 2011 Dropbox, Inc. All rights reserved.
//

// Taken from three20 (http://three20.info/)
#define DB_FIX_CATEGORY_BUG(name) @interface DB_FIX_CATEGORY_BUG##name @end @implementation DB_FIX_CATEGORY_BUG##name @end
Expand Up @@ -16,4 +16,6 @@ typedef enum {
DBErrorGenericError = 1000,
DBErrorFileNotFound,
DBErrorInsufficientDiskSpace,
DBErrorIllegalFileType, // Error sent if you try to upload a directory
DBErrorInvalidResponse, // Sent when the client does not get valid JSON when it's expecting it
} DBErrorCode;
38 changes: 38 additions & 0 deletions DropboxSDK.framework/Headers/DBLog.h
@@ -0,0 +1,38 @@
//
// DBLog.h
// Dropbox
//
// Created by Will Stockwell on 11/4/10.
// Copyright 2010 Dropbox, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

#if !defined(NS_FORMAT_FUNCTION)
#define NS_FORMAT_FUNCTION(F, A)
#endif

typedef enum {
DBLogLevelInfo = 0,
DBLogLevelAnalytics,
DBLogLevelWarning,
DBLogLevelError,
DBLogLevelFatal
} DBLogLevel;

typedef void DBLogCallback(DBLogLevel logLevel, NSString *format, va_list args);

NSString * DBLogFilePath(void);
void DBSetupLogToFile(void);

NSString* DBStringFromLogLevel(DBLogLevel logLevel);


void DBLogSetLevel(DBLogLevel logLevel);
void DBLogSetCallback(DBLogCallback *callback);

void DBLog(DBLogLevel logLevel, NSString *format, ...) NS_FORMAT_FUNCTION(2,3);
void DBLogInfo(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
void DBLogWarning(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
void DBLogError(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
void DBLogFatal(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
Expand Up @@ -18,8 +18,11 @@
NSString* humanReadableSize;
NSString* root;
NSString* icon;
long long revision;
NSString* rev;
long long revision; // Deprecated; will be removed in version 2. Use rev whenever possible
BOOL isDeleted;

NSString *filename;
}

- (id)initWithDictionary:(NSDictionary*)dict;
Expand All @@ -34,7 +37,9 @@
@property (nonatomic, readonly) NSString* humanReadableSize;
@property (nonatomic, readonly) NSString* root;
@property (nonatomic, readonly) NSString* icon;
@property (nonatomic, readonly) long long revision;
@property (nonatomic, readonly) long long revision; // Deprecated, use rev instead
@property (nonatomic, readonly) NSString* rev;
@property (nonatomic, readonly) BOOL isDeleted;
@property (nonatomic, readonly) NSString* filename;

@end
File renamed without changes.
Expand Up @@ -44,6 +44,10 @@
/* Cancels the request and prevents it from sending additional messages to the delegate. */
- (void)cancel;

/* If there is no error, it will parse the response as JSON and make sure the JSON object is the
correct type. If not, it will set the error object with an error code of DBErrorInvalidResponse */
- (id)parseResponseAsType:(Class)cls;

@property (nonatomic, assign) SEL failureSelector; // To send failure events to a different selector set this
@property (nonatomic, assign) SEL downloadProgressSelector; // To receive download progress events set this
@property (nonatomic, assign) SEL uploadProgressSelector; // To receive upload progress events set this
Expand All @@ -53,6 +57,7 @@
@property (nonatomic, readonly) NSURLRequest* request;
@property (nonatomic, readonly) NSHTTPURLResponse* response;
@property (nonatomic, readonly) NSInteger statusCode;
@property (nonatomic, readonly) long long contentLength;
@property (nonatomic, readonly) CGFloat downloadProgress;
@property (nonatomic, readonly) CGFloat uploadProgress;
@property (nonatomic, readonly) NSData* resultData;
Expand Down

0 comments on commit e4df7e9

Please sign in to comment.