Geen omschrijving

FKBrandSubscribeRequest.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // FKBrandSubscribeRequest.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/4/25.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBrandSubscribeRequest.h"
  9. @implementation FKBrandSubscribeRequest
  10. + (void)requestBrandWithCategoryID:(NSString *)categoryID
  11. subscribe:(NSString *)subscribe
  12. identify:(int)identify
  13. delegate:(id<FLNetworkDelegate>)delegate {
  14. NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/search/search_brand_by_category.json", [[FKServerUtil sharedInstance] apiServer]];
  15. NSString *itemJson = [FLRequestHelper JSONStringWithKeys:@[@"front_category_id", @"subscribe"]
  16. values:@[[FLStringHelper replaceNilWithEmpty:categoryID], [FLStringHelper replaceNilWithEmpty:subscribe]]];
  17. NSMutableDictionary *para = [NSMutableDictionary dictionary];
  18. [para setValue:itemJson forKey:@"search_json"];
  19. [para addEntriesFromDictionary:[FLRequestHelper commonParamater]];
  20. [[FLDataCenter sharedDataCenter] POST:urlString para:para identify:identify delegate:delegate];
  21. }
  22. + (void)requestMyBrand:(int)identify delegate:(id<FLNetworkDelegate>)delegate {
  23. NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/subscribe/my_subscribe_brands.json", [[FKServerUtil sharedInstance] apiServer]];
  24. [[FLDataCenter sharedDataCenter] POST:urlString para:[FLRequestHelper commonParamater] identify:identify delegate:delegate];
  25. }
  26. + (void)requestCreateSubscribe:(NSArray *)ids identify:(int)identify delegate:(id<FLNetworkDelegate>)delegate {
  27. NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/subscribe/create_subscribe.json", [[FKServerUtil sharedInstance] apiServer]];
  28. NSString *itemJson = [FKBrandSubscribeRequest subscribeJSONString:ids];
  29. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  30. [dict setValue:[FLStringHelper replaceNilWithEmpty:itemJson] forKey:@"subscribe_json"];
  31. [dict addEntriesFromDictionary:[FLRequestHelper commonParamater]];
  32. [[FLDataCenter sharedDataCenter] POST:urlString para:dict identify:identify delegate:delegate];
  33. }
  34. + (void)requestCancelSubscribe:(NSArray *)ids identify:(int)identify delegate:(id<FLNetworkDelegate>)delegate {
  35. NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/subscribe/cancel_subscribe.json", [[FKServerUtil sharedInstance] apiServer]];
  36. NSString *itemJson = [FKBrandSubscribeRequest subscribeJSONString:ids];
  37. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  38. [dict setValue:[FLStringHelper replaceNilWithEmpty:itemJson] forKey:@"subscribe_json"];
  39. [dict addEntriesFromDictionary:[FLRequestHelper commonParamater]];
  40. [[FLDataCenter sharedDataCenter] POST:urlString para:dict identify:identify delegate:delegate];
  41. }
  42. + (NSString *)subscribeJSONString:(NSArray *)ids {
  43. NSMutableArray *mutableArray = [NSMutableArray array];
  44. NSMutableDictionary *dict;
  45. for (NSString *value in ids) {
  46. dict = [NSMutableDictionary dictionary];
  47. [dict setValue:@"14" forKey:@"type"];
  48. [dict setValue:value forKey:@"value"];
  49. [mutableArray addObject:dict];
  50. }
  51. NSError *error;
  52. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:mutableArray
  53. options:NSJSONWritingPrettyPrinted
  54. error:&error];
  55. if (!jsonData) {
  56. return nil;
  57. }
  58. return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  59. }
  60. @end