mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-22 20:18:53 +08:00
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:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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]];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user