Commits

Paul Schifferer committed 6154369

Fixed the incorrect handling of annotations in post, user, message and channel.

Comments (0)

Files changed (6)

Snapper/Source/Shared/SNPChannel.m

 
 #import "SNPChannel.h"
 
+#import "SNPAnnotation.h"
+
 
 @implementation SNPChannel
 
                                                          }];
 }
 
++ (NSValueTransformer*)annotationsTransformer {
+    return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(NSArray* annotationDicts) {
+        NSMutableArray* annotations = [NSMutableArray new];
+
+        for(NSDictionary* annoDict in annotationDicts) {
+            SNPAnnotation* annotation = [[SNPAnnotation alloc] initWithExternalRepresentation:annoDict];
+
+            [annotations addObject:annotation];
+        }
+
+        return [annotations copy];
+    }
+                                                         reverseBlock:^(NSArray* annotations) {
+                                                             NSMutableArray* annoDicts = [NSMutableArray new];
+
+                                                             for(SNPAnnotation* annotation in annotations) {
+                                                                 NSDictionary* annoDict = [annotation externalRepresentation];
+
+                                                                 [annoDicts addObject:annoDict];
+                                                             }
+
+                                                             return [annoDicts copy];
+                                                         }];
+}
+
 @end

Snapper/Source/Shared/SNPMessage.m

 //
 
 #import "SNPMessage.h"
+#import "SNPAnnotation.h"
 
 
 @implementation SNPMessage
                                                          }];
 }
 
++ (NSValueTransformer*)annotationsTransformer {
+    return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(NSArray* annotationDicts) {
+        NSMutableArray* annotations = [NSMutableArray new];
+
+        for(NSDictionary* annoDict in annotationDicts) {
+            SNPAnnotation* annotation = [[SNPAnnotation alloc] initWithExternalRepresentation:annoDict];
+
+            [annotations addObject:annotation];
+        }
+
+        return [annotations copy];
+    }
+                                                         reverseBlock:^(NSArray* annotations) {
+                                                             NSMutableArray* annoDicts = [NSMutableArray new];
+
+                                                             for(SNPAnnotation* annotation in annotations) {
+                                                                 NSDictionary* annoDict = [annotation externalRepresentation];
+
+                                                                 [annoDicts addObject:annoDict];
+                                                             }
+
+                                                             return [annoDicts copy];
+                                                         }];
+}
+
 @end

Snapper/Source/Shared/SNPPost.m

 #import "SNPHashtag.h"
 #import "SNPMention.h"
 #import "SNPLink.h"
+#import "SNPAnnotation.h"
 
 
 @implementation SNPPost
                                                          }];
 }
 
++ (NSValueTransformer*)annotationsTransformer {
+    return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(NSArray* annotationDicts) {
+        NSMutableArray* annotations = [NSMutableArray new];
+
+        for(NSDictionary* annoDict in annotationDicts) {
+            SNPAnnotation* annotation = [[SNPAnnotation alloc] initWithExternalRepresentation:annoDict];
+
+            [annotations addObject:annotation];
+        }
+
+        return [annotations copy];
+    }
+                                                         reverseBlock:^(NSArray* annotations) {
+                                                             NSMutableArray* annoDicts = [NSMutableArray new];
+
+                                                             for(SNPAnnotation* annotation in annotations) {
+                                                                 NSDictionary* annoDict = [annotation externalRepresentation];
+
+                                                                 [annoDicts addObject:annoDict];
+                                                             }
+
+                                                             return [annoDicts copy];
+                                                         }];
+}
+
 @end

Snapper/Source/Shared/SNPUser.m

 //
 
 #import "SNPUser.h"
+#import "SNPAnnotation.h"
 
 
 @implementation SNPUser
                                                          }];
 }
 
++ (NSValueTransformer*)annotationsTransformer {
+    return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(NSArray* annotationDicts) {
+        NSMutableArray* annotations = [NSMutableArray new];
+
+        for(NSDictionary* annoDict in annotationDicts) {
+            SNPAnnotation* annotation = [[SNPAnnotation alloc] initWithExternalRepresentation:annoDict];
+
+            [annotations addObject:annotation];
+        }
+
+        return [annotations copy];
+    }
+                                                         reverseBlock:^(NSArray* annotations) {
+                                                             NSMutableArray* annoDicts = [NSMutableArray new];
+
+                                                             for(SNPAnnotation* annotation in annotations) {
+                                                                 NSDictionary* annoDict = [annotation externalRepresentation];
+
+                                                                 [annoDicts addObject:annoDict];
+                                                             }
+                                                             
+                                                             return [annoDicts copy];
+                                                         }];
+}
+
 @end

SnapperTests/Resources/post.json

 {
-    "annotations": [],
+    "annotations": [{
+                    "type": "com.pilgrimagesoftware.snapper",
+                    "value": {
+                    "key1": "value1",
+                    "key2": "value2"
+                    }
+                    }],
     "canonical_url": "https://alpha.app.net/pilgrim/post/2165974",
     "created_at": "2012-12-24T04:15:19Z",
     "entities": {

SnapperTests/Source/ModelTests.m

     STAssertNotNil(post.canonicalURL, @"Post 'canonicalURL' property should not be nil");
     STAssertNotNil(post.user, @"Post 'user' property should not be nil");
     STAssertTrue([post.mentions count] == 1, @"Post 'mentions' property should contain 1 item, actually has %d", [post.mentions count]);
+    STAssertTrue([post.annotations count] == 1, @"Post 'annotations' property should contain 1 item, actually has %d", [post.annotations count]);
+
+    SNPAnnotation* annotation = post.annotations[0];
+    STAssertNotNil(annotation, @"Annotation at index 0 should not be nil");
+    STAssertTrue([annotation.type isEqualToString:@"com.pilgrimagesoftware.snapper"], @"Annotation 'type' property should be 'com.pilgrimagesoftware.snapper', is actually %@", annotation.type);
+    NSString* value1 = annotation.value[@"key1"];
+    STAssertNotNil(value1, @"'key1' from annotation should not be nil");
+    STAssertTrue([value1 isEqualToString:@"value1"], @"'key1' value from annotation should be 'value1', is actually %@", value1);
 }
 
 - (void)testRepostFromJSON {