BBASMCommonRequestInfo.h 5.05 KB
//  BBAMNP
//
//  Created by baidu on 2019/5/12.
//  Copyright © 2019 Baidu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <BBAAPIRequest/BBAAPIRequest.h>

// 网络库日志字段from与subFrom http://wiki.baidu.com/pages/viewpage.action?pageId=1134363185
extern APIRequestFrom const BBASMCommonRequestInfoFromMNP;
extern APIRequestFrom const BBASMGameRequestInfoFromMNP;

NS_ASSUME_NONNULL_BEGIN

// 网络库日志字段subFrom
typedef NS_ENUM(NSInteger, BBASMRequestSubFromType) {
    BBASMRequestSubFromTypeDefault = 0,            // 默认设置
    BBASMRequestSubFromTypeDownloadFile = 1,       // 小程序downloadFile
    BBASMRequestSubFromTypeUploadFile = 2,         // 小程序uploadFile
    BBASMRequestSubFromTypeRequest = 3,            // 小程序request
    BBASMRequestSubFromTypePMS = 10,               // 小程序PMS请求
    BBASMRequestSubFromTypeUpdate = 20,            // 小程序ma/update请求
    BBASMRequestSubFromTypeAuthorize = 21,         // 小程序authorize请求
    BBASMRequestSubFromTypeAD = 30,                // 小程序广告请求
    BBASMRequestSubFromTypeAnti = 1601,            // 小游戏防沉迷
    BBASMRequestSubFromTypeReVisit = 1605,         // 回访引导
    BBASMRequestSubFromTypeRecommend = 1607,       // 小游戏交叉换量
    BBASMRequestSubFromTypeShare = 1608            // 小游戏录屏分享
};


typedef NS_ENUM(NSInteger, BBASMRequestClassType) {
    BBASMRequestClassTypeDefault = 0,              // BBANormalAPIRequest类
    BBASMRequestClassTypeBdtls = 1                 // BBASMBdtlsRequest类
};

// content-type类型
extern NSString *const BBASMContentTypeJson; // application/json
extern NSString *const BBASMContentTypeForm; // application/x-www-form-urlencoded
extern NSString *const BBASMContentTypeText; // text/plain

extern NSInteger const BBASMInternetHttpSuccessCode;

/// 请求参数
@interface BBASMCommonRequestInfo : NSObject

/// 构造请求类,默认为类为BBANormalAPIRequest
@property (nonatomic, assign) BBASMRequestClassType requestClassType;

/// 请求方法,不设置默认为GET方法
@property (nonatomic, assign) APIRequestMethod method;
/// 请求地址url,如果有公参,可以直接拼接到url中
@property (nonatomic, copy) NSString *url;
/// 请求参数
@property (nonatomic, strong, nullable) NSMutableDictionary *params;
/// 请求体(只有post方法使用,设置postBodyData会忽略params)
@property (nonatomic, strong, nullable) NSData *postBodyData;
/// 请求头中的U-A信息,此处设置会覆盖heads中的U-A
@property (nonatomic, copy, nullable) NSString *userAgent;
/// 请求头中的refer信息,此处设置会覆盖heads中的refer
@property (nonatomic, copy, nullable) NSString *referer;
/// 请求头中的contentType信息,此处设置会覆盖heads中的contentType
@property (nonatomic, copy, nullable) NSString *contentType;
/// 非User-Agent、Refer、content-type的请求头信息在otherHeaders中添加
@property (nonatomic, strong, nullable) NSMutableDictionary *otherHeaders;
/// 请求cookie信息
@property (nonatomic, strong, nullable) NSMutableArray <NSHTTPCookie*> *requestCookies;
/// 获取请求参数时的错误信息,如果请求参数正确,该error信息为nil
@property (nonatomic, strong, nullable) NSError *error;
/// 请求超时时间  (单位秒)
@property (nonatomic, assign) NSTimeInterval requestTimeout;
/// 解析格式,默认为Json格式,绝大部分response各位为Array或Dic等格式的无需关心此字段
@property (nonatomic, assign) APISerializerType serializerType;
/// 是否为内部请求,默认为YES
@property (nonatomic, assign) BOOL isInternal;
/// xcx网络日志的子业务标识细分
@property (nonatomic, assign) BBASMRequestSubFromType requestSubFrom;
/// xcx网络日志的业务标识
@property (nonatomic, assign) APIRequestFrom requestFrom;

/// @brief 通过字典构造请求实体类,此方法为了兼容旧逻辑,不推荐使用,直接使用init方法即可
/// @param paramDic 字典信息
/// @return 请求实体类
- (instancetype)initWithRequestParam:(NSDictionary *)paramDic;

/// @brief 返回请求方法字符串,默认为GET
/// @param method  请求方法,类型为APIRequestMethod
+ (NSString *)getRequestMethodStr:(APIRequestMethod)method;

@end

/// 构造请求URL
@interface BBASMHttpUrlBuilder : NSObject

/// 请求host,再执行addQueryName:value:方法后调用有效
@property (nonatomic, copy, readonly) NSString *urlStr;

/// @brief 构造请求URL
/// @param host 请求host
/// @param path 请求path
- (instancetype)initHost:(NSString *)host path:(NSString *)path;

/// @brief 构造请求URL,添加单个query
/// @param keyName 请求query名字
/// @param kayValue 请求query值
- (void)addQueryName:(NSString *)keyName value:(NSString *)kayValue;

/// @brief 向请求URL添加一组query
/// @param queryDic 请求query集合
- (void)addQueryDictionary:(NSDictionary *)queryDic;

/// @brief 向请求URL 在原有的query里面,追加query
/// @param queryStr  NSString 追加query
- (void)appendQuery:(NSString *)queryStr;

@end


NS_ASSUME_NONNULL_END