Introduced RKMakeURL and RKMakeURLPath convenience methods for generating NSURL and NSString URL's quickly against the sharedClient's base URL. This can be useful if you have some web content in your app that loads off of sub-paths and want the convenience & flexibility of working off of resourcePath's instead of full URL's.

This commit is contained in:
Blake Watters
2011-01-03 12:49:31 -05:00
parent 058e55242c
commit f1db54c156
2 changed files with 44 additions and 0 deletions

View File

@@ -12,6 +12,30 @@
#import "NSDictionary+RKRequestSerialization.h"
#import "RKReachabilityObserver.h"
/////////////////////////////////////////////////////////////////////////
/**
* URL & URL Path Convenience methods
*/
/**
* Returns an NSURL with the specified resource path appended to the base URL
* that the shared RKClient instance is configured with
*
* Shortcut for calling [[RKClient sharedClient] URLForResourcePath:@"/some/path"]
*/
NSURL* RKMakeURL(NSString* resourcePath);
/**
* Returns an NSString with the specified resource path appended to the base URL
* that the shared RKClient instance is configured with
*
* Shortcut for calling [[RKClient sharedClient] URLPathForResourcePath:@"/some/path"]
*/
NSString* RKMakeURLPath(NSString* resourcePath);
/////////////////////////////////////////////////////////////////////////
/**
* RKClient exposes the low level client interface for working
* with HTTP servers and RESTful services. It wraps the request/response
@@ -98,6 +122,11 @@
*/
- (NSURL*)URLForResourcePath:(NSString*)resourcePath;
/**
* Returns an NSString by adding a resource path to the base URL
*/
- (NSString*)URLPathForResourcePath:(NSString*)resourcePath;
/**
* Returns a NSURL by adding a resource path to the base URL and appending a URL encoded set of query parameters
*/

View File

@@ -16,6 +16,17 @@
static RKClient* sharedClient = nil;
///////////////////////////////////////////////////////////////////////////////////////////////////
// URL Conveniences functions
NSURL* RKMakeURL(NSString* resourcePath) {
return [[RKClient sharedClient] URLForResourcePath:resourcePath];
}
NSString* RKMakeURLPath(NSString* resourcePath) {
return [[RKClient sharedClient] URLPathForResourcePath:resourcePath];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation RKClient
@@ -99,6 +110,10 @@ static RKClient* sharedClient = nil;
return [RKURL URLWithBaseURLString:self.baseURL resourcePath:resourcePath];
}
- (NSString*)URLPathForResourcePath:(NSString*)resourcePath {
return [[self URLForResourcePath:resourcePath] absoluteString];
}
- (NSURL*)URLForResourcePath:(NSString *)resourcePath queryParams:(NSDictionary*)queryParams {
return [self URLForResourcePath:[self resourcePath:resourcePath withQueryParams:queryParams]];
}