Permalink
Browse files

First commit into Git.

  • Loading branch information...
0 parents commit c9be12651ff3c8d642779b16a5028b44f8a28979 @snej snej committed Jul 11, 2011
Showing with 9,795 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +3 −0 .gitmodules
  3. +14 −0 Couch/Couch.h
  4. +38 −0 Couch/CouchAttachment.h
  5. +128 −0 Couch/CouchAttachment.m
  6. +32 −0 Couch/CouchChangeTracker.h
  7. +212 −0 Couch/CouchChangeTracker.m
  8. +87 −0 Couch/CouchDatabase.h
  9. +251 −0 Couch/CouchDatabase.m
  10. +59 −0 Couch/CouchDesignDocument.h
  11. +106 −0 Couch/CouchDesignDocument.m
  12. +53 −0 Couch/CouchDocument.h
  13. +239 −0 Couch/CouchDocument.m
  14. +50 −0 Couch/CouchInternal.h
  15. +7 −0 Couch/CouchPrefix.pch
  16. +110 −0 Couch/CouchQuery.h
  17. +247 −0 Couch/CouchQuery.m
  18. +23 −0 Couch/CouchResource.h
  19. +70 −0 Couch/CouchResource.m
  20. +61 −0 Couch/CouchRevision.h
  21. +196 −0 Couch/CouchRevision.m
  22. +40 −0 Couch/CouchServer.h
  23. +92 −0 Couch/CouchServer.m
  24. +1,055 −0 CouchCocoa.xcodeproj/project.pbxproj
  25. +7 −0 CouchCocoa.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  26. +28 −0 Demo/CouchDemo-Info.plist
  27. +2,669 −0 Demo/CouchDemo.xib
  28. +23 −0 Demo/DemoAppController.h
  29. +47 −0 Demo/DemoAppController.m
  30. +26 −0 Demo/DemoItem.h
  31. +99 −0 Demo/DemoItem.m
  32. +27 −0 Demo/DemoQuery.h
  33. +97 −0 Demo/DemoQuery.m
  34. +1,723 −0 Doxyfile
  35. +11 −0 REST/REST.h
  36. +66 −0 REST/RESTBody.h
  37. +209 −0 REST/RESTBody.m
  38. +48 −0 REST/RESTCache.h
  39. +89 −0 REST/RESTCache.m
  40. +29 −0 REST/RESTInternal.h
  41. +56 −0 REST/RESTInternal.m
  42. +129 −0 REST/RESTOperation.h
  43. +345 −0 REST/RESTOperation.m
  44. +126 −0 REST/RESTResource.h
  45. +275 −0 REST/RESTResource.m
  46. +30 −0 Resources/CouchCocoa-Info.plist
  47. +2 −0 Resources/en.lproj/InfoPlist.strings
  48. BIN Resources/logo.png
  49. +325 −0 Test/Test_Couch.m
  50. +127 −0 Test/Test_REST.m
  51. +1 −0 Vendor/JSONKit
