diff dstep/foundation/NSURLRequest.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 19885b43130e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dstep/foundation/NSURLRequest.d	Mon Aug 03 15:23:15 2009 +0200
@@ -0,0 +1,229 @@
+/**
+ * Copyright: Copyright (c) 2009 Jacob Carlborg.
+ * Authors: Jacob Carlborg
+ * Version: Initial created: Aug 3, 2009 
+ * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
+ */
+module dstep.foundation.NSURLRequest;
+
+import dstep.AvailabilityMacros;
+import dstep.foundation.NSData;
+import dstep.foundation.NSDate;
+import dstep.foundation.NSDictionary;
+import dstep.foundation.NSInputStream;
+import dstep.foundation.NSObject;
+import dstep.foundation.NSString;
+import dstep.foundation.NSURL;
+import dstep.foundation.NSURLRequestInternal;
+import dstep.objc.bridge.Bridge;
+import dstep.objc.objc : id;
+
+alias NSUInteger NSURLRequestCachePolicy;
+
+enum
+{
+	NSURLRequestUseProtocolCachePolicy = 0,
+	NSURLRequestReloadIgnoringLocalCacheData = 1,
+	NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4,
+	NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData,
+	NSURLRequestReturnCacheDataElseLoad = 2,
+	NSURLRequestReturnCacheDataDontLoad = 3,
+	NSURLRequestReloadRevalidatingCacheData = 5
+}
+
+class NSURLRequest : NSObject, INSCoding, INSCopying, INSMutableCopying
+{
+	mixin ObjcWrap;
+	mixin TNSHTTPURLRequest;
+
+	static Object requestWithURL (NSURL URL)
+	{
+		return invokeObjcSelfClass!(Object, "requestWithURL:", NSURL)(URL);
+	}
+
+	static Object requestWithURL (NSURL URL, uint cachePolicy, double timeoutInterval)
+	{
+		return invokeObjcSelfClass!(Object, "requestWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval);
+	}
+
+	Object initWithURL (NSURL URL)
+	{
+		return invokeObjcSelf!(Object, "initWithURL:", NSURL)(URL);
+	}
+
+	this (NSURL URL)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithURL:", NSURL)(objcObject, URL);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	Object initWithURL (NSURL URL, uint cachePolicy, double timeoutInterval)
+	{
+		return invokeObjcSelf!(Object, "initWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval);
+	}
+
+	this (NSURL URL, uint cachePolicy, double timeoutInterval)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(objcObject, URL, cachePolicy, timeoutInterval);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	NSURL URL ()
+	{
+		return invokeObjcSelf!(NSURL, "URL");
+	}
+
+	uint cachePolicy ()
+	{
+		return invokeObjcSelf!(uint, "cachePolicy");
+	}
+
+	double timeoutInterval ()
+	{
+		return invokeObjcSelf!(double, "timeoutInterval");
+	}
+
+	NSURL mainDocumentURL ()
+	{
+		return invokeObjcSelf!(NSURL, "mainDocumentURL");
+	}
+
+	void encodeWithCoder (NSCoder aCoder)
+	{
+		return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
+	}
+
+	Object initWithCoder (NSCoder aDecoder)
+	{
+		return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
+	}
+
+	this (NSCoder aDecoder)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	Object copyWithZone (NSZone* zone)
+	{
+		return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
+	}
+
+	Object mutableCopyWithZone (NSZone* zone)
+	{
+		return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone);
+	}
+}
+
+class NSMutableURLRequest : NSURLRequest
+{
+	mixin ObjcWrap;
+	mixin TNSMutableHTTPURLRequest;
+
+	void setURL (NSURL URL)
+	{
+		return invokeObjcSelf!(void, "setURL:", NSURL)(URL);
+	}
+
+	void setCachePolicy (uint policy)
+	{
+		return invokeObjcSelf!(void, "setCachePolicy:", uint)(policy);
+	}
+
+	void setTimeoutInterval (double seconds)
+	{
+		return invokeObjcSelf!(void, "setTimeoutInterval:", double)(seconds);
+	}
+
+	void setMainDocumentURL (NSURL URL)
+	{
+		return invokeObjcSelf!(void, "setMainDocumentURL:", NSURL)(URL);
+	}
+}
+
+template TNSHTTPURLRequest ()
+{
+	NSString HTTPMethod ()
+	{
+		return invokeObjcSelf!(NSString, "HTTPMethod");
+	}
+
+	NSDictionary allHTTPHeaderFields ()
+	{
+		return invokeObjcSelf!(NSDictionary, "allHTTPHeaderFields");
+	}
+
+	NSString valueForHTTPHeaderField (NSString field)
+	{
+		return invokeObjcSelf!(NSString, "valueForHTTPHeaderField:", NSString)(field);
+	}
+
+	NSData HTTPBody ()
+	{
+		return invokeObjcSelf!(NSData, "HTTPBody");
+	}
+
+	NSInputStream HTTPBodyStream ()
+	{
+		return invokeObjcSelf!(NSInputStream, "HTTPBodyStream");
+	}
+
+	bool HTTPShouldHandleCookies ()
+	{
+		return invokeObjcSelf!(bool, "HTTPShouldHandleCookies");
+	}
+}
+
+template TNSMutableHTTPURLRequest ()
+{
+	void setHTTPMethod (NSString method)
+	{
+		return invokeObjcSelf!(void, "setHTTPMethod:", NSString)(method);
+	}
+
+	void setAllHTTPHeaderFields (NSDictionary headerFields)
+	{
+		return invokeObjcSelf!(void, "setAllHTTPHeaderFields:", NSDictionary)(headerFields);
+	}
+
+	void setValue (NSString value, NSString field)
+	{
+		return invokeObjcSelf!(void, "setValue:forHTTPHeaderField:", NSString, NSString)(value, field);
+	}
+
+	void addValue (NSString value, NSString field)
+	{
+		return invokeObjcSelf!(void, "addValue:forHTTPHeaderField:", NSString, NSString)(value, field);
+	}
+
+	void setHTTPBody (NSData data)
+	{
+		return invokeObjcSelf!(void, "setHTTPBody:", NSData)(data);
+	}
+
+	void setHTTPBodyStream (NSInputStream inputStream)
+	{
+		return invokeObjcSelf!(void, "setHTTPBodyStream:", NSInputStream)(inputStream);
+	}
+
+	void setHTTPShouldHandleCookies (bool should)
+	{
+		return invokeObjcSelf!(void, "setHTTPShouldHandleCookies:", bool)(should);
+	}
+}
+