typedef void(^Callback)(id obj);
@interface ShouyeUtils : NSObject
+(void)GetShouyeUpButtonsWithCallback:(Callback)callback;
+(void)GetshouyeNewsWith:(NSString*)upButtonID andPage:(NSString *)pageandCallback:(Callback)callback;
//解析7个scrollerView的标题
//解析对应的cell的新闻内容
#import "ShouyeUtils.h"
#import "AFNetworking.h"
#import "ShouyeUpButtonItem.h"
#import "JsonParser.h"
@implementationShouyeUtils
+(void)GetShouyeUpButtonsWithCallback:(Callback)callback{
NSMutableArray *buttonItems = [NSMutableArray array];
NSString *path = @"http://api.hlj.sinosns.cn/api/v11/newsInfo/getDefNewsCol";
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]init];
[manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
[managerGET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObjectoptions:0error:nil];
NSArray *arr = dic[@"defCols"];
for (NSDictionary*d in arr) {
ShouyeUpButtonItem *item= [[ShouyeUpButtonItem alloc]init];
item.itemID = [d[@"id"] stringValue];
item.itemTitle = d[@"cTitle"];
[buttonItems addObject:item];
}
callback(buttonItems);
} failure:^(AFHTTPRequestOperation*operation, NSError *error) {
NSLog(@"请求首页上方按钮失败");
}];
}
+(void)GetshouyeNewsWith:(NSString*)upButtonID andPage:(NSString *)pageandCallback:(Callback)callback{
NSString *path = [NSString stringWithFormat:@"http://api.hlj.sinosns.cn/api/v11/newsInfo/getIndexByOptSliders/%@/all/%@",upButtonID,page];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]init];
[manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
[managerGET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObjectoptions:0error:nil];
NSArray *news = [JsonParser parserNewsWithDic:dic];
callback(news);
} failure:^(AFHTTPRequestOperation*operation, NSError *error) {
NSLog(@"请求首页新闻失败");
}];
}
@end