1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- //
- // FKBookPreferRequest.m
- // FirstLink
- //
- // Created by jack on 16/5/12.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKBookPreferRequest.h"
- #import "FKPreferItem.h"
- @implementation FKBookPreferRequest
- + (void)reqPreferListWithIdentify:(int)identify
- delegate:(id<FLNetworkDelegate>)delegate{
-
- NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/subscribe/my_subscribe_settings.json", [[FKServerUtil sharedInstance] apiServer]];
-
- NSString *jsonStr = [FLRequestHelper JSONStringWithKeys:@[@"type"] values:@[@(16)]];
-
- NSMutableDictionary *dictM = [NSMutableDictionary dictionaryWithDictionary:[FLRequestHelper commonParamater]];
- [dictM setObject:jsonStr forKey:@"subscribe_json"];
-
- [[FLDataCenter sharedDataCenter] POST:urlString
- para:dictM
- identify:identify
- delegate:delegate];
-
- }
- + (void)requestCreatePreferList:(NSArray *)preferList
- identify:(int)identify
- delegate:(id<FLNetworkDelegate>)delegate{
-
- NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/subscribe/save_subscribe_settings.json", [[FKServerUtil sharedInstance] apiServer]];
-
- NSString *itemJson = [self subscribeJSONString:preferList];
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setValue:[FLStringHelper replaceNilWithEmpty:itemJson] forKey:@"subscribe_json"];
- [dict addEntriesFromDictionary:[FLRequestHelper commonParamater]];
-
- [[FLDataCenter sharedDataCenter] POST:urlString
- para:dict
- identify:identify
- delegate:delegate];
- }
- + (NSString *)subscribeJSONString:(NSArray *)ids {
- NSMutableArray *mutableArray = [NSMutableArray array];
- NSMutableDictionary *dict;
-
- for (FKPreferItem *item in ids) {
- dict = [NSMutableDictionary dictionary];
- [dict setValue:@"16" forKey:@"type"];
- [dict setValue:(item.selected ? @1 : @0) forKey:@"status"];
- [dict setValue:[FLStringHelper replaceNilWithEmpty:item.itemId] forKey:@"value"];
-
- [mutableArray addObject:dict];
- }
-
- NSError *error;
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:mutableArray
- options:NSJSONWritingPrettyPrinted
- error:&error];
-
- if (!jsonData) {
- return nil;
- }
-
- return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- }
- @end
|