Skip to content

Commit

Permalink
Added convenience accessors on RKObjectManager for the requestCache a…
Browse files Browse the repository at this point in the history
…nd requestQueue. Cleaned up some styling and normalized method names.
  • Loading branch information
blakewatters committed Sep 6, 2011
1 parent e5ac48d commit 4299cab
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 81 deletions.
78 changes: 42 additions & 36 deletions Code/Network/RKClient.h
Expand Up @@ -120,17 +120,17 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @see RKRequestSerializable
*/
@interface RKClient : NSObject {
NSString* _baseURL;
NSString* _username;
NSString* _password;
NSString *_baseURL;
NSString *_username;
NSString *_password;
BOOL _forceBasicAuthentication;
NSMutableDictionary* _HTTPHeaders;
RKReachabilityObserver* _baseURLReachabilityObserver;
NSString* _serviceUnavailableAlertTitle;
NSString* _serviceUnavailableAlertMessage;
NSMutableDictionary *_HTTPHeaders;
RKReachabilityObserver *_baseURLReachabilityObserver;
NSString *_serviceUnavailableAlertTitle;
NSString *_serviceUnavailableAlertMessage;
BOOL _serviceUnavailableAlertEnabled;
RKRequestQueue *_requestQueue;
RKRequestCache* _cache;
RKRequestCache *_requestCache;
RKRequestCachePolicy _cachePolicy;
NSMutableSet *_additionalRootCertificates;
BOOL _disableCertificateValidation;
Expand All @@ -155,12 +155,12 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
reachability can be determined. This prevents requests dispatched immediately after
client initialization from failing to be sent.
*/
@property (nonatomic, retain) NSString* baseURL;
@property (nonatomic, retain) NSString *baseURL;

/**
* A dictionary of headers to be sent with each request
*/
@property (nonatomic, readonly) NSMutableDictionary* HTTPHeaders;
@property (nonatomic, readonly) NSMutableDictionary *HTTPHeaders;

/**
* Accept all SSL certificates. This is a potential security exposure,
Expand All @@ -175,7 +175,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
*Default*: A new request queue is instantiated for you during init
*/
@property (nonatomic, retain) RKRequestQueue* requestQueue;
@property (nonatomic, retain) RKRequestQueue *requestQueue;

/**
* Will check for network connectivity to the host specified in the baseURL
Expand All @@ -193,7 +193,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @param header The HTTP header to add
* @see HTTPHeaders
*/
- (void)setValue:(NSString*)value forHTTPHeaderField:(NSString*)header;
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)header;

/////////////////////////////////////////////////////////////////////////
/// @name SSL Validation
Expand All @@ -204,7 +204,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* A set of additional certificates to be used in evaluating server
* SSL certificates.
*/
@property(nonatomic, readonly) NSSet* additionalRootCertificates;
@property(nonatomic, readonly) NSSet *additionalRootCertificates;

/**
* Adds an additional certificate that will be used to evaluate server SSL certs
Expand All @@ -222,12 +222,12 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
/**
* The username to use for authentication via HTTP AUTH
*/
@property(nonatomic, retain) NSString* username;
@property(nonatomic, retain) NSString *username;

/**
* The password to use for authentication via HTTP AUTH
*/
@property(nonatomic, retain) NSString* password;
@property(nonatomic, retain) NSString *password;

/**
When YES, RKRequest objects dispatched through the client will have an HTTP Basic
Expand All @@ -248,7 +248,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
*
* @see RKReachabilityObserver
*/
@property(nonatomic, readonly) RKReachabilityObserver* baseURLReachabilityObserver;
@property(nonatomic, readonly) RKReachabilityObserver *baseURLReachabilityObserver;

/////////////////////////////////////////////////////////////////////////
/// @name Service Availability Alerting
Expand All @@ -260,15 +260,15 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
*
* *Default*: _"Service Unavailable"_
*/
@property(nonatomic, retain) NSString* serviceUnavailableAlertTitle;
@property(nonatomic, retain) NSString *serviceUnavailableAlertTitle;

