From 10aa379f17db49e78b526b9b12ad482bb58e1731 Mon Sep 17 00:00:00 2001 From: Night Tempo Date: Wed, 26 Oct 2016 17:01:27 +0900 Subject: [PATCH 1/4] add source's pointer, parameter --- Classes/JSONAPIErrorResource.h | 4 ++++ Classes/JSONAPIErrorResource.m | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Classes/JSONAPIErrorResource.h b/Classes/JSONAPIErrorResource.h index 31a285e..9489035 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 *)pointer; +- (NSString *)parameter; + @end diff --git a/Classes/JSONAPIErrorResource.m b/Classes/JSONAPIErrorResource.m index f2d2e79..ba447eb 100644 --- a/Classes/JSONAPIErrorResource.m +++ b/Classes/JSONAPIErrorResource.m @@ -24,9 +24,28 @@ - (instancetype) initWithDictionary:(NSDictionary*)dictionary { _detail = dictionary[@"detail"]; _links = dictionary[@"links"]; _paths = dictionary[@"paths"]; + _source = dictionary[@"source"]; } return self; } +- (NSString *)pointer +{ + if (self.source) { + return self.source[@"pointer"];; + } + + return nil; +} + +- (NSString *)parameter +{ + if (self.source) { + return self.source[@"parameter"]; + } + + return nil; +} + @end From b9f7f202865479889192bd5c6763212204d13efd Mon Sep 17 00:00:00 2001 From: Kyungho Jung Date: Wed, 26 Oct 2016 22:34:08 +0900 Subject: [PATCH 2/4] put pointer, parameter nil check --- Classes/JSONAPIErrorResource.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Classes/JSONAPIErrorResource.m b/Classes/JSONAPIErrorResource.m index ba447eb..de3f2cd 100644 --- a/Classes/JSONAPIErrorResource.m +++ b/Classes/JSONAPIErrorResource.m @@ -33,7 +33,11 @@ - (instancetype) initWithDictionary:(NSDictionary*)dictionary { - (NSString *)pointer { if (self.source) { - return self.source[@"pointer"];; + NSString *pointer = self.source[@"pointer"]; + + if (pointer) { + return pointer; + } } return nil; @@ -42,7 +46,11 @@ - (NSString *)pointer - (NSString *)parameter { if (self.source) { - return self.source[@"parameter"]; + NSString *parameter = self.source[@"parameter"]; + + if (parameter) { + return parameter; + } } return nil; From e686ea31e527e524720509beeb94b908090ff731 Mon Sep 17 00:00:00 2001 From: Kyungho Jung Date: Wed, 26 Oct 2016 22:37:23 +0900 Subject: [PATCH 3/4] change pointer, parameter method name --- Classes/JSONAPIErrorResource.h | 4 ++-- Classes/JSONAPIErrorResource.m | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Classes/JSONAPIErrorResource.h b/Classes/JSONAPIErrorResource.h index 9489035..f72ceb3 100644 --- a/Classes/JSONAPIErrorResource.h +++ b/Classes/JSONAPIErrorResource.h @@ -25,7 +25,7 @@ - (instancetype) initWithDictionary:(NSDictionary*)dictionary; -- (NSString *)pointer; -- (NSString *)parameter; +- (NSString *)sourcePointer; +- (NSString *)sourceParameter; @end diff --git a/Classes/JSONAPIErrorResource.m b/Classes/JSONAPIErrorResource.m index de3f2cd..1861214 100644 --- a/Classes/JSONAPIErrorResource.m +++ b/Classes/JSONAPIErrorResource.m @@ -30,7 +30,7 @@ - (instancetype) initWithDictionary:(NSDictionary*)dictionary { return self; } -- (NSString *)pointer +- (NSString *)sourcePointer { if (self.source) { NSString *pointer = self.source[@"pointer"]; @@ -43,7 +43,7 @@ - (NSString *)pointer return nil; } -- (NSString *)parameter +- (NSString *)sourceParameter { if (self.source) { NSString *parameter = self.source[@"parameter"]; From c1308cfb48ed2eabaa5770ee19c50e60389b2a42 Mon Sep 17 00:00:00 2001 From: Kyungho Jung Date: Thu, 27 Oct 2016 00:27:32 +0900 Subject: [PATCH 4/4] source is must be key - value object (pointer or parameter) --- Project/JSONAPITests/error_example.json | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) 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" + } + }] +}