YH_NetworkAdapter+Live.m
7.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//
// 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