Permalink
Browse files

added support for tags

  • Loading branch information...
1 parent 38e26ed commit 87709257fa38efd737c7bc4c77630733e42c6036 @robertwijas robertwijas committed Aug 6, 2012
@@ -48,6 +48,8 @@
@property (nonatomic, readwrite, retain) NSDate *objectUpdatedTime;
@property (nonatomic, readonly) NSString *objectType;
+@property (nonatomic, readonly) NSMutableArray *tags;
+
- (id)initWithDictionary:(NSDictionary *)values;
- (void)setValuesWithDictionary:(NSDictionary *)values;
- (NSString *)objectToString;
@@ -18,6 +18,7 @@
#import "BoxObject.h"
#import "BoxFolder.h"
#import "BoxFile.h"
+#import "BoxTag.h"
@implementation BoxObject
@@ -32,6 +33,8 @@ @implementation BoxObject
@synthesize objectSize = _objectSize;
@synthesize objectCreatedTime = _objectCreatedTime;
@synthesize objectUpdatedTime = _objectUpdatedTime;
+@synthesize tags = _tags;
+
-(void)releaseAndNilValues {
[_objectId release];
@@ -52,6 +55,8 @@ -(void)releaseAndNilValues {
_objectCreatedTime = nil;
[_objectUpdatedTime release];
_objectUpdatedTime = nil;
+ [_tags release];
+ _tags = nil;
}
- (void)setValuesWithDictionary:(NSDictionary *)values {
@@ -125,8 +130,18 @@ - (NSMutableDictionary *)getValuesInDictionaryForm {
return returnDict;
}
+- (id)init {
+ self = [super init];
+ if (self) {
+ _tags = [[NSMutableArray alloc] init];
+ }
+
+ return self;
+}
+
+
- (id)initWithDictionary:(NSDictionary *)values {
- if (self = [super init]) {
+ if (self = [self init]) {
[self setValuesWithDictionary:values];
}
@@ -35,8 +35,8 @@ + (NSString *)getAuthTokenUrlString:(NSString *)userName userPassword:(NSString
+ (NSString *)getAccountTreeOneLevelUrlString:(NSString *)token boxFolderId:(NSString *)folderID {
NSString *urlString = [NSString stringWithFormat:
- @"https://www.box.net/api/1.0/rest?action=get_account_tree&api_key=%@&auth_token=%@&folder_id=%@&params[]=nozip&params[]=onelevel&params[]=has_collaborators&params[]=checksum",
- BOX_API_KEY,
+ @"https://www.box.net/api/1.0/rest?action=get_account_tree&api_key=%@&auth_token=%@&folder_id=%@&params[]=nozip&params[]=onelevel&params[]=has_collaborators&params[]=checksum&params[]=web_links&params[]=show_tag_names",
+ BOX_API_KEY,
token,
folderID];
@@ -45,7 +45,7 @@ + (NSString *)getAccountTreeOneLevelUrlString:(NSString *)token boxFolderId:(NSS
+ (NSString *)getAccountTreeOneLevelUrlStringFoldersOnly:(NSString *)token boxFolderId:(NSString *)folderID {
NSString *urlString = [NSString stringWithFormat:
- @"https://www.box.net/api/1.0/rest?action=get_account_tree&api_key=%@&auth_token=%@&folder_id=%@&params[]=nozip&params[]=onelevel&params[]=has_collaborators&params[]=checksum&params[]=nofiles",
+ @"https://www.box.net/api/1.0/rest?action=get_account_tree&api_key=%@&auth_token=%@&folder_id=%@&params[]=nozip&params[]=onelevel&params[]=has_collaborators&params[]=checksum&params[]=nofiles&params[]=web_links&params[]=show_tag_names",
BOX_API_KEY,
token,
folderID];
@@ -17,6 +17,7 @@
#import "BoxFolderXMLBuilder.h"
#import "BoxWebLink.h"
+#import "BoxTag.h"
@implementation BoxFolderXMLBuilder
@@ -30,6 +31,7 @@ @implementation BoxFolderXMLBuilder
static BOOL inOuterFolderTag;
static BoxFolder *curModel;
+static BoxObject *currentlyParsedObject;
static NSLock *parserLock = nil; // necessary so that the statics don't trample each other from different threads. Fix later if we want XML parsing & DL to be parallel (doesn't makes sense for iphone though). We should go to JSON though... Really.
@@ -55,6 +57,8 @@ - (BOOL)parseXMLWithUrlLocal:(NSURL *)xmlUrl
basePathOrNil:(NSIndexPath *)path
{
curModel = folder;
+ currentlyParsedObject = nil;
+
basePath = path;
if (!basePath) {
@@ -187,9 +191,11 @@ - (void)parser:(NSXMLParser *)parser
contentHolder = [NSMutableString string ];
} else if ([elementName isEqualToString: @"file"]) {
BoxFile *info = [[[BoxFile alloc] initWithDictionary:attributeDict] autorelease];
+ currentlyParsedObject = info;
[curModel.objectsInFolder addObject:info];
} else if ([elementName isEqualToString: @"web_link"]) {
BoxWebLink *info = [[[BoxWebLink alloc] initWithDictionary:attributeDict] autorelease];
+ currentlyParsedObject = info;
[curModel.objectsInFolder addObject:info];
} else if ([elementName isEqualToString: @"folder"]){
if(inOuterFolderTag == YES) {
@@ -213,11 +219,15 @@ - (void)parser:(NSXMLParser *)parser
[curModel setValuesWithDictionary:attributeDict]; // we do this for the root, otherwise it would be unnecessary.
} else {
BoxFolder *folder = [[BoxFolder alloc] initWithDictionary:attributeDict];
+ currentlyParsedObject = folder;
[curModel.objectsInFolder addObject:folder];
[folder release];
}
} else if ([elementName isEqual: @"collaboration"]) {
inCollaborationTag = NO;
+ } else if ([elementName isEqual: @"tag"]) {
+ BoxTag *tag = [[[BoxTag alloc] initWithDictionary:attributeDict] autorelease];
+ [currentlyParsedObject.tags addObject:tag];
} else {
contentHolder = nil;
}
@@ -0,0 +1,17 @@
+//
+// Created by Robert Wijas on 8/6/12.
+//
+
+
+#import <Foundation/Foundation.h>
+
+
+@interface BoxTag : NSObject
+
+@property(nonatomic, retain)NSString *tagId;
+@property(nonatomic, retain)NSString *name;
+
+- (id)initWithDictionary:(NSDictionary *)values;
+- (void)setAttributesDictionary:(NSDictionary *)attributes;
+
+@end
@@ -0,0 +1,36 @@
+//
+// Created by Robert Wijas on 8/6/12.
+//
+
+
+#import "BoxTag.h"
+
+
+@implementation BoxTag {
+
+}
+
+@synthesize name = _name;
+@synthesize tagId = _tagId;
+
+
+- (void)dealloc {
+ [_name release];
+ [_tagId release];
+ [super dealloc];
+}
+
+- (id)initWithDictionary:(NSDictionary *)values {
+ if (self = [super init]) {
+ [self setAttributesDictionary:values];
+ }
+
+ return self;
+}
+
+- (void)setAttributesDictionary:(NSDictionary *)dictionary {
+ self.tagId = [dictionary objectForKey:@"id"];
+ self.name = [dictionary objectForKey:@"name"];
+}
+
+@end

0 comments on commit 8770925

Please sign in to comment.