Finished split into more logical components. Library now copies Headers to Build/RestKit and you can selectively link against the components your app needs. libRestKit.a contains everything from the core library.

This commit is contained in:
Blake Watters
2010-10-01 13:02:24 -04:00
parent f06e3acb88
commit bd93d43f94
72 changed files with 1001 additions and 513 deletions

13
Code/CoreData/CoreData.h Normal file
View File

@@ -0,0 +1,13 @@
//
// CoreData.h
// RestKit
//
// Created by Blake Watters on 9/30/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import <CoreData/CoreData.h>
#import "../ObjectMapping/ObjectMapping.h"
#import "RKManagedObject.h"
#import "RKManagedObjectStore.h"
#import "RKObjectSeeder.h"

View File

@@ -7,9 +7,7 @@
//
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "RKObjectMappable.h"
#import "RKObjectManager.h"
#import "../ObjectMapping/ObjectMapping.h"
/////////////////////////////////////////////////////////////////////////////////////////////////
// RestKit managed models

View File

@@ -1,23 +1,22 @@
//
// RKModelSeeder.h
// RKObjectSeeder.h
// RestKit
//
// Created by Blake Watters on 3/4/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RKObjectManager.h"
#import "../ObjectMapping/ObjectMapping.h"
// TODO: This class needs an API scrubbing
// TODO: Really only needs to be initialized with mapper, not the manager... ?
@interface RKObjectSeeder : NSObject {
RKObjectManager* _manager;
}
/**
* Initialize a new model seeder
* Initialize a new object seeder
*/
- (id)initWithResourceManager:(RKObjectManager*)manager;
- (id)initWithObjectManager:(RKObjectManager*)manager;
/**
* Read a file from the main bundle and seed the database with its contents.
@@ -25,6 +24,9 @@
*/
- (NSArray*)seedDatabaseWithBundledFile:(NSString*)fileName ofType:(NSString*)type;
/**
* Seeds the database with an array of files of the specified type
*/
- (void)seedDatabaseWithBundledFiles:(NSArray*)fileNames ofType:(NSString*)type;
/**

View File

@@ -10,7 +10,7 @@
@implementation RKObjectSeeder
- (id)initWithResourceManager:(RKObjectManager*)manager {
- (id)initWithObjectManager:(RKObjectManager*)manager {
if (self = [self init]) {
_manager = [manager retain];
}

12
Code/Network/Network.h Normal file
View File

@@ -0,0 +1,12 @@
//
// Network.h
// RestKit
//
// Created by Blake Watters on 9/30/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RKClient.h"
#import "RKRequest.h"
#import "RKResponse.h"
#import "RKRequestSerializable.h"

View File

@@ -6,10 +6,10 @@
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "RestKit/RKRequest.h"
#import "RestKit/RKResponse.h"
#import "RestKit/NSDictionary+RKRequestSerialization.h"
#import "RestKit/RKNotifications.h"
#import "RKRequest.h"
#import "RKResponse.h"
#import "NSDictionary+RKRequestSerialization.h"
#import "RKNotifications.h"
@implementation RKRequest

View File

@@ -8,7 +8,7 @@
#import "RKResponse.h"
#import "RKNotifications.h"
#import "RKMappingFormatJSONParser.h"
#import "RKJSONParser.h"
@implementation RKResponse
@@ -111,7 +111,7 @@
}
- (id)bodyAsJSON {
return [[[[RKMappingFormatJSONParser alloc] init] autorelease] objectFromString:[self bodyAsString]];
return [[[[RKJSONParser alloc] init] autorelease] objectFromString:[self bodyAsString]];
}
- (NSString*)failureErrorDescription {

View File

@@ -0,0 +1,11 @@
//
// ObjectMapping.h
// RestKit
//
// Created by Blake Watters on 9/30/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RKObjectManager.h"
#import "RKObject.h"
#import "RKObjectLoader.h"

View File

@@ -8,8 +8,7 @@
// TODO: Factor core data out...
#import <CoreData/CoreData.h>
#import "RKRequest.h"
#import "RKResponse.h"
#import "../Network/Network.h"
#import "RKObjectMapper.h"
@class RKObjectLoader;

View File

@@ -8,7 +8,6 @@
#import <CoreData/CoreData.h>
#import "RKObjectLoader.h"
#import "RKResponse.h"
#import "RKObjectManager.h"
#import "Errors.h"
#import "RKManagedObject.h"

View File

@@ -6,16 +6,19 @@
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "RKClient.h"
#import "../Network/Network.h"
#import "RKObjectMapper.h"
#import "RKObjectLoader.h"
#import "RKStaticRouter.h"
#import "RKManagedObjectStore.h"
// Notifications
extern NSString* const RKDidEnterOfflineModeNotification;
extern NSString* const RKDidEnterOnlineModeNotification;
// TODO: Factor out into a protocol...
// insertObject:, deleteObject:, save, etc.
@class RKManagedObjectStore;
@interface RKObjectManager : NSObject {
RKClient* _client;
RKMappingFormat _format;

View File

@@ -7,8 +7,6 @@
*
*/
#import "RKRequest.h"
/**
* Must be implemented by all classes utilizing the RKModelMapper to map REST
* responses to domain model classes

View File

@@ -9,31 +9,16 @@
#import <Foundation/Foundation.h>
#import "RKObjectMappable.h"
#import "RKObjectPropertyInspector.h"
#import "../Support/RKParser.h"
/**
* Define the resource mapping formats
* Define the object mapping formats
*/
typedef enum {
RKMappingFormatXML = 0,
RKMappingFormatJSON
} RKMappingFormat;
/**
* The format parser is responsible for transforming a string
* of data into a dictionary. This allows the model mapper to
* map properties using key-value coding
*/
@protocol RKMappingFormatParser
/**
* Return a key-value coding compliant representation of a payload.
* Object attributes are encoded as a dictionary and collections
* of objects are returned as arrays.
*/
- (id)objectFromString:(NSString*)string;
@end
@interface RKObjectMapper : NSObject {
NSMutableDictionary* _elementToClassMappings;
RKMappingFormat _format;
@@ -117,8 +102,15 @@ typedef enum {
///////////////////////////////////////////////////////////////////////////////
// Non-element based object mapping
- (id)parseString:(NSString*)string;
/**
* Map the objects in a given payload string to a particular object class
*/
- (id)mapFromString:(NSString *)string toClass:(Class)class;
/**
* Map an array of object dictionary representations to instances of a particular
* object class
*/
- (NSArray*)mapObjectsFromArrayOfDictionaries:(NSArray*)array toClass:(Class)class;
@end

View File

@@ -7,10 +7,12 @@
//
#import <objc/message.h>
// TODO: Factor out Core Data...
#import <CoreData/CoreData.h>
#import "RKObjectMapper.h"
#import "NSDictionary+RKAdditions.h"
#import "RKMappingFormatJSONParser.h"
#import "RKJSONParser.h"
// Default format string for date and time objects from Rails
// TODO: Rails specifics should probably move elsewhere...
@@ -20,6 +22,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
@interface RKObjectMapper (Private)
- (id)parseString:(NSString*)string;
- (void)updateModel:(id)model fromElements:(NSDictionary*)elements;
- (Class)typeClassForProperty:(NSString*)property ofClass:(Class)class;
@@ -83,10 +86,10 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
- (id)parseString:(NSString*)string {
NSMutableDictionary* threadDictionary = [[NSThread currentThread] threadDictionary];
NSObject<RKMappingFormatParser>* parser = [threadDictionary objectForKey:kRKModelMapperMappingFormatParserKey];
NSObject<RKParser>* parser = [threadDictionary objectForKey:kRKModelMapperMappingFormatParserKey];
if (!parser) {
if (_format == RKMappingFormatJSON) {
parser = [[RKMappingFormatJSONParser alloc] init];
parser = [[RKJSONParser alloc] init];
[threadDictionary setObject:parser forKey:kRKModelMapperMappingFormatParserKey];
[parser release];
}

View File

@@ -6,9 +6,8 @@
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RKRequest.h"
#import "../Network/Network.h"
#import "RKObjectMappable.h"
#import "RKRequestSerializable.h"
/**
* Defines a protocol for mapping Cocoa objects to remote resource locations and

View File

@@ -1,37 +0,0 @@
//
// RKMappingFormatJSONParser+SBJSON.m
// RestKit
//
// Created by Blake Watters on 3/4/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RKMappingFormatJSONParser.h"
#import "SBJsonParser.h"
@implementation RKMappingFormatJSONParser
- (id)init {
if (self = [super init]) {
_parser = [[SBJsonParser alloc] init];
}
return self;
}
- (void)dealloc {
[_parser release];
[super dealloc];
}
- (NSDictionary*)objectFromString:(NSString*)string {
id result = [_parser objectWithString:string];
if (nil == result) {
// TODO: Need to surface these errors in a better fashion
NSLog(@"[RestKit] RKMappingFormatJSONParser: Parser failed with error trace: %@ and string: %@", [(SBJsonParser*)_parser errorTrace], string);
}
return result;
}
@end

20
Code/RestKit.h Normal file
View File

@@ -0,0 +1,20 @@
//
// RestKit.h
// RestKit
//
// Created by Blake Watters on 2/19/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "Network/Network.h"
#import "Support/Support.h"
#import "ObjectMapping/ObjectMapping.h"
//#import "RestKit/RKClient.h"
//#import "RestKit/Errors.h"
//#import "RestKit/RKObjectManager.h"
//#import "RestKit/RKObject.h"
//#import "RestKit/RKManagedObject.h"
//#import "RestKit/RKNotifications.h"
//#import "RestKit/RKObjectSeeder.h"
//#import "RestKit/NSDictionary+RKAdditions.h"

9
Code/RestKit.m Normal file
View File

@@ -0,0 +1,9 @@
//
// RestKit.m
// RestKit
//
// Created by Blake Watters on 9/30/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
// This file is here only to cause XCode to link libRestKit.a

View File

@@ -1,16 +0,0 @@
//
// RestKit.h
// RestKit
//
// Created by Blake Watters on 2/19/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RestKit/RKClient.h"
#import "RestKit/Errors.h"
#import "RestKit/RKObjectManager.h"
#import "RestKit/RKObject.h"
#import "RestKit/RKManagedObject.h"
#import "RestKit/RKNotifications.h"
#import "RestKit/RKObjectSeeder.h"
#import "RestKit/NSDictionary+RKAdditions.h"

View File

@@ -0,0 +1,26 @@
//
// RKJSONParser+SBJSON.m
// RestKit
//
// Created by Blake Watters on 3/4/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RKJSONParser.h"
#import "SBJsonParser.h"
@implementation RKJSONParser
- (NSDictionary*)objectFromString:(NSString*)string {
SBJsonParser* parser = [[SBJsonParser alloc] init];
id result = [parser objectWithString:string];
[parser release];
if (nil == result) {
// TODO: Need to surface these errors in a better fashion
NSLog(@"[RestKit] RKMappingFormatJSONParser: Parser failed with error trace: %@ and string: %@", [parser errorTrace], string);
}
return result;
}
@end

View File

@@ -6,10 +6,10 @@
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RKMappingFormatJSONParser.h"
#import "RKJSONParser.h"
#import "YAJL.h"
@implementation RKMappingFormatJSONParser
@implementation RKJSONParser
- (NSDictionary*)objectFromString:(NSString*)string {
return [string yajl_JSON];

View File

@@ -6,10 +6,9 @@
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "RKObjectMapper.h"
#import "RKParser.h"
@interface RKMappingFormatJSONParser : NSObject <RKMappingFormatParser> {
id _parser;
@interface RKJSONParser : NSObject <RKParser> {
}
@end

23
Code/Support/RKParser.h Normal file
View File

@@ -0,0 +1,23 @@
//
// RKParser.h
// RestKit
//
// Created by Blake Watters on 10/1/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
/**
* A Parser is responsible for transforming a string
* of data into a dictionary. This allows the model mapper to
* map properties using key-value coding
*/
@protocol RKParser
/**
* Return a key-value coding compliant representation of a payload.
* Object attributes are encoded as a dictionary and collections
* of objects are returned as arrays.
*/
- (id)objectFromString:(NSString*)string;
@end

10
Code/Support/Support.h Normal file
View File

@@ -0,0 +1,10 @@
//
// Support.h
// RestKit
//
// Created by Blake Watters on 9/30/10.
// Copyright 2010 Two Toasters. All rights reserved.
//
#import "Errors.h"
#import "NSDictionary+RKAdditions.h"

View File

@@ -7,7 +7,7 @@
//
#import <Three20/Three20.h>
#import <RestKit/RestKit.h>
#import "RestKit.h"
#import "RKRequestModel.h"
/**

File diff suppressed because it is too large Load Diff

11
Scripts/Protect.command Normal file
View File

@@ -0,0 +1,11 @@
# Protect the copied header files from being modified. This is done in an attempt to avoid
# accidentally editing the copied headers.
# Ignore whitespace characters in paths
IFS=$'\n'
cd ${CONFIGURATION_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}
find * -name '*.h' | xargs chmod a-w
exit 0

14
TODO Normal file
View File

@@ -0,0 +1,14 @@
- Update README to reflect new realities
- Clean up CoreData mess
- Sample apps
- Doxygen markup & generation
- Request Queue
- Network Watcher
- Clean up specs
- Factor out Rails support
- RKObjectMapperDelegate
- extract error from the payload
- digest the payload to return objects at arbitrary KVC paths
- RKRailsObjectMapperDelegate
- Dynamic Router (interpolate property values into paths)
- Three20 Integration Cleanup