/*
    Generic HTTP client. Supports POST and GET.
    I'm using CoreFoundation here rather than NSURLConnection and family.
 */

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <CoreFoundation/CoreFoundation.h>
#import <CoreServices/CoreServices.h>

#define DAClientMethodPOST 1
#define DAClientMethodGET  2

/* Your class should implement this to be notified when download is finished */
/* data will be nil on error. */
@interface NSObject (DAClientDelegate)
- (void) requestDidFinish:(NSData *)data;
@end

@interface DAClient : NSObject 
{
	CFReadStreamRef _stream;
	NSMutableData *_data;
	id _delegate;
}

/* Returns NO on error. Calls [delegate requestDidFinish:dataReceived] when
   finished downloading. dataReceived will be nil on error. */
- (BOOL) fetchUrl:(NSURL *)url withMethod:(int)method 
   withParameters:(NSDictionary *)params withDelegate:(id)delegate;

- (void) cancelPending;

- (void) handleNetworkEvent:(CFStreamEventType)type;
- (void) handleBytesAvailable;
- (void) handleStreamComplete;
- (void) handleStreamError;

- (id) delegate;
- (void) setDelegate:(id)newDelegate;

@end