/**
* The message to use in the alert shown when a request encounters a
* ServiceUnavailable (503) response.
*
* *Default*: _"The remote resource is unavailable. Please try again later."_
*/
@property(nonatomic, retain) NSString* serviceUnavailableAlertMessage;
@property(nonatomic, retain) NSString *serviceUnavailableAlertMessage;

/**
* Flag that determines whether the Service Unavailable alert is shown in response
Expand All @@ -286,7 +286,13 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
An instance of the request cache used to store/load cacheable responses for requests
sent through this client
*/
@property (nonatomic, retain) RKRequestCache* cache;
@property (nonatomic, retain) RKRequestCache *cache DEPRECATED_ATTRIBUTE;

/**
An instance of the request cache used to store/load cacheable responses for requests
sent through this client
*/
@property (nonatomic, retain) RKRequestCache *requestCache;

/**
The default cache policy to apply for all requests sent through this client
Expand All @@ -298,7 +304,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
/**
The path used to store response data for this client's request cache
*/
@property (nonatomic, readonly) NSString* cachePath;
@property (nonatomic, readonly) NSString *cachePath;

/////////////////////////////////////////////////////////////////////////
/// @name Shared Client Instance
Expand All @@ -307,14 +313,14 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
/**
* Return the configured singleton instance of the client
*/
+ (RKClient*)sharedClient;
+ (RKClient *)sharedClient;

/**
* Set the shared singleton issue of the client, releasing the current singleton (if any)
*
* @param client The RKClient instance to set as the new singleton
*/
+ (void)setSharedClient:(RKClient*)client;
+ (void)setSharedClient:(RKClient *)client;

/////////////////////////////////////////////////////////////////////////
/// @name Initializing a Client
Expand All @@ -327,7 +333,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @see baseURL
* @return A configured RKClient instance ready to send requests
*/
+ (RKClient*)clientWithBaseURL:(NSString*)baseURL;
+ (RKClient *)clientWithBaseURL:(NSString *)baseURL;

/**
* Return a Rest client scoped to a particular base URL with a set of HTTP AUTH credentials.
Expand All @@ -338,7 +344,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @param password The password to use for HTTP Authentication challenges
* @return A configured RKClient instance ready to send requests
*/
+ (RKClient*)clientWithBaseURL:(NSString*)baseURL username:(NSString*)username password:(NSString*)password;
+ (RKClient *)clientWithBaseURL:(NSString *)baseURL username:(NSString *)username password:(NSString *)password;

/**
* Return a client scoped to a particular base URL. If the singleton client is nil, the return client is set as the singleton
Expand All @@ -347,7 +353,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @see baseURL
* @return A configured RKClient instance ready to send requests
*/
- (id)initWithBaseURL:(NSString*)baseURL;
- (id)initWithBaseURL:(NSString *)baseURL;

/////////////////////////////////////////////////////////////////////////
/// @name Constructing Resource Paths and URLs
Expand All @@ -359,15 +365,15 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @param resourcePath The resource path to build a URL against
* @return An NSURL constructed by concatenating the baseURL and the resourcePath
*/
- (NSURL*)URLForResourcePath:(NSString*)resourcePath;
- (NSURL *)URLForResourcePath:(NSString *)resourcePath;

/**
* Returns an NSString by adding a resource path to the base URL
*
* @param resourcePath The resource path to build a URL against
* @return A string URL constructed by concatenating the baseURL and the resourcePath
*/
- (NSString*)URLPathForResourcePath:(NSString*)resourcePath;
- (NSString *)URLPathForResourcePath:(NSString *)resourcePath;

/**
* Returns a resource path with a dictionary of query parameters URL encoded and appended
Expand All @@ -385,7 +391,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @see RKPathAppendQueryParams()
* @deprecated Use RKPathAppendQueryParams instead
*/
- (NSString*)resourcePath:(NSString*)resourcePath withQueryParams:(NSDictionary*)queryParams DEPRECATED_ATTRIBUTE;
- (NSString *)resourcePath:(NSString *)resourcePath withQueryParams:(NSDictionary *)queryParams DEPRECATED_ATTRIBUTE;