@@ -0,0 +1,8 @@
+.DS_Store
+*.swp
+*.pbxuser
+*.perspectivev3
+*.mode1v3
+xcuserdata/
+build/
+Documentation/
@@ -0,0 +1,3 @@
+[submodule "Vendor/JSONKit"]
+ path = Vendor/JSONKit
+ url = git://github.com/johnezang/JSONKit.git
@@ -0,0 +1,14 @@
+//
+// Couch.h
+// CouchCocoa
+//
+// Created by Jens Alfke on 6/12/11.
+// Copyright 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import "CouchServer.h"
+#import "CouchDatabase.h"
+#import "CouchQuery.h"
+#import "CouchDocument.h"
+#import "CouchRevision.h"
+#import "CouchAttachment.h"
@@ -0,0 +1,38 @@
+//
+// CouchAttachment.h
+// CouchCocoa
+//
+// Created by Jens Alfke on 5/26/11.
+// Copyright 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import "CouchResource.h"
+@class CouchDocument;
+
+
+/** A binary attachment to a document. */
+@interface CouchAttachment : CouchResource
+{
+ @private
+ NSString* _contentType;
+}
+
+- (id) initWithDocument: (CouchDocument*)document
+ name: (NSString*)name
+ type: (NSString*)contentType;
+
+@property (readonly) CouchDocument* document;
+@property (readonly) NSString* name;
+@property (readonly, copy) NSString* contentType;
+
+/** Asynchronous setter for the body. (Use inherited -GET to get it.) */
+- (RESTOperation*) PUT: (NSData*)body contentType: (NSString*)contentType;
+
+/** Asynchronous setter for the body. (Use inherited -GET to get it.) */
+- (RESTOperation*) PUT: (NSData*)body;
+
+/** Synchronous accessor for the body.
+ If the getter fails, it returns nil. The setter fails silently. */
+@property (copy) NSData* body;
+
+@end
@@ -0,0 +1,128 @@
+//
+// CouchAttachment.m
+// CouchCocoa
+//
+// Created by Jens Alfke on 5/26/11.
+// Copyright 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import "CouchAttachment.h"
+#import "CouchDocument.h"
+#import "RESTInternal.h"
+
+
+@interface CouchAttachment ()
+@property (readwrite, copy) NSString* contentType;
+@end
+
+
+@implementation CouchAttachment
+
+
+- (id) initWithDocument: (CouchDocument*)document
+ name: (NSString*)name
+ type: (NSString*)contentType
+{
+ NSParameterAssert(contentType);
+ self = [super initWithParent: document relativePath: name];
+ if (self) {
+ _contentType = [contentType copy];
+ }
+ return self;
+}
+
+
+- (void)dealloc {
+ [_contentType release];
+ [super dealloc];
+}
+
+
+@synthesize contentType = _contentType;
+
+
+- (NSString*) name {
+ return self.relativePath;
+}
+
+
+- (CouchDocument*) document {
+ return (CouchDocument*)self.parent;
+}
+
+
+#pragma mark -
+#pragma mark BODY
+
+
+- (BOOL) contentsAreJSON {
+ return NO; // overridden from CouchResource
+}
+
+
+- (RESTOperation*) PUT: (NSData*)body contentType: (NSString*)contentType {
+ if (!contentType) {
+ contentType = _contentType;
+ NSParameterAssert(contentType != nil);
+ }
+ NSDictionary* params = [NSDictionary dictionaryWithObject: contentType
+ forKey: @"Content-Type"];
+ return [self PUT: body parameters: params];
+}
+
+
+- (RESTOperation*) PUT: (NSData*)body {
+ return [self PUT: body contentType: _contentType];
+}
+
+
+- (NSData*) body {
+ RESTOperation* op = [self GET];
+ if ([op wait])
+ return op.responseBody.content;
+ else {
+ Warn(@"Synchronous CouchAttachment.body getter failed: %@", op.error);
+ return nil;
+ }
+}
+
+
+- (void) setBody: (NSData*)body {
+ RESTOperation* op = [self PUT: body];
+ if (![op wait])
+ Warn(@"Synchronous CouchAttachment.body setter failed: %@", op.error);
+}
+
+
+- (NSMutableURLRequest*) requestWithMethod: (NSString*)method
+ parameters: (NSDictionary*)parameters {
+ if ([method isEqualToString: @"PUT"] || [method isEqualToString: @"DELETE"]) {
+ // Add a ?rev= query param with the current document revision:
+ NSString* revisionID = self.document.currentRevisionID;
+ if (revisionID) {
+ NSMutableDictionary* nuParams = [[parameters mutableCopy] autorelease];
+ if (!nuParams)
+ nuParams = [NSMutableDictionary dictionary];
+ [nuParams setObject: revisionID forKey: @"?rev"];
+ parameters = nuParams;
+ }
+ }
+ return [super requestWithMethod: method parameters: parameters];
+}
+
+
+- (NSError*) op: (RESTOperation*)op willCompleteWithError: (NSError*)error {
+ error = [super operation: op willCompleteWithError: error];
+
+ if (!error && op.isSuccessful) {
+ // Capture changes to the contentType made by GETs and PUTs:
+ if (op.isGET)
+ self.contentType = [op.responseHeaders objectForKey: @"Content-Type"];
+ else if (op.isPUT)
+ self.contentType = [op.request valueForHTTPHeaderField: @"Content-Type"];
+ }
+ return error;
+}
+
+
+@end
@@ -0,0 +1,32 @@
+//
+// CouchChangeTracker.h
+// CouchCocoa
+//
+// Created by Jens Alfke on 6/20/11.
+// Copyright 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+@class CouchDatabase;
+
+
+/** Reads the continuous-mode _changes feed of a database, and sends the individual lines to -[CouchDatabase receivedChangeChunk:].
+ This class is used internally by CouchDatabase and you shouldn't need to use it yourself. */
+@interface CouchChangeTracker : NSObject <NSStreamDelegate>
+{
+ @private
+ CouchDatabase* _database;
+ NSUInteger _lastSequenceNo;
+ NSInputStream* _trackingInput;
+ NSOutputStream* _trackingOutput;
+ NSString* _trackingRequest;
+
+ NSMutableData* _inputBuffer;
+ int _state;
+}
+
+- (id)initWithDatabase: (CouchDatabase*)database sequenceNumber: (NSUInteger)lastSequenceNo;
+- (BOOL) start;
+- (void) stop;
+
+@end
Oops, something went wrong.

0 comments on commit c9be126

Please sign in to comment.