RQHTTPResponse.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // RQHTTPResponse.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/16.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. //
  8. #import "RQHTTPResponse.h"
  9. #import "RQHTTPServiceConstant.h"
  10. @interface RQHTTPResponse ()
  11. /// The parsed RQObject object corresponding to the API response.
  12. /// The developer need care this data
  13. @property (nonatomic, readwrite, strong) id parsedResult;
  14. /// 自己服务器返回的状态码
  15. @property (nonatomic, readwrite, assign) RQHTTPResponseCode code;
  16. /// 自己服务器返回的信息
  17. @property (nonatomic, readwrite, copy) NSString *msg;
  18. @end
  19. @implementation RQHTTPResponse
  20. - (instancetype)initWithResponseObject:(id)responseObject parsedResult:(id)parsedResult {
  21. self = [super init];
  22. if (self) {
  23. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  24. NSDictionary *dic = responseObject;
  25. NSMutableDictionary *mydic = dic.mutableCopy;
  26. if ([mydic.allKeys containsObject:@"path"]) {
  27. self.parsedResult = parsedResult ?:NSNull.null;
  28. self.code = [responseObject[RQHTTPServiceResponseCodeKey] integerValue];
  29. self.msg = responseObject[RQHTTPServiceResponseMsgKey];
  30. } else {
  31. self.parsedResult = parsedResult ?:NSNull.null;
  32. self.code = [responseObject[RQHTTPServiceResponseCodeKey] integerValue];
  33. self.msg = responseObject[RQHTTPServiceResponseMsgKey];
  34. }
  35. } else {
  36. self.parsedResult = parsedResult ?:NSNull.null;
  37. self.code = [responseObject[RQHTTPServiceResponseCodeKey] integerValue];
  38. self.msg = responseObject[RQHTTPServiceResponseMsgKey];
  39. }
  40. }
  41. return self;
  42. }
  43. @end