猎豆优选

MtopService.h 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //
  2. // MtopService.h
  3. // mtopext
  4. //
  5. // mtop api 调用统一入口
  6. //
  7. // Created by sihai on 4/11/14.
  8. // Copyright (c) 2014 Taobao. All rights reserved.
  9. //
  10. #import <Foundation/Foundation.h>
  11. #import <mtopext/MtopExtRequestDelegate.h>
  12. #import <mtopext/MtopExtRequest.h>
  13. #import <mtopext/MtopExtResponse.h>
  14. #import <mtopext/LoginProtocol.h>
  15. #import <mtopext/TBSDKConfiguration.h>
  16. #import <mtopext/TBSDKAccountInfo.h>
  17. /**
  18. * 内置二方MTOP实例ID
  19. */
  20. #define MTOP_ID_INNER @"INNER"
  21. /**
  22. * 内置三方MTOP实例ID
  23. */
  24. #define MTOP_ID_OPEN @"OPEN"
  25. /**
  26. * MTOP 实例接口。MTOP 支持多实例,目前支持2种类型(MtopType),每一种类型均可创建多个实例,不同的实例以不同ID识别。
  27. *
  28. * 注意:该类型禁止被继承。
  29. */
  30. @interface MtopService : NSObject
  31. /**
  32. * 获取默认实例,默认返回ID为 MTOP_ID_INNER(二方类型)的实例。但是可以通过配置文件 mtopsdk_configuration.plist
  33. * 来设置默认返回类型。配置文件配置规则(示例)如下:
  34. *
  35. * Root (Dictionary)
  36. * |
  37. * |---DefaultID : @"INNER" (@"INNER" 内置二方实例; @“OPEN” 内置三方实例;或其他自定义实例 )
  38. *
  39. * @return MTOP实例
  40. */
  41. + (nullable instancetype) getInstance;
  42. /**
  43. * 通过实例ID来获取对应实例。其中已经内置ID为 MTOP_ID_INNER 与 MTOP_ID_OPEN 实例, 如果需要新增实例,请通过
  44. * mtopsdk_configuration.plist 配置文件来新增实例,只有在 plist 中注册过的ID,才可以使用。配置文件配置规则(示例)如下:
  45. *
  46. * ROOT (dictionary)
  47. * |---ExternalInstances (dictionary)
  48. * |---- @"id1":@"0" (0 表示该实例类型为二方实例)
  49. * |-----@"id2":@"1" (1 表示该实例类型为三方实例)
  50. *
  51. * 注意:ID为 MTOP_ID_INNER 与 MTOP_ID_OPEN 实例不可在配置文件中修改类型,已经分别设置为二方、三方实力。若不是
  52. * MTOP_ID_INNER 与 MTOP_ID_OPEN,且名称未在plist中注册,返回nil.
  53. *
  54. * @param Id 索引MTOP实例的KEY值。可以为 MTOP_ID_INNER/MTOP_ID_OPEN 或者定义在 mtopsdk_configuration.plist 中
  55. * @return MTOP实例。若非内置实例且名称未注册,则返回nil.
  56. */
  57. + (nullable instancetype) getInstanceWithID:(nonnull NSString *)Id;
  58. /**
  59. * 获取指定类型的实例。该接口废弃,使用 getInstanceWithName: 接口代替,kTypeInner对应 MTOP_ID_INNER,
  60. * kTypeOpen 对应 MTOP_ID_OPEN。
  61. *
  62. * @param type, 指定二方(kTypeInner) 或三方(kTypeOpen)
  63. * @return MTOP实例。若该类型未创建,则会同步创建一新实例。
  64. */
  65. + (nullable instancetype) getInstanceWithType:(MtopType)type DEPRECATED_MSG_ATTRIBUTE("请使用[getInstanceWithID:]替换");
  66. /**
  67. * 获取默认实例,实例ID为 MTOP_ID_OPEN. 该方法线程安全。
  68. *
  69. * @return MTOP实例
  70. */
  71. + (nullable instancetype) shareInstance DEPRECATED_MSG_ATTRIBUTE("兼容原三方API");
  72. /**
  73. * 当前实例的配置
  74. */
  75. - (nonnull TBSDKConfiguration *)configuration;
  76. /**
  77. * 当前实例ID。
  78. */
  79. - (nonnull NSString *)ID;
  80. /**
  81. * 当前实例类型。
  82. */
  83. - (MtopType)type;
  84. /**
  85. * 安装一个自定义的登录模块
  86. * 在请求API时, 判断本地无session时, 会调用该模块进行登录, 或者服务端返回session效时会调用该模块进行登录, 登录成功后重放失败请求。
  87. * 在登录的过程中, 有需要登录请求的API的请求会被 pending 到队列, 然后在登录成功后重放, 会登录失败后直接失败
  88. *
  89. * @param module, 登陆模块的实现
  90. */
  91. - (void) installCustomLoginModule:(nonnull id<LoginProtocol>)module;
  92. /**
  93. * 安装一个自定义的授权模块
  94. * 在请求API时, 判断本地无AUTH时, 会调用该模块进行登录, 或者服务端返回AUTH无效时会调用该模块进行登录, 登录成功后重放失败请求。
  95. * 在登录的过程中, 有需要登录请求的API的请求会被 pending 到队列, 然后在登录成功后重放, 会登录失败后直接失败
  96. *
  97. * @param module, 授权模块的实现
  98. */
  99. - (void) installCustomAuthModule:(nonnull id<MtopAuthProtocol>)module;
  100. /**
  101. * 获取当前实例上的登录接口
  102. */
  103. - (nonnull id<LoginProtocol>) loginModule;
  104. /**
  105. * 获取当前实例上的鉴权接口
  106. */
  107. - (nonnull id<MtopAuthProtocol>) authModule;
  108. /**
  109. * 获取账户信息
  110. */
  111. - (nullable TBSDKAccountInfo *)currentAccount;
  112. /*!
  113. * 安装防刷delegate
  114. * @param delegate
  115. */
  116. // TO DO
  117. //- (id<FloodProtectionDelegate>) installFloodProtectionDelegate: (id<FloodProtectionDelegate>) delegate;
  118. /**
  119. * 同步调用API
  120. *
  121. * @param request
  122. * @return MtopExtResponse API响应
  123. */
  124. - (nullable MtopExtResponse*) sync_call: (nonnull MtopExtRequest*) request;
  125. /**
  126. * 异步调用API
  127. *
  128. * @param request
  129. * @param delegate
  130. *
  131. */
  132. - (void)async_call:(nonnull MtopExtRequest *)request;
  133. /**
  134. * 异步调用API
  135. *
  136. * @param request
  137. * @param delegate
  138. *
  139. */
  140. - (void) async_call: (nonnull MtopExtRequest*) request delegate: (nullable id<MtopExtRequestDelegate>) delegate;
  141. /**
  142. * 异步调用API, 跳过startFilter之前的filter
  143. *
  144. * @param request
  145. * @param delegate
  146. * @param startFilter
  147. *
  148. */
  149. - (void) async_call:(nonnull MtopExtRequest*) request delegate: (nullable id<MtopExtRequestDelegate>) delegate startFilter: (nullable NSString*) startFilter;
  150. /**
  151. * 提供一个便捷的方法, 同步调用没有参数的API
  152. *
  153. * @param apiName API名称
  154. * @param apiVersion API版本
  155. * @return MtopExtResponse API响应
  156. */
  157. - (nullable MtopExtResponse*) sync_call: (nonnull NSString*) apiName apiVersion: (nonnull NSString*) apiVersion;
  158. /**
  159. * 提供一个便捷的方法, 同步调用API
  160. *
  161. * @param apiName API名称
  162. * @param apiVersion API版本
  163. * @param bizParameters API业务参数
  164. * @return MtopExtResponse API响应
  165. */
  166. - (nullable MtopExtResponse*) sync_call: (nonnull NSString*) apiName apiVersion: (nonnull NSString*) apiVersion bizParameters: (nullable NSDictionary*) bizParameters;
  167. #pragma mark 新增mtop添加/删除全局header以及query参数接口
  168. /**
  169. * 添加一个全局http请求头(不做URLENCODE)
  170. *
  171. * @param value HTTP头value, 请不要做urlencode, 底层会统一做的
  172. * @param key HTTP头key
  173. */
  174. - (void) addCustomHttpHeader: (nonnull NSString*) value forKey: (nonnull NSString*) key;
  175. /**
  176. * 添加一个全局http请求头
  177. * @param value HTTP头value, 请不要做urlencode, 底层会统一做的
  178. * @param key HTTP头key
  179. */
  180. - (void) addHttpHeader: (nonnull NSString*) value forKey: (nonnull NSString*) key;
  181. /**
  182. * 提供一个移除全局自定义请求头的方法
  183. */
  184. - (void)removHttpHeader:(nonnull NSString *)key;
  185. /**
  186. * 添加一个全局扩展参数和data参数平级
  187. * @param value 参数值
  188. * @param key 参数名
  189. */
  190. - (void) addExtParameter: (nonnull id) value forKey: (nonnull NSString*) key;
  191. /**
  192. * 移除一个全局扩展参数
  193. * @param key
  194. */
  195. - (void) removeExtParameter: (nonnull NSString*) key;
  196. @end