Skip to content

Commit 718eafc

Browse files
author
Josh Holtz
committed
Updated to latest examples
1 parent 12b08a4 commit 718eafc

File tree

6 files changed

+56
-64
lines changed

6 files changed

+56
-64
lines changed

Project/JSONAPI.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/* Begin PBXBuildFile section */
2424
03866451186A909200985CEC /* PeopleResource.m in Sources */ = {isa = PBXBuildFile; fileRef = 03866450186A909200985CEC /* PeopleResource.m */; };
2525
03866454186A94B700985CEC /* CommentResource.m in Sources */ = {isa = PBXBuildFile; fileRef = 03866453186A94B700985CEC /* CommentResource.m */; };
26-
03866457186A94C200985CEC /* PostResource.m in Sources */ = {isa = PBXBuildFile; fileRef = 03866456186A94C200985CEC /* PostResource.m */; };
26+
03866457186A94C200985CEC /* ArticleResource.m in Sources */ = {isa = PBXBuildFile; fileRef = 03866456186A94C200985CEC /* ArticleResource.m */; };
2727
03866459186CCE6600985CEC /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = 03866458186CCE6600985CEC /* CHANGELOG.md */; };
2828
03A055BB1868E038004807F0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03A055BA1868E038004807F0 /* Foundation.framework */; };
2929
03A055BD1868E038004807F0 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03A055BC1868E038004807F0 /* CoreGraphics.framework */; };
@@ -69,8 +69,8 @@
6969
03866450186A909200985CEC /* PeopleResource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PeopleResource.m; sourceTree = "<group>"; };
7070
03866452186A94B700985CEC /* CommentResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommentResource.h; sourceTree = "<group>"; };
7171
03866453186A94B700985CEC /* CommentResource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommentResource.m; sourceTree = "<group>"; };
72-
03866455186A94C200985CEC /* PostResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostResource.h; sourceTree = "<group>"; };
73-
03866456186A94C200985CEC /* PostResource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PostResource.m; sourceTree = "<group>"; };
72+
03866455186A94C200985CEC /* ArticleResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArticleResource.h; sourceTree = "<group>"; };
73+
03866456186A94C200985CEC /* ArticleResource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ArticleResource.m; sourceTree = "<group>"; };
7474
03866458186CCE6600985CEC /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = CHANGELOG.md; path = ../CHANGELOG.md; sourceTree = "<group>"; };
7575
03A055B71868E038004807F0 /* JSONAPI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JSONAPI.app; sourceTree = BUILT_PRODUCTS_DIR; };
7676
03A055BA1868E038004807F0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -138,8 +138,8 @@
138138
0386643E186A791D00985CEC /* ResourceModels */ = {
139139
isa = PBXGroup;
140140
children = (
141-
03866455186A94C200985CEC /* PostResource.h */,
142-
03866456186A94C200985CEC /* PostResource.m */,
141+
03866455186A94C200985CEC /* ArticleResource.h */,
142+
03866456186A94C200985CEC /* ArticleResource.m */,
143143
0386644F186A909200985CEC /* PeopleResource.h */,
144144
03866450186A909200985CEC /* PeopleResource.m */,
145145
03866452186A94B700985CEC /* CommentResource.h */,
@@ -385,7 +385,7 @@
385385
03866451186A909200985CEC /* PeopleResource.m in Sources */,
386386
681B47761B08EA9800A99D76 /* JSONAPIResourceBase.m in Sources */,
387387
680E14F51B08146E004FF8CD /* JSONAPIResourceParser.m in Sources */,
388-
03866457186A94C200985CEC /* PostResource.m in Sources */,
388+
03866457186A94C200985CEC /* ArticleResource.m in Sources */,
389389
03A055D11868E038004807F0 /* ViewController.m in Sources */,
390390
03A055F71868E08A004807F0 /* JSONAPI.m in Sources */,
391391
68A469941AE47E0000E7BBC8 /* NSDateFormatter+JSONAPIDateFormatter.m in Sources */,

Project/JSONAPI/PostResource.h renamed to Project/JSONAPI/ArticleResource.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// PostResource.h
2+
// ArticleResource.h
33
// JSONAPI
44
//
55
// Created by Josh Holtz on 12/24/13.
@@ -10,7 +10,7 @@
1010

1111
@class PeopleResource;
1212

13-
@interface PostResource : JSONAPIResourceBase
13+
@interface ArticleResource : JSONAPIResourceBase
1414

1515
@property (nonatomic, strong) NSString *title;
1616
@property (nonatomic, strong) PeopleResource *author;

Project/JSONAPI/PostResource.m renamed to Project/JSONAPI/ArticleResource.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//
2-
// PostResource.m
2+
// ArticleResource.m
33
// JSONAPI
44
//
55
// Created by Josh Holtz on 12/24/13.
66
// Copyright (c) 2013 Josh Holtz. All rights reserved.
77
//
88

9-
#import "PostResource.h"
9+
#import "ArticleResource.h"
1010

1111
#import "JSONAPIPropertyDescriptor.h"
1212
#import "JSONAPIResourceDescriptor.h"
@@ -16,14 +16,14 @@
1616
#import "CommentResource.h"
1717

1818

19-
@implementation PostResource
19+
@implementation ArticleResource
2020

2121
static JSONAPIResourceDescriptor *__descriptor = nil;
2222

2323
+ (JSONAPIResourceDescriptor*)descriptor {
2424
static dispatch_once_t onceToken;
2525
dispatch_once(&onceToken, ^{
26-
__descriptor = [[JSONAPIResourceDescriptor alloc] initWithClass:[self class] forLinkedType:@"posts"];
26+
__descriptor = [[JSONAPIResourceDescriptor alloc] initWithClass:[self class] forLinkedType:@"articles"];
2727

2828
[__descriptor setIdProperty:@"ID"];
2929

Project/JSONAPI/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#import "CommentResource.h"
1414
#import "PeopleResource.h"
15-
#import "PostResource.h"
15+
#import "ArticleResource.h"
1616

1717
@interface ViewController ()
1818

Project/JSONAPITests/JSONAPITests.m

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#import "CommentResource.h"
1717
#import "PeopleResource.h"
18-
#import "PostResource.h"
18+
#import "ArticleResource.h"
1919

2020
@interface JSONAPITests : XCTestCase
2121

@@ -28,7 +28,7 @@ - (void)setUp {
2828

2929
[JSONAPIResourceDescriptor addResource:[CommentResource class]];
3030
[JSONAPIResourceDescriptor addResource:[PeopleResource class]];
31-
[JSONAPIResourceDescriptor addResource:[PostResource class]];
31+
[JSONAPIResourceDescriptor addResource:[ArticleResource class]];
3232
}
3333

3434
- (void)tearDown {
@@ -43,18 +43,18 @@ - (void)testMeta {
4343
XCTAssertEqualObjects(jsonAPI.meta[@"hehe"], @"hoho", @"Meta's 'hehe' should equal 'hoho'");
4444
}
4545

46-
- (void)testDataPosts {
46+
- (void)testDataArticles {
4747
NSDictionary *json = [self mainExampleJSON];
4848
JSONAPI *jsonAPI = [JSONAPI jsonAPIWithDictionary:json];
4949

5050
XCTAssertNotNil(jsonAPI.resource, @"Resource should not be nil");
5151
XCTAssertNotNil(jsonAPI.resources, @"Resources should not be nil");
5252
XCTAssertEqual(jsonAPI.resources.count, 1, @"Resources should contain 1 resource");
5353

54-
PostResource *post = jsonAPI.resource;
55-
XCTAssert([post isKindOfClass:[PostResource class]], @"Post should be a PostResource");
56-
XCTAssertEqualObjects(post.ID, @"1", @"Post id should be 1");
57-
XCTAssertEqualObjects(post.title, @"JSON API paints my bikeshed!", @"Post title should be 'JSON API paints my bikeshed!'");
54+
ArticleResource *article = jsonAPI.resource;
55+
XCTAssert([article isKindOfClass:[ArticleResource class]], @"Article should be a ArticleResource");
56+
XCTAssertEqualObjects(article.ID, @"1", @"Article id should be 1");
57+
XCTAssertEqualObjects(article.title, @"JSON API paints my bikeshed!", @"Article title should be 'JSON API paints my bikeshed!'");
5858
}
5959

6060
- (void)testIncludedPeopleAndComments {
@@ -66,14 +66,14 @@ - (void)testIncludedPeopleAndComments {
6666

6767
}
6868

69-
- (void)testDataPostAuthorAndComments {
69+
- (void)testDataArticleAuthorAndComments {
7070
NSDictionary *json = [self mainExampleJSON];
7171
JSONAPI *jsonAPI = [JSONAPI jsonAPIWithDictionary:json];
7272

73-
PostResource *post = jsonAPI.resource;
74-
XCTAssertNotNil(post.author, @"Post's author should not be nil");
75-
XCTAssertNotNil(post.comments, @"Post's comments should not be nil");
76-
XCTAssertEqual(post.comments.count, 2, @"Post should contain 2 comments");
73+
ArticleResource *article = jsonAPI.resource;
74+
XCTAssertNotNil(article.author, @"Article author should not be nil");
75+
XCTAssertNotNil(article.comments, @"Article comments should not be nil");
76+
XCTAssertEqual(article.comments.count, 2, @"Article should contain 2 comments");
7777
}
7878

7979
- (void)testIncludedCommentIsLinked {
@@ -82,7 +82,7 @@ - (void)testIncludedCommentIsLinked {
8282

8383
CommentResource *comment = [jsonAPI includedResource:@"5" withType:@"comments"];
8484
XCTAssertNotNil(comment.author, @"Comment's author should not be nil");
85-
XCTAssertEqualObjects(comment.author.ID, @"9", @"Comment's author's ID should be 9");
85+
XCTAssertEqualObjects(comment.author.ID, @"2", @"Comment's author's ID should be 2");
8686
}
8787

8888
- (void)testNoError {
@@ -115,12 +115,12 @@ - (void)testSerializeSimple {
115115
}
116116

117117
- (void)testSerializeWithFormat {
118-
PostResource *newPost = [[PostResource alloc] init];
119-
newPost.title = @"Title";
120-
newPost.date = [NSDate date];
118+
ArticleResource *newArticle = [[ArticleResource alloc] init];
119+
newArticle.title = @"Title";
120+
newArticle.date = [NSDate date];
121121

122-
NSDictionary *json = [JSONAPIResourceParser dictionaryFor:newPost];
123-
XCTAssertEqualObjects(json[@"type"], @"posts", @"Did not create post!");
122+
NSDictionary *json = [JSONAPIResourceParser dictionaryFor:newArticle];
123+
XCTAssertEqualObjects(json[@"type"], @"articles", @"Did not create article!");
124124
XCTAssertNotNil(json[@"attributes"][@"date"], @"Wrong date!");
125125
XCTAssertTrue([json[@"attributes"][@"date"] isKindOfClass:[NSString class]], @"Date should be string!.");
126126
}
@@ -137,14 +137,14 @@ - (void)testSerializeComplex {
137137
newComment.author = newAuthor;
138138
newComment.text = @"First!";
139139

140-
PostResource *newPost = [[PostResource alloc] init];
141-
newPost.title = @"Title";
142-
newPost.author = newAuthor;
143-
newPost.date = [NSDate date];
144-
newPost.comments = [[NSArray alloc] initWithObjects:newComment, nil];
140+
ArticleResource *newArticle = [[ArticleResource alloc] init];
141+
newArticle.title = @"Title";
142+
newArticle.author = newAuthor;
143+
newArticle.date = [NSDate date];
144+
newArticle.comments = [[NSArray alloc] initWithObjects:newComment, nil];
145145

146-
NSDictionary *json = [JSONAPIResourceParser dictionaryFor:newPost];
147-
XCTAssertEqualObjects(json[@"type"], @"posts", @"Did not create Post!");
146+
NSDictionary *json = [JSONAPIResourceParser dictionaryFor:newArticle];
147+
XCTAssertEqualObjects(json[@"type"], @"articles", @"Did not create Article!");
148148
XCTAssertNotNil(json[@"relationships"], @"Did not create links!");
149149
XCTAssertNotNil(json[@"relationships"][@"author"], @"Did not create links!");
150150
XCTAssertNotNil(json[@"relationships"][@"author"][@"data"], @"Did not create links!");

Project/JSONAPITests/main_example.json

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
"hehe": "hoho"
44
},
55
"links": {
6-
"self": "http://example.com/posts",
7-
"next": "http://example.com/posts?page[offset]=2",
8-
"last": "http://example.com/posts?page[offset]=10"
6+
"self": "http://example.com/articles",
7+
"next": "http://example.com/articles?page[offset]=2",
8+
"last": "http://example.com/articles?page[offset]=10"
99
},
1010
"data": [{
11-
"type": "posts",
11+
"type": "articles",
1212
"id": "1",
1313
"attributes": {
1414
"title": "JSON API paints my bikeshed!"
1515
},
1616
"relationships": {
1717
"author": {
1818
"links": {
19-
"self": "http://example.com/posts/1/relationships/author",
20-
"related": "http://example.com/posts/1/author"
19+
"self": "http://example.com/articles/1/relationships/author",
20+
"related": "http://example.com/articles/1/author"
2121
},
2222
"data": { "type": "people", "id": "9" }
2323
},
2424
"comments": {
2525
"links": {
26-
"self": "http://example.com/posts/1/relationships/comments",
27-
"related": "http://example.com/posts/1/comments"
26+
"self": "http://example.com/articles/1/relationships/comments",
27+
"related": "http://example.com/articles/1/comments"
2828
},
2929
"data": [
3030
{ "type": "comments", "id": "5" },
@@ -33,16 +33,16 @@
3333
}
3434
},
3535
"links": {
36-
"self": "http://example.com/posts/1"
36+
"self": "http://example.com/articles/1"
3737
}
3838
}],
3939
"included": [{
4040
"type": "people",
4141
"id": "9",
4242
"attributes": {
43-
"first-name": "Dan",
44-
"last-name": "Gebhardt",
45-
"twitter": "dgeb"
43+
"first-name": "Dan",
44+
"last-name": "Gebhardt",
45+
"twitter": "dgeb"
4646
},
4747
"links": {
4848
"self": "http://example.com/people/9"
@@ -51,16 +51,12 @@
5151
"type": "comments",
5252
"id": "5",
5353
"attributes": {
54-
"body": "First!"
54+
"body": "First!"
5555
},
5656
"relationships": {
57-
"author": {
58-
"links": {
59-
"self": "http://example.com/posts/1/relationships/author",
60-
"related": "http://example.com/posts/1/author"
61-
},
62-
"data": { "type": "people", "id": "9" }
63-
},
57+
"author": {
58+
"data": { "type": "people", "id": "2" }
59+
}
6460
},
6561
"links": {
6662
"self": "http://example.com/comments/5"
@@ -69,16 +65,12 @@
6965
"type": "comments",
7066
"id": "12",
7167
"attributes": {
72-
"body": "I like XML better"
68+
"body": "I like XML better"
7369
},
7470
"relationships": {
7571
"author": {
76-
"links": {
77-
"self": "http://example.com/posts/1/relationships/author",
78-
"related": "http://example.com/posts/1/author"
79-
},
8072
"data": { "type": "people", "id": "9" }
81-
},
73+
}
8274
},
8375
"links": {
8476
"self": "http://example.com/comments/12"

0 commit comments

Comments
 (0)