// // FamilyContact.m // tongxin // // Created by ecell on 2021/7/15. // Copyright © 2021 xTT. All rights reserved. // #import "FamilyContact.h" #import "Device.h" #import "User.h" @implementation FamilyContact -(void)save:(FamilyContact *)familyContact success:(void (^)(void))success failure:(void (^)(NSError *error))failure{ NSString *urlStr = HTTP_FAMILY__CONTACT; NSMutableDictionary *parameter = [NSMutableDictionary dictionary]; [parameter setValue:familyContact.number forKey:@"number"]; [parameter setValue:familyContact.name forKey:@"name"]; [parameter setValue:familyContact.phone forKey:@"phone"]; [parameter setValue:cUser.cDevice.imei forKey:@"imei"]; [parameter setValue:@"1" forKey:@"type"]; [xMyHttp URL:urlStr method:@"POST" parameters:parameter success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"result"] intValue] == 1) { success(); } else { if (failure) { NSString *domain = @"com.zuoyebang.iot.watch"; NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]}; NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo]; failure(err); } } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } }]; } -(void)update:(FamilyContact *)familyContact success:(void (^)(void))success failure:(void (^)(NSError *error))failure { NSString *urlStr = HTTP_FAMILY__CONTACT; NSMutableDictionary *parameter = [NSMutableDictionary dictionary]; [parameter setValue:familyContact.number forKey:@"number"]; [parameter setValue:familyContact.name forKey:@"name"]; [parameter setValue:familyContact.phone forKey:@"phone"]; [parameter setValue:cUser.cDevice.imei forKey:@"imei"]; [parameter setValue:familyContact.id forKey:@"id"]; [parameter setValue:@"1" forKey:@"type"]; [xMyHttp URL:urlStr method:@"PATCH" parameters:parameter success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"result"] intValue] == 1) { success(); } else { if (failure) { NSString *domain = @"com.zuoyebang.iot.watch"; NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]}; NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo]; failure(err); } } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } }]; } -(void)query:(void (^)(NSMutableArray *arr))success failure:(void (^)(NSError *error))failure { NSString *urlStr = HTTP_FAMILY__CONTACT; NSMutableDictionary *parameter = [NSMutableDictionary dictionary]; [parameter setValue:cUser.cDevice.imei forKey:@"imei"]; [parameter setValue:@"1" forKey:@"type"]; [xMyHttp URL:urlStr method:@"GET" parameters:parameter success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"result"] intValue] == 1) { NSMutableArray *arr = [FamilyContact mj_objectArrayWithKeyValuesArray:responseObject[@"familyPhones"]]; success(arr); } else { if (failure) { NSString *domain = @"com.zuoyebang.iot.watch"; NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]}; NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo]; failure(err); } } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } }]; } -(void)deleteOne:(NSString *)cid imei:(NSString *)imei success:(void (^)(void))success failure:(void (^)(NSError *error))failure { NSString *urlStr = HTTP_FAMILY__CONTACT; NSMutableDictionary *parameter = [NSMutableDictionary dictionary]; [parameter setValue:cUser.cDevice.imei forKey:@"imei"]; [parameter setValue:cid forKey:@"id"]; [parameter setValue:@"1" forKey:@"type"]; [xMyHttp URL:urlStr method:@"DELETE" parameters:parameter success:^(NSURLSessionDataTask *task, id responseObject) { if ([responseObject[@"result"] intValue] == 1) { success(); } else { if (failure) { NSString *domain = @"com.zuoyebang.iot.watch"; NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]}; NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo]; failure(err); } } } failure:^(NSURLSessionDataTask *task, NSError *error) { if (failure) { failure(error); } }]; } @end