Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved URL initialization from service to request
  • Loading branch information
ivasic committed Apr 6, 2011
1 parent b0b2787 commit 330bc79
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 40 deletions.
15 changes: 11 additions & 4 deletions RESTframework/RESTframework/RESTclasses/RESTRequest.h
Expand Up @@ -27,8 +27,15 @@ typedef enum {
NSMutableDictionary* params;
NSMutableDictionary* files;
NSUInteger tag;
NSURL* serviceEndpoint;
}

/*!
* @property serviceEndpoint
* @abstract URL pointing to the base of RESTful service
*/
@property (retain) NSURL* serviceEndpoint;

@property RESTRequestType type;
@property RESTRequestBodyType bodyType;
@property (readonly) NSString* requestType;
Expand All @@ -37,11 +44,11 @@ typedef enum {
@property (readonly) BOOL hasFiles;
@property NSUInteger tag;

-(id) initWithType:(RESTRequestType)t resourcePath:(NSArray*)path;
-(id) initWithType:(RESTRequestType)t resourcePath:(NSArray*)path bodyType:(RESTRequestBodyType)bt;
-(id) initWithURL:(NSURL*)url type:(RESTRequestType)t resourcePath:(NSArray*)path;
-(id) initWithURL:(NSURL*)url type:(RESTRequestType)t resourcePath:(NSArray*)path bodyType:(RESTRequestBodyType)bt;

+(id) requestWithType:(RESTRequestType)t resourcePath:(NSArray*)path;
+(id) requestWithType:(RESTRequestType)t resourcePath:(NSArray*)path bodyType:(RESTRequestBodyType)bt;
+(id) requestWithURL:(NSURL*)url type:(RESTRequestType)t resourcePath:(NSArray*)path;
+(id) requestWithURL:(NSURL*)url type:(RESTRequestType)t resourcePath:(NSArray*)path bodyType:(RESTRequestBodyType)bt;

-(void) addParam:(NSString*)value forKey:(NSString*)key;
-(void) addFile:(NSData*)data withContentType:(NSString*)ct forKey:(NSString*)key;
Expand Down
21 changes: 11 additions & 10 deletions RESTframework/RESTframework/RESTclasses/RESTRequest.m
Expand Up @@ -6,7 +6,6 @@
//

#import "RESTRequest.h"
#import "RESTConf.h"
#import "JSONKit.h"

#define GS_POST_BOUNDARY @"----------ThIs_Is_tHe_bouNdaRY_$"
Expand All @@ -17,7 +16,7 @@ @interface RESTRequest ()
@end

@implementation RESTRequest
@synthesize type, resourcePath, requestType, bodyType, params, files, tag;
@synthesize type, resourcePath, serviceEndpoint, requestType, bodyType, params, files, tag;

#pragma mark -
#pragma mark Properties
Expand All @@ -36,12 +35,12 @@ -(BOOL) hasFiles {

#pragma mark - Initialization

-(id) initWithType:(RESTRequestType)t resourcePath:(NSArray*)path
-(id) initWithURL:(NSURL*)url type:(RESTRequestType)t resourcePath:(NSArray*)path
{
return [self initWithType:t resourcePath:path bodyType:RESTRequestBodyTypeFormUrlEncoded];
return [self initWithURL:url type:t resourcePath:path bodyType:RESTRequestBodyTypeFormUrlEncoded];
}

-(id) initWithType:(RESTRequestType)t resourcePath:(NSArray*)path bodyType:(RESTRequestBodyType)bt
-(id) initWithURL:(NSURL*)url type:(RESTRequestType)t resourcePath:(NSArray*)path bodyType:(RESTRequestBodyType)bt
{
if ((self = [super init])) {
self.type = t;
Expand All @@ -51,17 +50,19 @@ -(id) initWithType:(RESTRequestType)t resourcePath:(NSArray*)path bodyType:(REST
return self;
}

+(id) requestWithType:(RESTRequestType)t resourcePath:(NSArray*)path
+(id) requestWithURL:(NSURL*)url type:(RESTRequestType)t resourcePath:(NSArray*)path
{
return [[[RESTRequest alloc] initWithType:t resourcePath:path] autorelease];
return [[[RESTRequest alloc] initWithURL:url type:t resourcePath:path] autorelease];
}

+(id) requestWithType:(RESTRequestType)t resourcePath:(NSArray*)path bodyType:(RESTRequestBodyType)bt
+(id) requestWithURL:(NSURL*)url type:(RESTRequestType)t resourcePath:(NSArray*)path bodyType:(RESTRequestBodyType)bt
{
return [[[RESTRequest alloc] initWithType:t resourcePath:path bodyType:bt] autorelease];
return [[[RESTRequest alloc] initWithURL:url type:t resourcePath:path bodyType:bt] autorelease];
}

-(void) dealloc {
[serviceEndpoint release];
serviceEndpoint = nil;
self.params = nil;
self.files = nil;
self.resourcePath = nil;
Expand Down Expand Up @@ -162,7 +163,7 @@ -(NSString*) contentType {

-(NSURLRequest*) getUrlRequest {
NSString* urlString = [NSString stringWithFormat:@"%@%@",
ENDPOINT_URL, [self resourcePathString]];
self.serviceEndpoint, [self resourcePathString]];

//We need to alter URL if it's a GET req..
if (self.type == RESTRequestTypeGet && self.hasParams) {
Expand Down
14 changes: 0 additions & 14 deletions RESTframework/RESTframework/RESTclasses/RESTSvc.h
Expand Up @@ -14,7 +14,6 @@
@interface RESTSvc : NSObject {

id<RESTSvcDelegate> delegate;
NSURL* serviceEndpoint;

@private
NSURLConnection* urlConnection;
Expand All @@ -32,12 +31,6 @@
*/
@property (assign) id<RESTSvcDelegate> delegate;

/*!
* @property serviceEndpoint
* @abstract URL pointing to the base of RESTful service
*/
@property (retain) NSURL* serviceEndpoint;

/*!
* @method execRequest:
* @abstract Adds the request to the queue for execution and executes it when the time comes
Expand All @@ -59,13 +52,6 @@
*/
-(BOOL) hasRequestWithTag:(NSUInteger)tag;

/*
* @method initWithEndpointURL:
* @abstract Initializes the service with the enpoint URL
* @param tag NSUInteger value to look up
*/
-(id) initWithEndpointURL:(NSURL*)url;

@end

/*!
Expand Down
13 changes: 1 addition & 12 deletions RESTframework/RESTframework/RESTclasses/RESTSvc.m
Expand Up @@ -20,7 +20,7 @@ -(void) continueExecFromQueue;
@end

@implementation RESTSvc
@synthesize delegate, currentRequest, requestsQueue, serviceEndpoint;
@synthesize delegate, currentRequest, requestsQueue;

#pragma mark - Props

Expand All @@ -35,18 +35,7 @@ -(NSMutableArray*) requestsQueue

#pragma mark - Initialization

-(id) initWithEndpointURL:(NSURL*)url
{
if ((self = [super init])) {
self.serviceEndpoint = url;
}

return self;
}

-(void) dealloc {
[serviceEndpoint release];
serviceEndpoint = nil;
[self cancelRequests];//if any...
[requestsQueue release];
requestsQueue = nil;
Expand Down

0 comments on commit 330bc79

Please sign in to comment.