No Description

FKBookPreferRequest.m 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // FKBookPreferRequest.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/5/12.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBookPreferRequest.h"
  9. #import "FKPreferItem.h"
  10. @implementation FKBookPreferRequest
  11. + (void)reqPreferListWithIdentify:(int)identify
  12. delegate:(id<FLNetworkDelegate>)delegate{
  13. NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/subscribe/my_subscribe_settings.json", [[FKServerUtil sharedInstance] apiServer]];
  14. NSString *jsonStr = [FLRequestHelper JSONStringWithKeys:@[@"type"] values:@[@(16)]];
  15. NSMutableDictionary *dictM = [NSMutableDictionary dictionaryWithDictionary:[FLRequestHelper commonParamater]];
  16. [dictM setObject:jsonStr forKey:@"subscribe_json"];
  17. [[FLDataCenter sharedDataCenter] POST:urlString
  18. para:dictM
  19. identify:identify
  20. delegate:delegate];
  21. }
  22. + (void)requestCreatePreferList:(NSArray *)preferList
  23. identify:(int)identify
  24. delegate:(id<FLNetworkDelegate>)delegate{
  25. NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/subscribe/save_subscribe_settings.json", [[FKServerUtil sharedInstance] apiServer]];
  26. NSString *itemJson = [self subscribeJSONString:preferList];
  27. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  28. [dict setValue:[FLStringHelper replaceNilWithEmpty:itemJson] forKey:@"subscribe_json"];
  29. [dict addEntriesFromDictionary:[FLRequestHelper commonParamater]];
  30. [[FLDataCenter sharedDataCenter] POST:urlString
  31. para:dict
  32. identify:identify
  33. delegate:delegate];
  34. }
  35. + (NSString *)subscribeJSONString:(NSArray *)ids {
  36. NSMutableArray *mutableArray = [NSMutableArray array];
  37. NSMutableDictionary *dict;
  38. for (FKPreferItem *item in ids) {
  39. dict = [NSMutableDictionary dictionary];
  40. [dict setValue:@"16" forKey:@"type"];
  41. [dict setValue:(item.selected ? @1 : @0) forKey:@"status"];
  42. [dict setValue:[FLStringHelper replaceNilWithEmpty:item.itemId] forKey:@"value"];
  43. [mutableArray addObject:dict];
  44. }
  45. NSError *error;
  46. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:mutableArray
  47. options:NSJSONWritingPrettyPrinted
  48. error:&error];
  49. if (!jsonData) {
  50. return nil;
  51. }
  52. return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  53. }
  54. @end