Skip to content

Commit a9f8a34

Browse files
author
Josh Holtz
committed
Updated README
1 parent 846daeb commit a9f8a34

File tree

1 file changed

+11
-69
lines changed

1 file changed

+11
-69
lines changed

README.md

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ A library for loading data from a [JSON API](http://jsonapi.org) datasource. Par
99

1010
Version | Changes
1111
--- | ---
12+
**1.0.0-rc1** | Rewrote core of `JSONAPI` and `JSONAPIResource` and all unit tests to be up to spec with JSON API spec 1.0.0-rc3. Removed `JSONAPIResourceLinker`. Added `JSONAPIErrorResource`
1213
**0.2.0** | Added `NSCopying` and `NSCoded` to `JSONAPIResource`; Added `JSONAPIResourceFormatter` to format values before getting mapped - [more info](#formatter)
1314
**0.1.2** | `JSONAPIResource` IDs can either be numbers or strings (thanks [danylhebreux](https://github.com/danylhebreux)); `JSONAPIResource` subclass can have mappings defined to set JSON values into properties automatically - [more info](#resource-mappings)
1415
**0.1.1** | Fixed linked resources with links so they actually link to other linked resources
1516
**0.1.0** | Initial release
1617

1718
### Features
1819
- Parses datasource into manageable objects of `JSONAPIResource`
19-
- Auto-links resources with custom link mapping definitions using `JSONAPIResourceLinker` (ex: link 'book' to 'books', link 'person' to 'people')
2020
- Allows resource types to be created into subclasses of `JSONAPIResource` using `JSONAPIResourceModeler`
2121
- Set mapping for `JSONAPIResource` subclass to set JSON values into properties
2222

@@ -30,7 +30,7 @@ Clone the repository and drop in the .h and .m files from the "Classes" director
3030
JSONAPI is available through [CocoaPods](http://cocoapods.org), to install
3131
it simply add the following line to your Podfile:
3232

33-
pod 'JSONAPI', '~> 0.2.0'
33+
pod 'JSONAPI', '~> 1.0.0-rc1'
3434

3535
## Usage
3636

@@ -54,13 +54,13 @@ Below is an example to register a "Date" function to format a date in a NSString
5454
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
5555
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
5656
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
57-
57+
5858
NSDate *date = nil;
5959
NSError *error = nil;
6060
if (![dateFormatter getObjectValue:&date forString:jsonValue range:nil error:&error]) {
6161
NSLog(@"Date '%@' could not be parsed: %@", jsonValue, error);
6262
}
63-
63+
6464
return date;
6565
}];
6666

@@ -97,35 +97,6 @@ Below is an example to register a "Date" function to format a date in a NSString
9797
9898
````
9999

100-
### JSONAPIResourceLinker
101-
`JSONAPIResourceLinker` is used for configuring the type of 'links' resources to 'linked' resources.
102-
103-
#### Example
104-
The "author" defined in "links" need to be mapped to the "people" type in "linked"
105-
106-
````
107-
{
108-
"posts":[
109-
{
110-
"id":1,
111-
"name":"A post!",
112-
"links":{
113-
"author":9
114-
}
115-
}
116-
],
117-
"linked":{
118-
"people":[
119-
{
120-
"id":9,
121-
"name":"Josh Holtz"
122-
}
123-
]
124-
}
125-
}
126-
127-
````
128-
129100
### JSONAPIResourceModeler
130101

131102
`JSONAPIResourceModeler` is used for configuring what type of JSONAPIResource subclass that resource types are created into.
@@ -136,13 +107,13 @@ The "author" defined in "links" need to be mapped to the "people" type in "linke
136107

137108
```` objc
138109

139-
NSString *json = @"{\"posts\":[{\"id\":1,\"name\":\"A post!\"},{\"id\":2,\"name\":\"Another post!\"}]}";
110+
NSString *json = @"{\"data\":[{\"id\":1,\"type\":\"posts\",\"name\":\"A post!\"},{\"id\":2,\"type\":\"posts\",\"name\":\"Another post!\"}]}";
140111

141112
// Parses JSON string into JSONAPI object
142113
JSONAPI *jsonApi = [JSONAPI JSONAPIWithString:json];
143114

144115
// Iterates over JSONAPIResources for "posts"
145-
NSArray *posts = [jsonApi resourcesForKey:@"posts"];
116+
NSArray *posts = jsonApi.resources;
146117
for (JSONAPIResource *post in posts) {
147118
// Prints post name
148119
NSLog(@"\"%@\"", [post objectForKey:@"name"]);
@@ -151,39 +122,12 @@ for (JSONAPIResource *post in posts) {
151122

152123
````
153124
154-
### Parsing - Using linked resources
155-
156-
```` objc
157-
158-
NSString *json = @"{\"posts\":[{\"id\":1,\"name\":\"A post!\",\"links\":{\"author\":9}},{\"id\":2,\"name\":\"Another post!\",\"links\":{\"author\":10}}],\"linked\":{\"people\":[{\"id\":9,\"name\":\"Josh Holtz\"},{\"id\":10,\"name\":\"Bandit the Cat\"}]}}";
159-
160-
// Links "author" resource to "people" linked resources
161-
[JSONAPIResourceLinker link:@"author" toLinkedType:@"people"];
162-
163-
// Parses JSON string into JSONAPI object
164-
JSONAPI *jsonApi = [JSONAPI JSONAPIWithString:json];
165-
166-
// Iterates over JSONAPIResources for "posts"
167-
NSArray *posts = [jsonApi resourcesForKey:@"posts"];
168-
for (JSONAPIResource *post in posts) {
169-
// Gets linked author resource
170-
JSONAPIResource *author = [post linkedResourceForKey:@"author"];
171-
172-
// Prints post name and author
173-
NSLog(@"\"%@\" by %@", [post objectForKey:@"name"], [author objectForKey:@"name"]);
174-
}
175-
176-
````
177-
178-
### Parsing - Using linked resources, subclassed JSONAPIResource classes, and model mappings
125+
### Parsing - Using subclassed JSONAPIResource classes, and model mappings
179126
This example shows how a response can be mapped directly into properties of a sublcasses JSONAPIResource
180127
181128
```` objc
182129
183-
NSString *json = @"{\"posts\":[{\"id\":1,\"name\":\"A post!\",\"links\":{\"author\":9,\"comments\":[2,3]}},{\"id\":2,\"name\":\"Another post!\",\"links\":{\"author\":10,\"comments\":[3,4]}}],\"linked\":{\"people\":[{\"id\":9,\"name\":\"Josh Holtz\"},{\"id\":10,\"name\":\"Bandit the Cat\"}],\"comments\":[{\"id\":2,\"text\":\"Omg this post is awesome\"},{ \"id\":3,\"text\":\"Omg this post is awesomer\"},{ \"id\":4,\"text\":\"Meeeehhhhh\"}]}}";
184-
185-
// Links "author" resource to "people" linked resources
186-
[JSONAPIResourceLinker link:@"author" toLinkedType:@"people"];
130+
NSString *json = @"{ \"data\": [{ \"type\": \"posts\", \"id\": \"1\", \"title\": \"JSON API paints my bikeshed!\", \"links\": { \"self\": \"http:\/\/example.com\/posts\/1\", \"author\": { \"linkage\": { \"type\": \"people\", \"id\": \"9\" } }, \"comments\": { \"linkage\": [ { \"type\": \"comments\", \"id\": \"5\" }, { \"type\": \"comments\", \"id\": \"12\" } ] } } }], \"included\": [{ \"type\": \"people\", \"id\": \"9\", \"first-name\": \"Dan\", \"last-name\": \"Gebhardt\", \"twitter\": \"dgeb\", \"links\": { } }, { \"type\": \"comments\", \"id\": \"5\", \"body\": \"First!\", \"links\": { \"author\": { \"linkage\": { \"type\": \"people\", \"id\": \"9\" } } } }, { \"type\": \"comments\", \"id\": \"12\", \"body\": \"I like XML better\", \"links\": { \"author\": { \"linkage\": { \"type\": \"people\", \"id\": \"9\" } } } }] }";
187131
188132
// Loads "people" into `PeopleResource`, "posts" into `PostResource`, and "comments" into `CommentResource`
189133
[JSONAPIResourceModeler useResource:[PeopleResource class] toLinkedType:@"people"];
@@ -194,14 +138,14 @@ NSString *json = @"{\"posts\":[{\"id\":1,\"name\":\"A post!\",\"links\":{\"autho
194138
JSONAPI *jsonApi = [JSONAPI JSONAPIWithString:json];
195139
196140
// Gets posts from JSONAPI that will be an array of PostResource objects
197-
NSArray *posts = [jsonApi resourcesForKey:@"posts"];
141+
NSArray *posts = jsonApi.resources;
198142
199143
// Parsing using JSONAPI and modeled resources (PostResource, PeopleResource, CommentResource
200144
for (PostResource *post in posts) {
201-
145+
202146
PeopleResource *author = post.author;
203147
NSLog(@"\"%@\" by %@", post.name, author.name);
204-
148+
205149
NSArray *comments = post.comments;
206150
for (CommentResource *comment in comments) {
207151
NSLog(@"\t%@", comment.text);
@@ -289,5 +233,3 @@ Josh Holtz, [email protected], [@joshdholtz](https://twitter.com/joshdholtz)
289233
## License
290234
291235
JSONAPI is available under the MIT license. See the LICENSE file for more info.
292-
293-

0 commit comments

Comments
 (0)