单军华
2017-07-12 20d1260d26b028897f3c0935c12fc35aa37b2e93
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
 
/*!
 *  @header BAKit.h
 *          BABaseProject
 *
 *  @brief  BAKit
 *
 *  @author 博爱
 *  @copyright    Copyright © 2016年 博爱. All rights reserved.
 *  @version    V1.0
 */
 
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                            O\ = /O
//                        ____/`---'\____
//                      .   ' \\| |// `.
//                       / \\||| : |||// \
//                     / _||||| -:- |||||- \
//                       | | \\\ - /// | |
//                     | \_| ''\---/'' | |
//                      \ .-\__ `-` ___/-. /
//                   ___`. .' /--.--\ `. . __
//                ."" '< `.___\_<|>_/___.' >'"".
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |
//                 \ \ `-. \_ __\ /__ _/ .-` / /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//
//         .............................................
//                  佛祖镇楼                  BUG辟易
//          佛曰:
//                  写字楼里写字间,写字间里程序员;
//                  程序人员写程序,又拿程序换酒钱。
//                  酒醒只在网上坐,酒醉还来网下眠;
//                  酒醉酒醒日复日,网上网下年复年。
//                  但愿老死电脑间,不愿鞠躬老板前;
//                  奔驰宝马贵者趣,公交自行程序员。
//                  别人笑我忒疯癫,我笑自己命太贱;
//                  不见满街漂亮妹,哪个归得程序员?
 
/*
 
 *********************************************************************************
 *
 * 在使用BAKit的过程中如果出现bug请及时以以下任意一种方式联系我,我会及时修复bug
 *
 * QQ     : 博爱1616【137361770】
 * 微博    : 博爱1616
 * Email  : 137361770@qq.com
 * GitHub : https://github.com/boai
 * 博客园  : http://www.cnblogs.com/boai/
 * 博客    : http://boai.github.io
 
 *********************************************************************************
 
 */
 
#import "BANewsNetManager.h"
#import "BAURLsPath.h"
 
#import "NSObject+BAMJParse.h"
#import "BaseResModel.h"
//#import "DemoVC11_model.h"
 
//static AFHTTPSessionManager *manger = nil;
 
@implementation BANewsNetManager
 
/*!
 *  示例1:DemoVC1中的网络获取示例
 *
 *  @param startIndex index
 *
 *  @return DemoVC1中的网络获取示例
 */
+ (id)getVideosWithStartIndex:(NSInteger)startIndex completionHandle:(void (^)(id, NSError *))completionHandle
{
    NSString *path = [NSString stringWithFormat:KVideoPath, startIndex];
    
//    return [self BA_GET_Url:path parameters:nil response:BAResponseStyleJSON requestHeadFile:nil completionHandle:^(id model, NSError *error) {
//        
//        completionHandle([BAVideoModel BAMJParse:model], error);
//    }];
    return [BANetManager ba_requestWithType:BAHttpRequestTypeGet UrlString:path Parameters:nil SuccessBlock:^(id response) {
        
        completionHandle([BaseResModel ModelParse:response], nil);
        
    } FailureBlock:^(NSError *error) {
        
        LOG_INFO(@"error:%@", error);
        completionHandle(nil, error);
 
    } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
        
    }];
}
 
/*!
 *  示例2:DemoVC11中的网络获取示例
 *
 *  @return DemoVC11中的网络获取示例
 */
+ (id)getDemoVC11DataCompletionHandle:(void(^)(id model, NSError *error))completionHandle
{
    return [BANetManager ba_requestWithType:BAHttpRequestTypeGet UrlString:DemoVC11URLPath Parameters:nil SuccessBlock:^(id response) {
        
        /*! 
         获取的字典示例:
         
         {
         description = "Hi\Uff0c\U6d17\U526a\U5439";
         height = 1600;
         id = 13328041;
         "photo_url" = "http://p.chanyouji.cn/333978/1451945850044p1a879bbtem71udn1ujh1aaa1h9958.jpg";
         "trip_id" = 333978;
         width = 1068;
         },
         {
         description = "";
         height = 1600;
         id = 14015158;
         "photo_url" = "http://p.chanyouji.cn/1456589788/B078C994-6D71-4811-80BE-653D01C3A2A1.jpg";
         "trip_id" = 361477;
         width = 1600;
         }
         
         */
        
    completionHandle([BaseResModel ModelParse:response], nil);
        
    } FailureBlock:^(NSError *error) {
        
        LOG_INFO(@"error:%@", error);
        completionHandle(nil, error);
        
    } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
        
    }];
}
 
/*!
 *  示例3:DemoVC11中的网络获取示例 post
 *
 *  @return DemoVC11中的网络获取示例
 */
+ (id)postDemoVC11DataWithParameters:parameters completionHandle:(void(^)(id model, NSError *error))completionHandle
{
//    NSString *url = [NSString stringWithFormat:@"%@%@", DemoVC11URLPath2, parameters[@"page"]];
    return [BANetManager ba_requestWithType:BAHttpRequestTypePost UrlString:DemoVC11URLPath2 Parameters:parameters SuccessBlock:^(id response) {
        completionHandle([BaseResModel ModelParse:response], nil);
    } FailureBlock:^(NSError *error) {
        LOG_INFO(@"error:%@", error);
        completionHandle(nil, error);
    } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
        
    }];
}
 
 
// 测试用例
//BA_WEAKSELF;
//[BANewsNetManager getVideosWithStartIndex:1 completionHandle:^(id model, NSError *error) {
//    
//    //        [weakSelf BA_hideProgress];
//    [weakSelf ba_showBallLoadingView:NO];
//    
//    if (!error)
//    {
//        BALog(@"model: %@", model);
//        [weakSelf BA_showAlertWithTitle:@"数据解析成功!请查看!"];
//    }
//    else
//    {
//        BALog(@"解析数据有误!");
//        //            [self BA_showAlertWithTitle:@"解析数据有误!请检查!"];
//    }
//}];
 
@end