Resource Path -> Path

This commit is contained in:
Blake Watters
2012-09-04 21:24:33 -04:00
parent d31b7a13c2
commit 627f6f5b7b
19 changed files with 177 additions and 210 deletions

View File

@@ -159,7 +159,7 @@
if (! localObjects) return NO;
for (id object in localObjects) {
if (NO == [results containsObject:object]) {
RKLogDebug(@"Deleting orphaned object %@: not found in result set and expected at this resource path", object);
RKLogDebug(@"Deleting orphaned object %@: not found in result set and expected at this URL", object);
[self.privateContext performBlockAndWait:^{
[self.privateContext deleteObject:object];
}];

View File

@@ -85,7 +85,7 @@ RKMappingResult, RKRequestDescriptor, RKResponseDescriptor;
<h4>Configuring Routes</h4>
Routing is the process of transforming objects and actions (as defined by HTTP verbs) into resource paths. RestKit ships
Routing is the process of transforming objects and actions (as defined by HTTP verbs) into paths. RestKit ships
<h4>Initializing a Core Data Object Store</h4>
<h3>Loading Remote Objects</h3>
@@ -185,16 +185,16 @@ RKMappingResult, RKRequestDescriptor, RKResponseDescriptor;
/// @name Building Object Request Operations
/**
Creates and returns an RKObjectPaginator instance targeting the specified resource path pattern.
Creates and returns an RKObjectPaginator instance targeting the specified path pattern.
The paginator instantiated will be initialized with an RKURL built by appending the resourcePathPattern to the
The paginator instantiated will be initialized with a URL built by appending the pathPattern to the
baseURL of the client.
@return The newly created paginator instance.
@see RKObjectMappingProvider
@see RKObjectPaginator
*/
//- (RKObjectPaginator *)paginatorWithResourcePathPattern:(NSString *)resourcePathPattern;
//- (RKObjectPaginator *)paginatorWithPathPattern:(NSString *)pathPattern;
////////////////////////////////////////////////////////
/// @name Registered Object Loaders
@@ -295,6 +295,7 @@ RKMappingResult, RKRequestDescriptor, RKResponseDescriptor;
- (void)addResponseDescriptorsFromArray:(NSArray *)responseDescriptors;
- (void)removeResponseDescriptor:(RKResponseDescriptor *)responseDescriptor;
// Moves to RKObjectManager+CoreData
@property (nonatomic, readonly) NSArray *fetchRequestBlocks;
- (void)addFetchRequestBlock:(RKFetchRequestBlock)block;

View File

@@ -188,7 +188,7 @@ static NSOperationQueue *defaultMappingQueue = nil;
/////////////////////////////////////////////////////////////
#pragma mark - Object Collection Loaders
//- (RKObjectPaginator *)paginatorWithResourcePathPattern:(NSString *)resourcePathPattern
//- (RKObjectPaginator *)paginatorWithPathPattern:(NSString *)pathPattern
//{
// RKURL *patternURL = [[self baseURL] URLByAppendingResourcePath:resourcePathPattern];
// RKObjectPaginator *paginator = [RKObjectPaginator paginatorWithPatternURL:patternURL

View File

@@ -60,19 +60,19 @@
//- (id)initWithPatternURL:(RKURL *)patternURL mappingProvider:(RKObjectMappingProvider *)mappingProvider;
//
///**
// A RKURL with a resource path pattern for building a complete URL from
// A RKURL with a path pattern for building a complete URL from
// which to load the paginated resource collection. The patterned resource
// path will be evaluated against the state of the paginator object itself.
//
// For example, given a paginated collection of data at the /articles resource path,
// the patterned resource path may look like:
// For example, given a paginated collection of data at the /articles path,
// the path pattern may look like:
//
// /articles?per_page=:perPage&page_number=:currentPage
//
// When the pattern is evaluated against the state of the paginator, this will
// yield a complete resource path that can be used to load the specified page. Given
// yield a complete path that can be used to load the specified page. Given
// a paginator configured with 100 objects per page and a current page number of 3,
// the resource path of the pagination URL would become:
// the path portion of the pagination URL would become:
//
// /articles?per_page=100&page_number=3
//

View File

@@ -21,23 +21,23 @@
#import "RKHTTPUtilities.h"
/**
The RKRoute class models a single routable resource path pattern in use by the application. A route
can be combined with an RKURL base URL and interpolated with an object to produce a new fully hydrated
URL object. Routes are always instantiated with a resource path pattern and metadata to provide for
The RKRoute class models a single routable path pattern in use by the application. A route
can be combined with an NSURL base URL and interpolated with an object to produce a new fully hydrated
URL object. Routes are always instantiated with a path pattern and metadata to provide for
the subsequent identification of the defined route.
There are three types of routes modeled by the RKRoute class:
1. Named Routes: A named route represents a single resource path and optional request method within
1. Named Routes: A named route represents a single path and optional request method within
the application. The route is not affiliated with any particular class. For example, one might
define a route with the name `@"airlines_list"` as a GET to /airlines.json
1. Class Routes: An class route represents a single resource path that is identified by object class
define a route with the name `@"airlines_list"` as a GET to the path '/airlines.json'.
1. Class Routes: An class route represents a single path that is identified by object class
and request method for which it is appropriate. For example, one might define a route for the class
`RKArticle` for a POST to /articles.json.
1. Relationship Routes: A relationship route represents a single resource path through which the relationship
`RKArticle` for a POST to the path '/articles.json'.
1. Relationship Routes: A relationship route represents a single path through which the relationship
of a parent object can be manipulated. For example, given an `RKArticle` and `RKComment` class, one
might define a relationship route for the `RKArticle` class's `@"comments"` relationship as pointing to
a GET to `@"/articles/:articleID/comments".
a GET to the path `@"/articles/:articleID/comments".
The RKRoute class is internally implemented as a class cluster and is not to be directly instantiated via alloc and
init.
@@ -70,55 +70,55 @@
@property (nonatomic, assign, readonly) RKRequestMethod method;
/**
The resource path pattern of the receiver.
The path pattern of the receiver.
A SOCKit pattern that describes the resource path of the route. Required and used by all route types.
A SOCKit pattern that describes the format of the path portion of URL's generated from the receiver. Required and used by all route types.
@see SOCPattern
*/
@property (nonatomic, strong, readonly) NSString *resourcePathPattern;
@property (nonatomic, strong, readonly) NSString *pathPattern;
/**
A Boolean value that determines if the resource path pattern should be escaped when evaluated.
A Boolean value that determines if the path pattern should be escaped when evaluated.
*Default*: NO
*/
@property (nonatomic, assign) BOOL shouldEscapeResourcePath;
@property (nonatomic, assign) BOOL shouldEscapePath;
///-----------------------------------------------------------------------------
/// @name Instantiating Routes
///-----------------------------------------------------------------------------
/**
Creates and returns a new named route object with the given name, resource path pattern and method.
Creates and returns a new named route object with the given name, path pattern and method.
@param name A unique identifying name for the route.
@param resourcePathPattern A SOCKit pattern describing the resource path represented by the route.
@param pathPattern A SOCKit pattern describing the format of URL paths generated from the route.
@param method The request method of the route.
@return A new named route object with the given name, resource path pattern and request method.
@return A new named route object with the given name, path pattern and request method.
*/
+ (id)routeWithName:(NSString *)name resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method;
+ (id)routeWithName:(NSString *)name pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method;
/**
Creates and returns a new class route object with the given object class, resource path pattern and method.
Creates and returns a new class route object with the given object class, path pattern and method.
@param objectClass The class that is represented by the route.
@param resourcePathPattern A SOCKit pattern describing the resource path represented by the route.
@param pathPattern A SOCKit pattern describing the format of URL paths generated from the route.
@param method The request method of the route.
@return A new class route object with the given object class, resource path pattern and request method.
@return A new class route object with the given object class, path pattern and request method.
*/
+ (id)routeWithClass:(Class)objectClass resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method;
+ (id)routeWithClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method;
/**
Creates and returns a new relationship route object with the given relationship name, object class, resource path pattern and method.
Creates and returns a new relationship route object with the given relationship name, object class, path pattern and method.
@param relationshipName The name of the relationship represented by the route.
@param objectClass The class containing the relationship represented by the route.
@param resourcePathPattern A SOCKit pattern describing the resource path represented by the route.
@param pathPattern A SOCKit pattern describing the format of URL paths generated from the route.
@param method The request method of the route.
@return A new class route object with the given object class, resource path pattern and request method.
@return A new class route object with the given object class, path pattern and request method.
*/
+ (id)routeWithRelationshipName:(NSString *)name objectClass:(Class)objectClass resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method;
+ (id)routeWithRelationshipName:(NSString *)name objectClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method;
///-----------------------------------------------------------------------------
/// @name Inspecting Route Types

View File

@@ -24,7 +24,7 @@
@property (nonatomic, strong, readwrite) NSString *name;
@property (nonatomic, strong, readwrite) Class objectClass;
@property (nonatomic, assign, readwrite) RKRequestMethod method;
@property (nonatomic, strong, readwrite) NSString *resourcePathPattern;
@property (nonatomic, strong, readwrite) NSString *pathPattern;
@end
@interface RKNamedRoute : RKRoute
@@ -39,36 +39,37 @@
@implementation RKRoute
+ (id)routeWithName:(NSString *)name resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method
+ (id)routeWithName:(NSString *)name pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method
{
NSParameterAssert(name);
NSParameterAssert(resourcePathPattern);
NSParameterAssert(pathPattern);
RKNamedRoute *route = [RKNamedRoute new];
route.name = name;
route.resourcePathPattern = resourcePathPattern;
route.pathPattern = pathPattern;
route.method = method;
return route;
}
+ (id)routeWithClass:(Class)objectClass resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method
+ (id)routeWithClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method
{
NSParameterAssert(objectClass);
NSParameterAssert(resourcePathPattern);
NSParameterAssert(pathPattern);
RKClassRoute *route = [RKClassRoute new];
route.objectClass = objectClass;
route.resourcePathPattern = resourcePathPattern;
route.pathPattern = pathPattern;
route.method = method;
return route;
}
+ (id)routeWithRelationshipName:(NSString *)relationshipName objectClass:(Class)objectClass resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method
+ (id)routeWithRelationshipName:(NSString *)relationshipName objectClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method
{
NSParameterAssert(relationshipName);
NSParameterAssert(objectClass);
NSParameterAssert(pathPattern);
RKRelationshipRoute *route = [RKRelationshipRoute new];
route.name = relationshipName;
route.objectClass = objectClass;
route.resourcePathPattern = resourcePathPattern;
route.pathPattern = pathPattern;
route.method = method;
return route;
}
@@ -114,8 +115,8 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p name=%@ method=%@ resourcePathPattern=%@>",
NSStringFromClass([self class]), self, self.name, RKStringFromRequestMethod(self.method), self.resourcePathPattern];
return [NSString stringWithFormat:@"<%@: %p name=%@ method=%@ pathPattern=%@>",
NSStringFromClass([self class]), self, self.name, RKStringFromRequestMethod(self.method), self.pathPattern];
}
@end
@@ -129,9 +130,9 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p objectClass=%@ method=%@ resourcePathPattern=%@>",
return [NSString stringWithFormat:@"<%@: %p objectClass=%@ method=%@ pathPattern=%@>",
NSStringFromClass([self class]), self, NSStringFromClass(self.objectClass),
RKStringFromRequestMethod(self.method), self.resourcePathPattern];
RKStringFromRequestMethod(self.method), self.pathPattern];
}
@end
@@ -145,9 +146,9 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p relationshipName=%@ objectClass=%@ method=%@ resourcePathPattern=%@>",
return [NSString stringWithFormat:@"<%@: %p relationshipName=%@ objectClass=%@ method=%@ pathPattern=%@>",
NSStringFromClass([self class]), self, self.name, NSStringFromClass(self.objectClass),
RKStringFromRequestMethod(self.method), self.resourcePathPattern];
RKStringFromRequestMethod(self.method), self.pathPattern];
}
@end

