Skip to content

Commit

Permalink
[#9] move everything to a category on NSObject
Browse files Browse the repository at this point in the history
  • Loading branch information
vickeryj committed Jan 29, 2009
1 parent 03c1a92 commit 42ae4f8
Show file tree
Hide file tree
Showing 15 changed files with 457 additions and 326 deletions.
8 changes: 4 additions & 4 deletions Classes/Dog.m
Expand Up @@ -33,19 +33,19 @@ - (void) dealloc

#pragma mark ObjectiveResource overrides to handle nestd resources

+ (NSString *)collectionName {
+ (NSString *)getORSCollectionName {
return @"people";
}

- (BOOL)createWithResponse:(NSError **)aError {
- (BOOL)createORSWithResponse:(NSError **)aError {
return [self createAtPath:[[self class] elementPath:[self nestedPath]] withResponse:aError];
}

- (BOOL)updateWithResponse:(NSError **)aError {
- (BOOL)updateORSWithResponse:(NSError **)aError {
return [self updateAtPath:[[self class] elementPath:[self nestedPath]] withResponse:aError];
}

- (BOOL)destroyWithResponse:(NSError **)aError {
- (BOOL)destroyORSWithResponse:(NSError **)aError {
return [self destroyAtPath:[[self class] elementPath:[self nestedPath]] withResponse:aError];
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/DogErrorTest.m
Expand Up @@ -10,15 +10,15 @@

@implementation DogError

+ (NSString *)getSite {
+ (NSString *)getORSSite {
return @"http://localhost:36313/";
}

@end

@implementation DogDoesNotExist

+ (NSString *)getSite {
+ (NSString *)getORSSite {
return @"http://badhost.localhost:9999/";
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/DogTest.m
Expand Up @@ -18,8 +18,8 @@ @implementation DogTest

-(void) setUp {
[ObjectiveResource setSite:@"http://localhost:36313/"];
//[ObjectiveResource setResponseType:JSONResponse];
[ObjectiveResource setResponseType:XmlResponse];
[ObjectiveResource setResponseType:JSONResponse];
//[ObjectiveResource setResponseType:XmlResponse];

owner = [Person find:[NSString stringWithFormat:@"%i",DOG_OWNER]];
}
Expand Down
4 changes: 4 additions & 0 deletions Classes/EditPersonController.m
Expand Up @@ -11,6 +11,7 @@

@implementation EditPersonController

@synthesize person, aTextField, aViewController;

/*
// Implement loadView to create a view hierarchy programmatically.
Expand Down Expand Up @@ -39,6 +40,9 @@ - (void)didReceiveMemoryWarning {


- (void)dealloc {
[person release];
[aTextField release];
[aViewController release];
[super dealloc];
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/Person.m
Expand Up @@ -15,15 +15,15 @@ @implementation Person


// handle pluralization
+ (NSString *)collectionName {
+ (NSString *)getORSCollectionName {
return @"people";
}


// this will go to the url http://localhost:3000/people/<id>/dogs
// and return the array of dogs
-(NSArray *) findAllDogs {
return [Person find:[NSString stringWithFormat:@"%@/%@",personId,@"dogs",nil]];
return [Dog find:[NSString stringWithFormat:@"%@/%@",personId,@"dogs",nil]];
}

@end
74 changes: 74 additions & 0 deletions Classes/lib/NSObject+ObjectiveResource.h
@@ -0,0 +1,74 @@
//
// NSObject+ObjectiveResource.h
// objectivesync
//
// Created by vickeryj on 1/29/09.
// Copyright 2009 Joshua Vickery. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSObject (ObjectiveResource)


// Response Formats
typedef enum {
XmlResponse = 0,
JSONResponse,
} ORSResponseFormat;

// Resource configuration
+ (NSString *)getORSSite;
+ (void)setORSSite:(NSString*)siteURL;
+ (NSString *)getORSUser;
+ (void)setORSUser:(NSString *)user;
+ (NSString *)getORSPassword;
+ (void)setORSPassword:(NSString *)password;
+ (SEL)getORSParseDataMethod;
+ (void)setORSParseDataMethod:(SEL)parseMethod;
+ (SEL) getORSSerializeMethod;
+ (void) setORSSerializeMethod:(SEL)serializeMethod;
+ (NSString *)getORSProtocolExtension;
+ (void)setORSProtocolExtension:(NSString *)protocolExtension;
+ (void)setORSResponseType:(ORSResponseFormat) format;
+ (ORSResponseFormat)getORSResponseType;


// Finders
+ (NSArray *)findAllORS;
+ (NSArray *)findAllORSWithResponse:(NSError **)aError;
+ (id)findORS:(NSString *)elementId;
+ (id)findORS:(NSString *)elementId withResponse:(NSError **)aError;

// URL construction accessors
+ (NSString *)getORSElementName;
+ (NSString *)getORSCollectionName;
+ (NSString *)getORSElementPath:(NSString *)elementId;
+ (NSString *)getORSCollectionPath;
+ (NSString *)getORSCollectionPathWithParameters:(NSDictionary *)parameters;
+ (NSString *)populateORSPath:(NSString *)path withParameters:(NSDictionary *)parameters;

// Instance-specific methods
- (id)getORSId;
- (NSString *)getORSClassIdName;
- (BOOL)createORS;
- (BOOL)createORSWithResponse:(NSError **)aError;
- (BOOL)createORSWithParameters:(NSDictionary *)parameters;
- (BOOL)createORSWithParameters:(NSDictionary *)parameters andResponse:(NSError **)aError;
- (BOOL)destroyORS;
- (BOOL)destroyORSWithResponse:(NSError **)aError;
- (BOOL)updateORS;
- (BOOL)updateORSWithResponse:(NSError **)aError;
- (BOOL)saveORS;
- (BOOL)saveORSWithResponse:(NSError **)aError;


- (BOOL)createORSAtPath:(NSString *)path withResponse:(NSError **)aError;
- (BOOL)updateORSAtPath:(NSString *)path withResponse:(NSError **)aError;
- (BOOL)destroyORSAtPath:(NSString *)path withResponse:(NSError **)aError;

// Instance helpers for getting at commonly used class-level values
- (NSString *)getORSCollectionPath;
- (NSString *)convertToORSExpectedType;

@end

0 comments on commit 42ae4f8

Please sign in to comment.