top4net - 淘宝开放平台.NET版SDK

jopen 12年前

设计原则

  1. 容易维护扩展(不需要修改主类就可以添加新的API支持)
  2. 注入型解释器(依据不同的返回格式注入相应的解释器)
  3. 集中管理请求参数与参数映射
  4. 使用泛型来做强类型编程
  5. 基于纯.NET 2.0的XML与JSON解释器实现
  6. 多协议扩展支持(REST, RPC, SOAP, etc)

设计类图

top4net - 淘宝开放平台.NET版SDK

扩展方式

  1. 实现ITopRequest类,覆盖其中的GetParameters和GetApiName方法
  2. 实现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")));

项目主页:http://www.open-open.com/lib/view/home/1360140599174