/**
* Returns a NSURL by adding a resource path to the base URL and appending a URL encoded set of query parameters
Expand All @@ -400,7 +406,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @param queryParams A dictionary of query parameters to be URL encoded and appended to the resource path
* @return A URL constructed by concatenating the baseURL and the resourcePath with the query parameters appended
*/
- (NSURL*)URLForResourcePath:(NSString *)resourcePath queryParams:(NSDictionary*)queryParams;
- (NSURL *)URLForResourcePath:(NSString *)resourcePath queryParams:(NSDictionary *)queryParams;

/////////////////////////////////////////////////////////////////////////
/// @name Building Requests
Expand All @@ -414,7 +420,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @see username
* @see password
*/
- (void)setupRequest:(RKRequest*)request;
- (void)setupRequest:(RKRequest *)request;

/**
* Return a request object targetted at a resource path relative to the base URL. By default the method is set to GET
Expand All @@ -425,7 +431,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @return A fully configured RKRequest instance ready for sending
* @see RKRequestDelegate
*/
- (RKRequest*)requestWithResourcePath:(NSString*)resourcePath delegate:(NSObject<RKRequestDelegate>*)delegate;
- (RKRequest *)requestWithResourcePath:(NSString *)resourcePath delegate:(NSObject<RKRequestDelegate> *)delegate;

///////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand All @@ -444,7 +450,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @param delegate A delegate object to inform of the results
* @return The RKRequest object built and sent to the remote system
*/
- (RKRequest*)get:(NSString*)resourcePath delegate:(NSObject<RKRequestDelegate>*)delegate;
- (RKRequest *)get:(NSString *)resourcePath delegate:(NSObject<RKRequestDelegate> *)delegate;

/**
* Fetch a resource via an HTTP GET with a dictionary of params
Expand All @@ -457,7 +463,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @param delegate A delegate object to inform of the results
* @return The RKRequest object built and sent to the remote system
*/
- (RKRequest*)get:(NSString*)resourcePath queryParams:(NSDictionary*)queryParams delegate:(NSObject<RKRequestDelegate>*)delegate;
- (RKRequest *)get:(NSString *)resourcePath queryParams:(NSDictionary *)queryParams delegate:(NSObject<RKRequestDelegate> *)delegate;

/**
* Create a resource via an HTTP POST with a set of form parameters
Expand All @@ -468,7 +474,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @return The RKRequest object built and sent to the remote system
* @see RKRequestSerializable
*/
- (RKRequest*)post:(NSString*)resourcePath params:(NSObject<RKRequestSerializable>*)params delegate:(NSObject<RKRequestDelegate>*)delegate;
- (RKRequest *)post:(NSString *)resourcePath params:(NSObject<RKRequestSerializable> *)params delegate:(NSObject<RKRequestDelegate> *)delegate;

/**
* Update a resource via an HTTP PUT
Expand All @@ -479,7 +485,7 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @return The RKRequest object built and sent to the remote system
* @see RKRequestSerializable
*/
- (RKRequest*)put:(NSString*)resourcePath params:(NSObject<RKRequestSerializable>*)params delegate:(NSObject<RKRequestDelegate>*)delegate;
- (RKRequest *)put:(NSString*)resourcePath params:(NSObject<RKRequestSerializable> *)params delegate:(NSObject<RKRequestDelegate> *)delegate;

/**
* Destroy a resource via an HTTP DELETE
Expand All @@ -488,6 +494,6 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
* @param delegate A delegate object to inform of the results
* @return The RKRequest object built and sent to the remote system
*/
- (RKRequest*)delete:(NSString*)resourcePath delegate:(NSObject<RKRequestDelegate>*)delegate;
- (RKRequest *)delete:(NSString*)resourcePath delegate:(NSObject<RKRequestDelegate> *)delegate;

@end

0 comments on commit 4299cab

Please sign in to comment.