Skip to content

Commit dc3c36c

Browse files
committed
Automatically link custom types based on 'links' hash
1 parent f2c6139 commit dc3c36c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Classes/JSONAPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
@property (nonatomic, strong) NSDictionary *meta;
1818
@property (nonatomic, strong) NSDictionary *linked;
19+
@property (nonatomic, strong) NSDictionary *links;
1920
@property (nonatomic, strong) NSError *error;
2021

2122
+ (id)JSONAPIWithString:(NSString*)string;

Classes/JSONAPI.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,27 @@ - (void)inflateWithDictionary:(NSDictionary*)dictionary {
130130

131131
}
132132

133+
//Link mapping / types
134+
_links = [dictionary objectForKey:@"links"];
135+
if (![_links isKindOfClass:[NSDictionary class]]) {
136+
_links = nil;
137+
}
138+
139+
if (_links) {
140+
for (NSString *key in _links) {
141+
142+
NSDictionary *mapping = [_links objectForKey:key];
143+
144+
if ([mapping isKindOfClass:[NSDictionary class]]) {
145+
146+
NSString *type = [mapping objectForKey:@"type"];
147+
NSString *strippedKey = [[key componentsSeparatedByString:@"."] lastObject];
148+
149+
[JSONAPIResourceLinker link:strippedKey toLinkedType:type];
150+
}
151+
}
152+
}
153+
133154
_linked = creatingLinked;
134155
}
135156

0 commit comments

Comments
 (0)