You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: JSONAPI.podspec
+1-1
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
Pod::Spec.newdo |s|
2
2
s.name="JSONAPI"
3
-
s.version="1.0.5"
3
+
s.version="1.0.6"
4
4
s.summary="A library for loading data from a JSON API datasource."
5
5
s.description=<<-DESC
6
6
A library for loading data from a JSON API datasource. Parses JSON API data into models with support for auto-linking of resources and custom model classes.
Copy file name to clipboardExpand all lines: README.md
+177-11
Original file line number
Diff line number
Diff line change
@@ -21,8 +21,9 @@ For some full examples on how to use everything, please see the tests - https://
21
21
22
22
Version | Changes
23
23
--- | ---
24
-
**1.0.5** | Fix 1-to-many relationships serialization according to JSON API v1.0 (https://github.com/joshdholtz/jsonapi-ios/pull/34). Thanks to [RafaelKayumov](https://github.com/RafaelKayumov) for helping!
25
-
**1.0.4** | Add support for empty to-one relationship according to JSON API v1.0 (https://github.com/joshdholtz/jsonapi-ios/pull/33). Thanks to [RafaelKayumov](https://github.com/RafaelKayumov) for helping!
24
+
**1.0.6** | Improved resource parsing and added parsing of `selfLinks` (https://github.com/joshdholtz/jsonapi-ios/pull/35). Thanks to [ artcom](https://github.com/ artcom) for helping! Also removed the need to define `setIdProperty` and `setSelfLinkProperty` in every resource (automatically mapped in the init of `JSONAPIResourceDescriptor`)
25
+
**1.0.5** | Fix 1-to-many relationships serialization according to JSON API v1.0 (https://github.com/joshdholtz/jsonapi-ios/pull/34). Thanks to [RafaelKayumov](https://github.com/RafaelKayumov) for helping!
26
+
**1.0.4** | Add support for empty to-one relationship according to JSON API v1.0 (https://github.com/joshdholtz/jsonapi-ios/pull/33). Thanks to [RafaelKayumov](https://github.com/RafaelKayumov) for helping!
26
27
**1.0.3** | Add ability to map different types of objects (https://github.com/joshdholtz/jsonapi-ios/pull/32). Thanks to [ealeksandrov](https://github.com/ealeksandrov) for helping!
27
28
**1.0.2** | Just some bug fixes. Thanks to [christianklotz](https://github.com/christianklotz) for helping again!
28
29
**1.0.1** | Now safely checks for `NSNull` in the parsed JSON. Thanks to [christianklotz](https://github.com/christianklotz) for that fix!
@@ -47,23 +48,40 @@ Clone the repository and drop in the .h and .m files from the "Classes" director
47
48
JSONAPI is available through [CocoaPods](http://cocoapods.org), to install
48
49
it simply add the following line to your Podfile:
49
50
50
-
pod 'JSONAPI', '~> 1.0.0'
51
+
pod 'JSONAPI', '~> 1.0.6'
51
52
52
-
## Usage
53
+
## Classes/protocols
53
54
For some full examples on how to use everything, please see the tests - https://github.com/joshdholtz/jsonapi-ios/blob/master/Project/JSONAPITests/JSONAPITests.m
54
55
55
56
### JSONAPI
56
57
`JSONAPI` parses and validates a JSON API document into a usable object. This object holds the response as an NSDictionary but provides methods to accomdate the JSON API format such as `meta`, `errors`, `linked`, `resources`, and `includedResources`.
57
58
58
59
### JSONAPIResource
59
-
`JSONAPIResource` is an object (that gets subclassed) that holds data for each resource in a JSON API document. This objects holds the "id" as `ID` and link for self as `selfLink` as well as attributes and relationships defined by descriptors (see below)
60
+
Protocol of an object that is available for JSON API serialization. When developing model classes for use with JSON-API, it is suggested that classes be derived from `JSONAPIResourceBase`, but that is not required. An existing model class can be adapted for JSON-API by implementing this protocol.
60
61
61
-
#### Resource mappings (using descriptors)
62
+
### JSONAPIResourceBase
63
+
`JSONAPIResourceBase` is an object (that gets subclassed) that holds data for each resource in a JSON API document. This objects holds the "id" as `ID` and link for self as `selfLink` as well as attributes and relationships defined by descriptors (see below)
64
+
65
+
### JSONAPIResourceDescriptor
62
66
`+ (JSONAPIResourceDescriptor*)descriptor` should be overwritten to define descriptors for mapping of JSON keys and relationships into properties of a subclassed JSONAPIResource.
Sometimes you may have parts of a resource that need to get mapped to something more specific than just an `NSDictionary`. Below is an example on how to map an `NSDictionary` to non-JSONAPIResource models.
196
+
197
+
We are essentially creating a property descriptor that maps to a private property on the resource. We then override that properties setter and do our custom mapping there.
198
+
199
+
#### Resource part of JSON API Response
200
+
```js
201
+
"attributes":{
202
+
"title": "Something something blah blah blah"
203
+
"image": {
204
+
"large": "http://someimageurl.com/large",
205
+
"medium": "http://someimageurl.com/medium",
206
+
"small": "http://someimageurl.com/small"
207
+
}
208
+
}
209
+
```
210
+
211
+
#### ArticleResource.h
212
+
213
+
```objc
214
+
215
+
@interfaceArticleResource : JSONAPIResourceBase
216
+
217
+
@property (nonatomic, strong) NSString *title;
218
+
219
+
// The properties we are pulling out of a a "images" dictionary
0 commit comments