diff --git a/Classes/JSONAPIErrorResource.h b/Classes/JSONAPIErrorResource.h index 31a285e..f72ceb3 100644 --- a/Classes/JSONAPIErrorResource.h +++ b/Classes/JSONAPIErrorResource.h @@ -21,7 +21,11 @@ @property (nonatomic, strong) NSString *detail; @property (nonatomic, strong) NSArray *links; @property (nonatomic, strong) NSArray *paths; +@property (nonatomic, strong) NSDictionary *source; - (instancetype) initWithDictionary:(NSDictionary*)dictionary; +- (NSString *)sourcePointer; +- (NSString *)sourceParameter; + @end diff --git a/Classes/JSONAPIErrorResource.m b/Classes/JSONAPIErrorResource.m index f2d2e79..1861214 100644 --- a/Classes/JSONAPIErrorResource.m +++ b/Classes/JSONAPIErrorResource.m @@ -24,9 +24,36 @@ - (instancetype) initWithDictionary:(NSDictionary*)dictionary { _detail = dictionary[@"detail"]; _links = dictionary[@"links"]; _paths = dictionary[@"paths"]; + _source = dictionary[@"source"]; } return self; } +- (NSString *)sourcePointer +{ + if (self.source) { + NSString *pointer = self.source[@"pointer"]; + + if (pointer) { + return pointer; + } + } + + return nil; +} + +- (NSString *)sourceParameter +{ + if (self.source) { + NSString *parameter = self.source[@"parameter"]; + + if (parameter) { + return parameter; + } + } + + return nil; +} + @end diff --git a/Project/JSONAPITests/error_example.json b/Project/JSONAPITests/error_example.json index 473b589..3dd4889 100644 --- a/Project/JSONAPITests/error_example.json +++ b/Project/JSONAPITests/error_example.json @@ -9,13 +9,16 @@ }, "data": [], "errors": [{ - "id": "123456", - "href": "/internet/is/fun", - "status": "400", - "code": "123abc", - "title": "some title", - "detail": "some detail", - "links": ["a_link"], - "source": ["a_path"] - }] -} \ No newline at end of file + "id": "123456", + "href": "/internet/is/fun", + "status": "400", + "code": "123abc", + "title": "some title", + "detail": "some detail", + "links": ["a_link"], + "source": { + "pointer": "/some/point", + "parameter": "a_parameter" + } + }] +}