iOS-MAS-Foundation
iOS-MAS-Foundation copied to clipboard
MASRequestBuilder only accept dictionary as body
PR: https://github.com/CAAPIM/iOS-MAS-Foundation/pull/291
Currently the MASRequest builder only accepts an NSDictionary
as the request body. This is an issue as not all (of our) endpoints expect a dictionary as the root object of a request's body.
Some possible fixes could be to:
- use
id
as the body's type (this change does not existing impact users when they update). - use
NSData
as the body's type (breaking change and users have to encode the json themselves. Offers flexibility however). - Introduce a
JSONObject
class as the body's type (JSONObject would then be initializable with all valid json data types:NSNumber
,NSString
,Bool
,NSDictionary
,NSArray
, etc. This limits the amount of "valid" types a user could use to set the request body):
@interface MASJsonObject: NSObject @property (nonatomic, strong) id value; - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithString:(NSString *)string; - (instancetype)initWithBool:(BOOL)boolean; - (instancetype)initWithNumber:(NSNumber *)number; - (instancetype)initWithDictionary:(NSDictionary *)dictionary; - (instancetype)initWithArray:(NSArray *)array; @end @implementation MASJsonObject - (instancetype)initWithString:(NSString *)string { self = [super init]; if (self) { self.value = string; } return self; } // etc... @end