YH_NetworkAdapter+Live.m 7.5 KB
//
//  YH_NetworkAdapter+Live.m
//  yohoLive
//
//  Created by 孟顺 on 16/8/18.
//  Copyright © 2016年 NewPower. All rights reserved.
//

#import "YH_NetworkAdapter+Live.h"
#import "UtilsMacros.h"

@implementation YH_NetworkAdapter (Live)

- (void)getRoomWithSecret:(NSString *)secret completion:(DictionaryBlock)finishBlock {
    NSDictionary *param = @{
                            @"secret":secret,
                            };
    [[YH_HttpEngine roomEngine] get:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"code"] integerValue] != 200) {
            NSError *anError = [NSError errorWithDomain:@"live" code:[responseObject[@"code"] integerValue] userInfo:@{}];
            BLOCK_EXEC(finishBlock, nil, anError);
        }else{
            BLOCK_EXEC(finishBlock, responseObject[@"data"],nil);
        }
        DLog(@"%@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        BLOCK_EXEC(finishBlock, nil,error);
        DLog(@"%@",error);
    }];
}

- (void)getPushListFinished:(DictionaryBlock)finishBlock {
    
    [[YH_HttpEngine roomListEngine] get:@{} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"code"] integerValue] != 200) {
            NSError *anError = [NSError errorWithDomain:@"live" code:[responseObject[@"code"] integerValue] userInfo:@{}];
            BLOCK_EXEC(finishBlock, nil, anError);
        }else{
            BLOCK_EXEC(finishBlock, responseObject,nil);
        }
        DLog(@"%@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        BLOCK_EXEC(finishBlock, nil,error);
        DLog(@"%@",error);
    }];
}

- (void)setStatusWithStat:(PushStatus)status andRoomId:(NSString *)room completion:(BoolBlock)block {
    NSDictionary *param = @{
                            @"room_id":room?:@"",
                            @"living_stat":@(status),
                            };
    [[YH_HttpEngine pushStatusEngine] get:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"code"] integerValue] != 200) {
            NSError *anError = [NSError errorWithDomain:@"live" code:[responseObject[@"code"] integerValue] userInfo:@{}];
            BLOCK_EXEC(block, NO, anError);
        }else{
            BLOCK_EXEC(block, YES,nil);
        }
        DLog(@"%@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        BLOCK_EXEC(block, NO,error);
        DLog(@"%@",error);
    }];
}

- (void)validateAnchorWithSecret:(NSString *)secret andRoomId:(NSString *)room completion:(BoolBlock)block {
    NSDictionary *param = @{
                            @"room_id":room,
                            @"secret":secret,
                            };
    [[YH_HttpEngine pushStatusEngine] get:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"code"] integerValue] != 200) {
            NSError *anError = [NSError errorWithDomain:@"live" code:[responseObject[@"code"] integerValue] userInfo:@{}];
            BLOCK_EXEC(block, NO, anError);
        }else{
            BLOCK_EXEC(block, YES,nil);
        }
        DLog(@"%@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        BLOCK_EXEC(block, NO,error);
        DLog(@"%@",error);
    }];
}

- (void)getLiveBarrageSocketAddressWithParam:(NSDictionary *)param completion:(DictionaryBlock)finishBlock {
    [[YH_HttpEngine socketAddrEngine] get:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        BLOCK_EXEC(finishBlock, responseObject,nil);
        NSLog(@"%@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        BLOCK_EXEC(finishBlock, nil,error);
        NSLog(@"%@",error);
    }];
}

- (void)getSknListDataFromRoomID:(NSString *)roomID completion:(ArrayBlock)finishBlock
{
    if (IsStrEmpty(roomID)) {
        BLOCK_EXEC(finishBlock, nil,[[NSError alloc] initWithDomain:@"liveDomain" code:-1000 userInfo:@{}]);
        return;
    }
    
    NSDictionary *paramDic = @{@"room_id":roomID};
    [[YH_HttpEngine liveEngine] get:paramDic resourcePath:@"/v1/product/list" success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSArray *sknArray = responseObject[@"data"];
        if ([sknArray isKindOfClass:[NSArray class]]) {
            BLOCK_EXEC(finishBlock, sknArray,nil);
        } else {
            BLOCK_EXEC(finishBlock, [NSArray array],nil);
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        BLOCK_EXEC(finishBlock, nil,error);
    }];
}

- (void)getProductListDataFromSknString:(NSString *)sknString completion:(DictionaryBlock)finishBlock
{
    if (IsStrEmpty(sknString)) {
        BLOCK_EXEC(finishBlock, nil,[[NSError alloc] initWithDomain:@"liveDomain" code:-1000 userInfo:@{}]);
        return;
    }
    
    NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
    [paramDic setObject:sknString forKey:@"productSkn"];
    [paramDic setObject:@"h5.product.batch" forKey:@"method"];
    [paramDic setObject:@"Y" forKey:@"contain_secKill"];
    
    [[YH_HttpEngine apiEngine] get:paramDic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dataDic = [responseObject objectForKey:@"data"];
        if ([dataDic.allKeys count]>0) {
            BLOCK_EXEC(finishBlock, dataDic,nil);
        } else {
            BLOCK_EXEC(finishBlock, [NSDictionary dictionary],nil);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        BLOCK_EXEC(finishBlock, nil,error);
    }];
    
}

- (void)getCouponDataWithRoomId:(NSString *)roodId completion:(DictionaryBlock)finishBlock {
    NSDictionary *params = @{
                             @"room_id":roodId?:@"",
                             @"app":@(1),
                             };
    [[YH_HttpEngine liveEngine] get:params resourcePath:@"/v1/coupon/detail" success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        if ([responseObject[@"code"] integerValue] == 200) {
            BLOCK_EXEC(finishBlock, responseObject[@"data"],nil);
        } else {
            BLOCK_EXEC(finishBlock, responseObject,nil);
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        BLOCK_EXEC(finishBlock, nil,error);
    }];
}

- (void)getRedPacketsWithRoomId:(NSString *)roomId completion:(ArrayBlock)block {
    
    NSDictionary *params = @{
                             @"room_id":roomId?:@"",
                             };
    [[YH_HttpEngine liveEngine] get:params resourcePath:@"/v1/redbag/pushbaglist" success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        if ([responseObject[@"code"] integerValue] == 200) {
            BLOCK_EXEC(block, responseObject[@"data"],nil);
        } else {
            BLOCK_EXEC(block, responseObject,nil);
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        BLOCK_EXEC(block, nil,error);
    }];
}

- (void)sendInterfaceHeartBeatWithRoomId:(NSString *)roomId {
    NSDictionary *params = @{
                             @"room_id":roomId?:@"",
                             };
    [[YH_HttpEngine liveEngine] get:params resourcePath:@"/v1/room/keeplive" success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        if ([responseObject[@"code"] integerValue] == 200) {

        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];
}
@end