//
//  WTNetWorkManager.h
//  WTRequestCenter
//
//  Created by SongWentong on 10/26/15.
//  Copyright 漏 2015 song. All rights reserved.
//  https://github.com/swtlovewtt/WTRequestCenter

@import Foundation;
NS_ASSUME_NONNULL_BEGIN
@interface WTNetWorkManager : NSObject
+(instancetype)sharedKit;

//缂撳瓨
+(NSURLCache*)sharedURLcache;
@property (readonly, nonatomic, strong) NSURLSession *session;


@property (nonatomic,strong) NSLock *lock;
-(NSOperationQueue*)operationQueue;



/*!
 鏍规嵁璇锋眰瀵硅薄鐢熸垚瀵瑰簲鐨則ask,骞舵墽琛岃姹? 娉ㄦ剰:鎴愬姛鍜屽け璐ラ兘鏄垎绾跨▼鍥炶皟
 */
-(NSURLSessionDataTask*)taskWithRequest:(NSURLRequest*)request
                               finished:(nullable void(^)(NSData * data, NSURLResponse * response))finish
                                 failed:(nullable void(^)(NSError * error))failed;

/*!
 缂撳瓨寮忚姹?鍙紦瀛楪ET,涓嶉噸澶? */
-(NSURLSessionDataTask*)cachedTaskWithRequest:(NSURLRequest*)request
                    finished:(nullable void(^)(NSData * data, NSURLResponse * response))finish
                      failed:(nullable void(^)(NSError * error))failed;
@end

@interface WTNetWorkManager(CreatRequest)
/*!
 鏍规嵁璇锋眰鏂规硶,URL鍜屽弬鏁板垱寤轰竴涓姹傚璞? 
 method 浼犲叆瀵瑰簲鐨勬柟娉曞氨鍙互浜?姣斿GET,POST
 URLString 浼犲叆浣犵殑url
 parameters 鍙傛暟
 error  閿欒
 */
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
                                 URLString:(NSString *)URLString
                                parameters:(nullable NSDictionary*)parameters
                                     error:(NSError *__autoreleasing *)error;


/*!
 鏍规嵁url,鍙傛暟鍜屽搴旂殑鏁版嵁鏉ュ垱寤轰竴涓姹傚璞? 
 body 涓瓨鐨勬槸NSDictionary,鍖呭惈4涓唴瀹? name 鏄悕瀛? filename 鏄枃浠跺悕
 contentType 鏄唴瀹圭被鍨? content 鏄唴瀹? 鐩墠娌℃湁鍋氱殑鏄悓涓€涓猲ame瀵瑰簲澶氫釜鏂囦欢,閭d釜鍋氳捣鏉ユ瘮杈冨鏉?娌″暐闇€姹?灏变笉鍋氫簡.
 
 1.name 鏄湇鍔$瀵瑰簲鐨刱ey
 
 2.filename鏄枃浠跺悕
 濡傝繃涓嶄紶filename,鍒欏拰name鍚屽悕
 
 3.contentType
 鍙负绌?榛樿鐢╝pplication/octet-stream)
 閫氬父鏈変互涓嬪嚑绉?
 "text/html", "image/png", "image/gif", "video/mpeg", "text/css", and "audio/basic"
 鍥剧墖鐨勮瘽鍙互鏍规嵁绫诲瀷,璁剧疆鎴愬搴旂殑,姣旀柟璇?"image/jpeg","image/png", "image/gif",
 璇︽儏鍙傝鐧惧害鐧剧:
 http://baike.baidu.com/link?url=JIKC351CPOldPwZa50dp6lUJRII_VdWelsP3jRSnHRLsa9UOWMpLhsYR3rRYfvuQfq17KQXnKpBMUbZU7UDnnK
 
 4.content鏄搴旂殑鏁版嵁璇诲嚭鏉ョ殑NSData瀵硅薄
 
 */
-(NSMutableURLRequest*)POSTRequestWithURL:(NSString*)url
                               parameters:(nullable NSDictionary*)parameters
                                     body:(NSArray*)body;
@end


/**
 Posted when an operation begins executing.
 */
extern NSString * const WTNetworkingOperationDidStartNotification;

/**
 Posted when an operation finishes.
 */
extern NSString * const WTNetworkingOperationDidFinishNotification;
NS_ASSUME_NONNULL_END// 鐗堟潈灞炰簬鍘熶綔鑰?// http://code4app.com (cn) http://code4app.net (en)
// 鍙戝竷浠g爜浜庢渶涓撲笟鐨勬簮鐮佸垎浜綉绔? Code4App.com