// // HBNetWorkingUtility+Services.m // QinJiuTV // // Created by HI_LOSER on 2024/5/28. // #import "HBNetWorkingUtility+Services.h" @implementation HBNetWorkingUtility (Commom) + (void)commom_deviceRegisterWithComplateBlock:(nullable HBResponseComplateBlock)complateBlock { if([NSUserDefaults boolForKey:HBCustomerLoginSuccessKey]) return; NSError * error = nil; NSString * identifierForVendor = [SAMKeychain passwordForService:[UIDevice bundleIdentifier] account:HBIdentifierForVendorKey error:&error]; if ([NSString empty:identifierForVendor] || error) { identifierForVendor = [UIDevice identifierForVendor]; [SAMKeychain setPassword:identifierForVendor forService:[UIDevice bundleIdentifier] account:HBIdentifierForVendorKey]; } NSDictionary * headers = @{ @"Authorization": @"", @"device-id": identifierForVendor, @"system-type": @"ios", @"model":[UIDevice model], @"system-version": [UIDevice systemVersion], @"brand": @"ios", @"app-version": [UIDevice appVersion] }; [HBNetWorkingUtility requestWithHTTPMethod:HTTPMethodPost api:@"customer/register" headers:headers parameters:nil response:^(HBNetWorkingUtilityResult * _Nullable result) { if (result.success) { [NSUserDefaults setObject:result.data[@"token"] forKey:HBNetWorkingTokenKey]; [NSUserDefaults setObject:result.data[@"customer_id"] forKey:HBCustomerIdKey]; } if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)commom_fetchBannersWithComplateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"getBanners" parameters:nil response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)common_searchVideosWithKey:(NSString *) key complateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"videoList" parameters:@{@"search":key} response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } @end @implementation HBNetWorkingUtility (home) + (void)home_fetchCategoriesWithComplateBlock:(nullable HBResponseComplateBlock)complateBlock{ [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"getHomeCategories" parameters:nil response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } @end @implementation HBNetWorkingUtility (Customer) + (void)customer_thirdLoginWithParams:(NSDictionary *) params complateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodPost api:@"customer/login" parameters:params response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)customer_logoutWithComplateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodPost api:@"customer/signout" parameters:nil response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) { [NSUserDefaults setObject:result.data[@"token"] forKey:HBNetWorkingTokenKey]; [NSUserDefaults setObject:result.data[@"customer_id"] forKey:HBCustomerIdKey]; complateBlock(result.success,result.data,result.message); } }]; } + (void)customer_signoutWithComplateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodPost api:@"customer/logoff" parameters:nil response:^(HBNetWorkingUtilityResult * _Nullable result) { if (result.success) [HBNetWorkingUtility commom_deviceRegisterWithComplateBlock:nil]; if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)customer_fetchUserInfoWithComplateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"customer/info" parameters:nil response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)customer_favoriteWithVideoId:(NSInteger )vId complateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodPost api:@"collect" parameters:@{@"short_video_id" : @(vId)} response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)customer_unFavoriteWithVideoId:(NSInteger )vId complateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodPost api:@"cancelCollect" parameters:@{@"short_video_id" : @(vId)} response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)customer_fetchFavoriteListWithComplateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"myCollections" parameters:nil response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } @end @implementation HBNetWorkingUtility (videos) + (void)videos_fetchCategoriesWithComplateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"getCategories" parameters:nil response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)videos_fetchCategoryVideosWithId:(NSInteger)cid complateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"videoList" parameters:@{@"category_id":@(cid)} response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)videos_fetchVideoDetailsWithSid:(NSInteger)sId complateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"getVideoDetails" parameters:@{@"short_video_id":@(sId)} response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)videos_uploadPlayHistoryWithSid:(NSInteger)sId vId:(NSInteger)vId complateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodPost api:@"createHistory" parameters:@{@"short_video_id":@(sId),@"video_id":@(vId)} response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } + (void)videos_fetchVisitTopWithComplateBlock:(nullable HBResponseComplateBlock)complateBlock { [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"getVisitTop" parameters:nil response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } @end @implementation HBNetWorkingUtility (Discover) + (void)discover_fetchRecommandsWithPage:(NSInteger)page size:(NSInteger)size complateBlock:(nullable HBResponseComplateBlock) complateBlock { NSDictionary * parmes = @{@"page_size":@(size), @"current_page":@(page)}; [HBNetWorkingUtility tokenRequestWithHTTPMethod:HTTPMethodGet api:@"getRecommands" parameters:parmes response:^(HBNetWorkingUtilityResult * _Nullable result) { if (complateBlock) complateBlock(result.success,result.data,result.message); }]; } @end