top4net - 淘宝开放平台.NET版SDK
设计原则
- 容易维护扩展(不需要修改主类就可以添加新的API支持)
- 注入型解释器(依据不同的返回格式注入相应的解释器)
- 集中管理请求参数与参数映射
- 使用泛型来做强类型编程
- 基于纯.NET 2.0的XML与JSON解释器实现
- 多协议扩展支持(REST, RPC, SOAP, etc)
设计类图
扩展方式
- 实现ITopRequest类,覆盖其中的GetParameters和GetApiName方法
- 实现ITopParser类,覆盖其中的Parse方法。
环境依赖
- 需要运行在.NET Framework 2.0的环境或者以上
调用方式TopXmlRestClient client = new TopXmlRestClient("http://gw.api.tbsandbox.com/router/rest", "test", "test"); UserGetRequest request = new UserGetRequest(); request.Fields = "user_id,nick,sex,created,location"; request.Nick = "tbtest520"; User user = client.UserGet(request); TopXmlRestClient client = new TopXmlRestClient("http://gw.api.tbsandbox.com/router/rest", "test", "test"); ItemUpdateRequest request = new ItemUpdateRequest(); request.Iid = "9ce7d2a5a38c1a20346cdd4af6f90de3"; request.Title = "Updated by Top4Net"; request.Image = new FileItem(new FileInfo("C:/temp.jpg")); Item item = client.ItemUpdate(request, "session_key"); TopXmlRestClient client = new TopXmlRestClient("http://gw.api.tbsandbox.com/router/rest", "test", "test"); TradesSoldGetRequest req = new TradesSoldGetRequest(); req.Fields = "tid,seller_nick,buyer_nick,orders.oid,orders.iid,orders.title,orders.price"; PageList<Trade> rsp = client.TradesSoldGet(req, "session_key"); List<Trade> trades = rsp.Content; long totalResults = rsp.TotalResults; ITopClient client = new TopRestClient("http://gw.api.tbsandbox.com/router/rest", "test", "test", "json"); UserGetRequest request = new UserGetRequest(); request.Fields = "user_id,nick,sex,created,location"; request.Nick = "tbtest520"; User user = client.Execute(request, new ObjectXmlParser<User>(new ParseData(request.getApiName(), "user")));
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!