View File

@@ -159,12 +159,4 @@ extern RKRequestMethod const RKRequestMethodAny;
*/
- (RKRoute *)routeForObject:(id)object method:(RKRequestMethod)method;
/**
Retrieves all routes with a given resource path pattern.
@param resourcePathPattern The resource path pattern of the routes to be retrieved.
@return An array containing all routes with a resource path pattern equal to the given value.
*/
- (NSArray *)routesWithResourcePathPattern:(NSString *)resourcePathPattern;
@end

View File

@@ -196,16 +196,4 @@ RKRequestMethod const RKRequestMethodAny = RKRequestMethodInvalid;
return nil;
}
- (NSArray *)routesWithResourcePathPattern:(NSString *)resourcePathPattern
{
NSMutableArray *routes = [NSMutableArray array];
for (RKRoute *route in self.routes) {
if ([route.resourcePathPattern isEqualToString:resourcePathPattern]) {
[routes addObject:route];
}
}
return [NSArray arrayWithArray:routes];
}
@end

View File

@@ -28,13 +28,13 @@
that are used by the application.
URL's can be generated by the router in three ways:
1. By name. Named routes link a symbolic name with a resource path and an HTTP request method.
1. By name. Named routes link a symbolic name with a path and an HTTP request method.
2. By object. Routes can be defined by class and HTTP request method. When a URL is requested from the
router for an object, the router will identify the most appropriate route for the object
and instantiate an RKURL with the route's resource path pattern and interpolate it against the object.
and instantiate an RKURL with the route's path pattern and interpolate it against the object.
3. By object relationship. Routes can be defined for relationships to other objects. When a URL is requested
from the router for a relationship, the router will retrieve the appropriate route for the relationship
from the route set and interpolate the route's resource path pattern against the source object.
from the route set and interpolate the route's path pattern against the source object.
@see RKURL
@see RKRoute
@@ -72,15 +72,15 @@
Generates a URL for the route with the given name.
The route set is searched for a route with the given name and a new RKURL object is instantiated
with the baseURL of the receiver and the resource path pattern of the route, optionally interpolated
with the baseURL of the receiver and the path pattern of the route, optionally interpolated
with a given object. If a pointer to an RKRequestMethod variable is provided, the HTTP method
for the route will be assigned to the reference.
@param routeName The name of the route for which a URL is to be generated.
@param method A pointer to an RKRequestMethod variable in which to store the HTTP method associated
with the named route.
@param object An optional object against which to interpolate the resource path pattern.
@return A new URL object constructed by appending the resource path pattern to the baseURL of the
@param object An optional object against which to interpolate the path pattern.
@return A new URL object constructed by appending the path pattern to the baseURL of the
receiver and interpolating against a given object; or nil if no route was found with the given
name.
*/
@@ -93,12 +93,12 @@
the object being routed. If there is not an exact match for the object's class, the inheritance
hierarchy is searched until a match is found or all possible routes are exhausted. Exact HTTP request
matches are favored over the wildcard method (RKRequestMethodAny). Once the appropriate route is identified,
a new RKURL object is instantiated with the baseURL of the receiver and the resource path pattern of the route,
a new RKURL object is instantiated with the baseURL of the receiver and the path pattern of the route,
interpolated against the object being routed.
@param object The object for which a URL is to be generated.
@param method The HTTP method for which the URL is to be generated.
@return A new URL object constructed by appending the resource path pattern of the route for the object and
@return A new URL object constructed by appending the path pattern of the route for the object and
HTTP method to the baseURL of the receiver, interpolated against the routed object; or nil if no route was found
for the given object and HTTP method.
*/
@@ -109,12 +109,12 @@
The route set is searched for a route that matches the relationship of the given object's class and the given
HTTP method. If a matching route is found, a new RKURL object is instantiated with the baseURL of the receiver
and the resource path pattern of the route, interpolated against the object being routed.
and the path pattern of the route, interpolated against the object being routed.
@param relationshipName The name of the relationship for which a URL is to be generated.
@param object The object for which the URL is to be generated.
@param method The HTTP method for which the URL is to be generated.
@return A new URL object constructed by appending the resource path pattern of the route for the given object's
@return A new URL object constructed by appending the path pattern of the route for the given object's
relationship and HTTP method to the baseURL of the receiver, interpolated against the routed object; or nil if no
route was found for the given relationship, object and HTTP method.
*/

View File

@@ -70,9 +70,9 @@
- (NSString *)pathFromRoute:(RKRoute *)route forObject:(id)object
{
if (! object) return route.resourcePathPattern;
RKPathMatcher *pathMatcher = [RKPathMatcher matcherWithPattern:route.resourcePathPattern];
return [pathMatcher pathFromObject:object addingEscapes:route.shouldEscapeResourcePath];
if (! object) return route.pathPattern;
RKPathMatcher *pathMatcher = [RKPathMatcher matcherWithPattern:route.pathPattern];
return [pathMatcher pathFromObject:object addingEscapes:route.shouldEscapePath];
}
@end