@@ -43,13 +43,13 @@ - (id) initWithNSDictionary:(NSDictionary *) dict {
4343}
4444
4545+ (instancetype ) payloadWithDictionary : (NSDictionary *) dict {
46- return [[self alloc ] initWithDictionary : dict];
46+ return [[self alloc ] initWithNSDictionary : dict];
4747}
4848
4949- (void ) addValueToPayload : (NSString *)value forKey : (NSString *)key {
5050 if (value == nil ) {
5151 [_payload removeObjectForKey: key];
52-
52+
5353 } else {
5454 [_payload setObject: value forKey: key];
5555 }
@@ -86,12 +86,12 @@ - (void)processParsedObject:(id)object depth:(int)depth parent:(id)parent key:(i
8686 else if ([object isKindOfClass: [NSNumber class ]])
8787 {
8888 NSString *num = [object stringValue ];
89-
89+
9090 if ([parent isKindOfClass: [NSArray class ]]) {
9191 NSUInteger idx = [((NSNumber *)key) intValue ];
92-
92+
9393 [parent replaceObjectAtIndex: idx withObject: num];
94-
94+
9595 } else {
9696 [parent setObject: num forKey: (NSString *)key];
9797 }
@@ -102,33 +102,33 @@ - (void) addDictionaryToPayload:(NSDictionary *)dict
102102 base64Encoded : (Boolean)encode
103103 typeWhenEncoded : (NSString *)typeEncoded
104104 typeWhenNotEncoded : (NSString *)typeNotEncoded {
105-
105+
106106 NSError * error = nil ;
107107 NSData *json = [NSJSONSerialization dataWithJSONObject: dict options: 0 error: &error];
108108 NSMutableDictionary *mdict = [NSJSONSerialization JSONObjectWithData: json options: NSJSONReadingAllowFragments |NSJSONReadingMutableContainers error: &error];
109109 json = [NSJSONSerialization dataWithJSONObject: [self processParsedObject: mdict] options: 0 error: &error];
110-
110+
111111 if (error) {
112112 LogError (@" addJsonToPayload: error: %@ " , error.userInfo );
113113 return ;
114114 }
115-
115+
116116 // Checks if it conforms to NSDictionary type
117117 if ([mdict isKindOfClass: [NSDictionary class ]]) {
118118 NSString *encodedString = nil ;
119119 if (encode) {
120120 encodedString = [json base64EncodedStringWithOptions: 0 ];
121-
121+
122122 // We need URL safe with no padding. Since there is no built-in way to do this, we transform
123123 // the encoded payload to make it URL safe by replacing chars that are different in the URL-safe
124124 // alphabet. Namely, 62 is - instead of +, and 63 _ instead of /.
125125 // See: https://tools.ietf.org/html/rfc4648#section-5
126126 encodedString = [[encodedString stringByReplacingOccurrencesOfString: @" /" withString: @" _" ]
127127 stringByReplacingOccurrencesOfString: @" +" withString: @" -" ];
128-
128+
129129 // There is also no padding since the length is implicitly known.
130130 encodedString = [encodedString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString: @" =" ]];
131-
131+
132132 [self addValueToPayload: encodedString forKey: typeEncoded];
133133 } else {
134134 [self addValueToPayload: [[NSString alloc ] initWithData: json encoding: NSUTF8StringEncoding] forKey: typeNotEncoded];
@@ -140,21 +140,21 @@ - (void) addJsonStringToPayload:(NSString *)json
140140 base64Encoded : (Boolean)encode
141141 typeWhenEncoded : (NSString *)typeEncoded
142142 typeWhenNotEncoded : (NSString *)typeNotEncoded {
143-
143+
144144 NSData *data = [json dataUsingEncoding: NSUTF8StringEncoding];
145145 NSError *error = nil ;
146146 NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingAllowFragments error: &error];
147-
147+
148148 if (error) {
149149 LogError (@" addJsonToPayload: error: %@ " , error.userInfo );
150150 return ;
151151 }
152-
152+
153153 [self addDictionaryToPayload: dict
154154 base64Encoded: encode
155155 typeWhenEncoded: typeEncoded
156156 typeWhenNotEncoded: typeNotEncoded];
157-
157+
158158}
159159
160160
0 commit comments