├── .gitignore
├── README.md
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── dongxuexidu
│ └── douban4j
│ ├── constants
│ ├── DefaultConfigs.java
│ ├── RequestUrls.java
│ └── StatusCode.java
│ ├── model
│ ├── IDoubanObject.java
│ ├── UnTested.java
│ ├── app
│ │ ├── AccessToken.java
│ │ ├── DoubanException.java
│ │ └── RequestGrantScope.java
│ ├── collection
│ │ ├── DoubanCollectionFeedObj.java
│ │ └── DoubanCollectionObj.java
│ ├── common
│ │ ├── DoubanAttributeObj.java
│ │ ├── DoubanAuthorObj.java
│ │ ├── DoubanCategoryObj.java
│ │ ├── DoubanCountObj.java
│ │ ├── DoubanEntityObj.java
│ │ ├── DoubanImageObj.java
│ │ ├── DoubanLinkObj.java
│ │ ├── DoubanLocationObj.java
│ │ ├── DoubanRatingObj.java
│ │ ├── DoubanTagObj.java
│ │ ├── DoubanWhenObj.java
│ │ └── DoubanWhereObj.java
│ ├── doumail
│ │ ├── DoubanMailEntryObj.java
│ │ └── DoubanMailFeedObj.java
│ ├── event
│ │ ├── DoubanEventEntryObj.java
│ │ └── DoubanEventFeedObj.java
│ ├── note
│ │ ├── DoubanNoteEntryObj.java
│ │ └── DoubanNoteFeedObj.java
│ ├── review
│ │ ├── DoubanReviewEntryObj.java
│ │ └── DoubanReviewFeedObj.java
│ ├── shuo
│ │ ├── DoubanShuoAttachementObj.java
│ │ ├── DoubanShuoMediaObj.java
│ │ ├── DoubanShuoStatusObj.java
│ │ └── DoubanShuoUserObj.java
│ ├── subject
│ │ ├── DoubanSubjectFeedObj.java
│ │ └── DoubanSubjectObj.java
│ ├── user
│ │ ├── DoubanUserFeedObj.java
│ │ └── DoubanUserObj.java
│ └── v2
│ │ ├── DoubanCastObject.java
│ │ ├── DoubanDirectorObj.java
│ │ ├── DoubanRatingObj.java
│ │ ├── DoubanSubjectListObj.java
│ │ └── DoubanSubjectObj.java
│ ├── playground
│ ├── BrowserLauncher.java
│ ├── DoubanPeopleEntry.java
│ ├── Link.java
│ ├── Location.java
│ └── PlayGround.java
│ ├── provider
│ └── OAuthDoubanProvider.java
│ ├── service
│ ├── DoubanBookMovieMusicService.java
│ ├── DoubanCollectionService.java
│ ├── DoubanEventService.java
│ ├── DoubanMailService.java
│ ├── DoubanNoteService.java
│ ├── DoubanReviewService.java
│ ├── DoubanService.java
│ ├── DoubanShuoService.java
│ └── DoubanUserService.java
│ └── utils
│ ├── Converters.java
│ ├── ErrorHandler.java
│ └── HttpManager.java
└── test
└── java
└── com
└── dongxuexidu
└── douban4j
└── service
├── DoubanBookMovieMusicServiceTest.java
├── DoubanCollectionServiceTest.java
├── DoubanEventServiceTest.java
├── DoubanMailServiceTest.java
├── DoubanNoteServiceTest.java
├── DoubanReviewServiceTest.java
├── DoubanShuoServiceTest.java
└── DoubanUserServiceTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | .settings/
3 |
4 | *.class
5 | *.war
6 | *.ear
7 | *.jar
8 | .classpath
9 | .project
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 豆瓣OAuth2 API Java SDK (几乎完全版) v0.727
4 | ======================================
5 |
6 | 注意
7 | ---
8 | 现在本SDK是基于豆瓣OAuth 2.0 API的v1版,也就是使用GData 和 Atom作为数据传输类型的版本,使用JSON的v2版本尚未支持。
9 | 由于主作者没有更多时间来更新这个SDK,欢迎大家Fork本SDK,如果您做了更新,欢迎发Pull Request给我,我会及时Merge.
10 |
11 | 功能/优点
12 | ---
13 | + **豆瓣Oauth2认证流程** - `用户登录`
14 | 从引导用户,用户批准权限换code到用code换accessToken
15 | + **完备的模型(Model)以及转换器(Parser)** - `无需担心数据转换和提取`
16 | 完美转换豆瓣API所使用的GData/Atom类型的xml以及json致简单易读易懂易用的JavaBean
17 | + **'豆瓣社区/书影音/豆瓣说'全覆盖** - `全面支持豆瓣开放了的API`
18 | 几乎支持全部豆瓣开放平台中开放了的API
19 | + **错误处理** - `轻松了解为何出错`
20 | 对各种Exception的包装,使得错误信息明了,使用简单(无需分门别类catch一大堆Exception)
21 | + **防误调用** - `减少调用中的问题`
22 | 精心设计的调用接口,使得无需阅读大量文档也可以轻松使用
23 | + **多线程/并发支持** - `虽然没测大量并发`
24 | 但是,谁用谁知道。在**没有bug的情况下**服务应该是线程安全的 :)
25 |
26 | 安装使用
27 | ---
28 | 有两种方式来整合SDK到您自己的项目中:
29 |
30 | * **使用Maven编译打包** - `(**推荐**)`
31 | 由于项目本身就是一个Maven项目,所以使用Maven最方便.
32 | 如果您的项目本身就是一个Maven项目,那么直接在您项目的pom.xml中加入依赖:
33 |
34 | ```xml
35 |
36 | com.zhibo
37 | Douban4jOAuth2
38 | 1.0-SNAPSHOT
39 |
40 | ```
41 |
42 | 然后编译SDK,**编译时请务必跳过所有test**(不然会通不过无法编译,因为很多测试用例都是需要accessToken的),编译命令使用mvn package或mvn install,根据您自己的需要(如果您不明白两者的区别,请google Maven的基础知识)。例子如下:
43 | ```
44 | mvn package -Dmaven.test.skip=true
45 | ```
46 |
47 | * **在您的项目中包含SDK全部源码** `(**如果能使用Maven请尽量使用Maven,尽量不要使用这种方式**)`
48 | 那么,您需要自己下载以下依赖:
49 | * commons-codec-1.9.jar
50 | * commons-lang-2.6.jar
51 | * google-http-client-1.10.3-beta.jar
52 | * gson-2.4.jar
53 | * guava-14.0.1.jar
54 | * httpclient-4.5.1.jar
55 | * httpcore-4.4.3.jar
56 | * jackson-core-asl-1.9.13.jar
57 | * json-lib-2.4-jdk15.jar
58 | * protobuf-java-2.4.1.jar
59 | * xmlpull-1.1.3.1.jar
60 |
61 | 可以到这儿下载:http://www.mvnrepository.com/
62 |
63 | OAuth认证流程
64 | ---
65 | 1. 初始化:
66 | ```js
67 | OAuthDoubanProvider oauth = new OAuthDoubanProvider();
68 | oauth.setApiKey("xxx").setSecretKey("xxx");//设置Apikey和secretKey.
69 | /*
70 | 也可以在DefaultConfigs中直接填入您的apikey和secretKey,那么就不需要每次都设置这两个值.
71 | */
72 | oauth.addScope(RequestGrantScope.BASIC_COMMON_SCOPE).addScope(......).//设置权限范围
73 | oauth.setRedirectUrl("http://www.dongxuexidu.com");//设置回调地址
74 | .........
75 | ```
76 |
77 | 2. 引导用户至豆瓣认证页面,该页面地址可以通过以下代码拿到:
78 | ```js
79 | String redirectUrl = oauth.getGetCodeRedirectUrl();
80 | ```
81 |
82 | 3. 通过你的回调地址获得code.
83 | ```js
84 | String code = howeverYouGetIt();
85 | ```
86 |
87 | 4. 用code换accessToken.
88 | ```js
89 | AccessToken at = oauth.tradeAccessTokenWithCode(code);
90 | ```
91 |
92 | 整个流程在PlayGround.java里面的testAccessToken()方法内有详细可以测试的例子。
93 |
94 | 豆瓣API调用
95 | ---
96 | 请详见Test目录下的全部测试用例
97 |
98 | 其他说明
99 | ---
100 | * **参数类型** 方法参数中类型为基本类型(如int, long)的说明该参数为必须,参数为包装类型(Integer, Long)的说明可为null且不会有任何问题。
101 | * **缺豆瓣说里面部分评论相关API** 懒了没写
102 | * **未测试方法** 部分未测试方法前含有@UnTested的Annotation,其余皆为已经测试通过的.
103 | * **未实现部分分支** 如豆邮过多需要验证码的引导,如上传本地图片至豆瓣说广播等.
104 | * **使用实例** 使用实例都可以在PlayGround,java和Test目录下找到.
105 | * **欢迎** 有兴趣的同学来一起继续完善这个SDK
106 |
107 | 开源使用协议
108 | ---
109 | MIT License
110 |
111 | Contributors
112 | ---
113 | - [UglyTroLL](https://github.com/UglyTroLL)
114 | - [Sean Guo](https://github.com/seanguo)
115 | - [SuperWang](https://github.com/SuperWang)
116 | - [wellno](https://github.com/wellno)
117 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.zhibo
6 | Douban4jOAuth2
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 | Douban4jOAuth2
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 |
20 | org.apache.maven.plugins
21 | maven-compiler-plugin
22 | 2.0.2
23 |
24 | 1.6
25 | 1.6
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | com.google.http-client
34 | google-http-client
35 | 1.10.3-beta
36 |
37 |
38 | junit
39 | junit
40 | 3.8.1
41 | test
42 |
43 |
44 | net.sf.json-lib
45 | json-lib
46 | 2.3
47 | jdk15
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/constants/DefaultConfigs.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.constants;
2 |
3 | import com.google.api.client.xml.XmlNamespaceDictionary;
4 |
5 | /**
6 | *
7 | * @author Zhibo Wei
8 | */
9 | public class DefaultConfigs {
10 |
11 | public static final String API_KEY = "";
12 | public static final String SECRET_KEY = "";
13 | public static final String API_URL_PREFIX = "https://api.douban.com";
14 | public static final String AUTH_URL = "https://www.douban.com/service/auth2/auth";
15 | public static final String ACCESS_TOKEN_URL = "https://www.douban.com/service/auth2/token";
16 | public static final String ACCESS_TOKEN_REDIRECT_URL = "http://www.dongxuexidu.com";
17 |
18 | public static final XmlNamespaceDictionary DOUBAN_XML_NAMESPACE = new XmlNamespaceDictionary();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/constants/RequestUrls.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.constants;
2 |
3 | /**
4 | *
5 | * @author Zhibo Wei
6 | */
7 | public class RequestUrls {
8 |
9 | /**
10 | * User services
11 | */
12 | public static final String DOUBAN_USER_PREFIX = DefaultConfigs.API_URL_PREFIX + "/people";
13 |
14 | /**
15 | * Collection services
16 | */
17 | public static final String DOUBAN_COLLECTION_PREFIX = DefaultConfigs.API_URL_PREFIX + "/collection";
18 |
19 | /**
20 | * Review services
21 | */
22 | public static final String DOUBAN_REVIEW_PREFIX = DefaultConfigs.API_URL_PREFIX + "/review";
23 |
24 | /**
25 | * Subject services
26 | */
27 | public static final String DOUBAN_BOOK_SUBJECT_PREFIX = DefaultConfigs.API_URL_PREFIX + "/book/subject";
28 | public static final String DOUBAN_MOVIE_SUBJECT_PREFIX = DefaultConfigs.API_URL_PREFIX + "/movie/subject";
29 | public static final String DOUBAN_MUSIC_SUBJECT_PREFIX = DefaultConfigs.API_URL_PREFIX + "/music/subject";
30 |
31 | public static final String DOUBAN_MOVIE_V2_SUBJECT_PREFIX = DefaultConfigs.API_URL_PREFIX + "/v2/movie/subject";
32 |
33 | public static final String DOUBAN_MOVIE_V2_PREFIX = DefaultConfigs.API_URL_PREFIX + "/v2/movie";
34 |
35 | /**
36 | * Note services
37 | */
38 | public static final String DOUBAN_NOTE_PREFIX = DefaultConfigs.API_URL_PREFIX + "/note";
39 |
40 | /**
41 | * Doumail Services
42 | */
43 |
44 | public static final String DOUBAN_MAIL_PREFIX = DefaultConfigs.API_URL_PREFIX + "/doumail";
45 |
46 | /**
47 | * Event Services
48 | */
49 |
50 | public static final String DOUBAN_EVENT_PREFIX = DefaultConfigs.API_URL_PREFIX + "/event";
51 |
52 | /**
53 | * Douban shuo Services
54 | */
55 |
56 | public static final String DOUBAN_SHUO_STATUS_PREFIX = DefaultConfigs.API_URL_PREFIX + "/shuo/statuses";
57 |
58 | public static final String DOUBAN_SHUO_USER_PREFIX = DefaultConfigs.API_URL_PREFIX + "/shuo/users";
59 |
60 | public static final String DOUBAN_SHUO_FRIENDSHIP_PREFIX = DefaultConfigs.API_URL_PREFIX + "/shuo/friendships";
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/constants/StatusCode.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.constants;
2 |
3 | /**
4 | *
5 | * @author Zhibo Wei
6 | */
7 | public class StatusCode {
8 |
9 | public static final int HTTP_STATUS_OK = 200; //请求成功
10 | public static final int HTTP_STATUS_CREATED = 201; //创建成功
11 | public static final int HTTP_STATUS_ACCEPTED = 202; //更新成功
12 | public static final int HTTP_STATUS_BAD_REQUEST = 400; //请求的地址不存在或者包含不支持的参数
13 | public static final int HTTP_STATUS_UNAUTHORIZED = 401; //未授权
14 | public static final int HTTP_STATUS_FORBIDDEN = 403; //被禁止访问
15 | public static final int HTTP_STATUS_NOT_FOUND = 404; //请求的资源不存在
16 | public static final int HTTP_STATUS_INTERNAL_SERVER_ERROR = 500; //内部错误
17 |
18 | /**
19 | * 100 invalid_request_scheme 错误的请求协议
20 | 101 invalid_request_method 错误的请求方法
21 | 102 access_token_is_missing 未找到access_token
22 | 103 invalid_access_token access_token不存在或已被用户删除
23 | 104 invalid_apikey apikey不存在或已删除
24 | 105 apikey_is_blocked apikey已被禁用
25 | 106 access_token_has_expired access_token已过期
26 | 107 invalid_request_uri 请求地址未注册
27 | 108 invalid_credencial1 用户未授权访问此数据
28 | 109 invalid_credencial2 apikey未申请此权限
29 | 110 not_trial_user 未注册的测试用户
30 | 111 rate_limit_exceeded1 用户访问速度限制
31 | 112 rate_limit_exceeded2 IP访问速度限制
32 | 113 required_parameter_is_missing 缺少参数
33 | 114 unsupported_grant_type 错误的grant_type
34 | 115 unsupported_response_type 错误的response_type
35 | 116 client_secret_mismatch client_secret不匹配
36 | 117 redirect_uri_mismatch redirect_uri不匹配
37 | 118 invalid_authorization_code authorization_code不存在或已过期
38 | 119 invalid_refresh_token refresh_token不存在或已过期
39 | 120 username_password_mismatch 用户名密码不匹配
40 | 121 invalid_user 用户不存在或已删除
41 | 122 user_has_blocked 用户已被屏蔽
42 | 123 access_token_has_expired_since_password_changed 因用户修改密码而导致access_token过期
43 | 124 access_token_has_not_expired access_token未过期
44 | 125 invalid_request_scope 访问的scope不合法,开发者不用太关注,一般不会出现该错误
45 | 999 unknown 未知错误
46 | *
47 | *
48 | * I guess we don't need these? Since the error description is already in the return message
49 | */
50 | public static final int API_CODE_INVALID_REQUEST_SCHEME = 100;
51 | public static final int API_CODE_INVALID_REQUEST_METHOD = 101;
52 | public static final int API_CODE_ACCESS_TOKEN_IS_MISSING = 102;
53 | public static final int API_CODE_INVALID_ACCESS_TOKEN = 103;
54 | public static final int API_CODE_INVALID_APIKEY = 104;
55 | public static final int API_CODE_APIKEY_IS_BLOCKED = 105;
56 | public static final int API_CODE_ACCESS_TOKEN_HAS_EXPIRED = 106;
57 | public static final int API_CODE_INVALID_REQUEST_URI = 107;
58 | public static final int API_CODE_INVALID_CREDENCIAL_NO_USER_PERMISSION = 108;
59 | public static final int API_CODE_INVALID_CREDENCIAL_NO_API_PERMISSION = 109;
60 | public static final int API_CODE_NOT_TRIAL_USER = 110;
61 | public static final int API_CODE_RATE_LIMIT_EXCEEDED_USER = 111;
62 | public static final int API_CODE_RATE_LIMIT_EXCEEDED_IP = 112;
63 | public static final int API_CODE_REQUIRED_PARAMETER_IS_MISSING = 113;
64 | public static final int API_CODE_UNSUPPORTED_GRANT_TYPE = 114;
65 | public static final int API_CODE_UNSUPPORTED_RESPONSE_TYPE = 115;
66 | public static final int API_CODE_CLIENT_SECRET_MISMATCH = 116;
67 | public static final int API_CODE_REDIRECT_URI_MISMATCH = 117;
68 | public static final int API_CODE_INVALID_AUTHORIZATION_CODE = 118;
69 | public static final int API_CODE_INVALID_REFRESH_TOKEN = 119;
70 | public static final int API_CODE_USERNAME_PASSWORD_MISMATCH = 120;
71 | public static final int API_CODE_INVALID_USER = 121;
72 | public static final int API_CODE_USER_HAS_BEEN_BLOCKED = 122;
73 | public static final int API_CODE_ACCESS_TOKEN_EXPIRED_SINCE_PASSWORD_CHANGED = 123;
74 | public static final int API_CODE_ACCESS_TOKEN_HAS_NOT_EXPIRED = 124;
75 | public static final int API_CODE_INVALID_REQUEST_SCOPE = 125;
76 | public static final int API_CODE_UNKNOWN_DAMN_IT = 999;
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/IDoubanObject.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model;
2 |
3 | /**
4 | *
5 | * @author Zhibo Wei
6 | */
7 | public interface IDoubanObject {
8 |
9 | String getObjName();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/UnTested.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model;
2 |
3 | /**
4 | *
5 | * @author Zhibo Wei
6 | */
7 | public @interface UnTested {
8 |
9 | //Just for fun
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/app/AccessToken.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.app;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | *
7 | * @author Zhibo Wei
8 | */
9 | public class AccessToken implements Serializable {
10 |
11 | private static final long serialVersionUID = 1L;
12 |
13 | private String accessToken = null;
14 | private Integer expiresIn = null;
15 | private String refreshToken = null;
16 | private String doubanUserId = null;
17 |
18 | /**
19 | * @return the accessToken
20 | */
21 | public String getAccessToken() {
22 | return accessToken;
23 | }
24 |
25 | /**
26 | * @param accessToken the accessToken to set
27 | */
28 | public void setAccessToken(String accessToken) {
29 | this.accessToken = accessToken;
30 | }
31 |
32 | /**
33 | * @return the expiresIn
34 | */
35 | public Integer getExpiresIn() {
36 | return expiresIn;
37 | }
38 |
39 | /**
40 | * @param expiresIn the expiresIn to set
41 | */
42 | public void setExpiresIn(Integer expiresIn) {
43 | this.expiresIn = expiresIn;
44 | }
45 |
46 | /**
47 | * @return the refreshToken
48 | */
49 | public String getRefreshToken() {
50 | return refreshToken;
51 | }
52 |
53 | /**
54 | * @param refreshToken the refreshToken to set
55 | */
56 | public void setRefreshToken(String refreshToken) {
57 | this.refreshToken = refreshToken;
58 | }
59 |
60 | /**
61 | * @return the doubanUserId
62 | */
63 | public String getDoubanUserId() {
64 | return doubanUserId;
65 | }
66 |
67 | /**
68 | * @param doubanUserId the doubanUserId to set
69 | */
70 | public void setDoubanUserId(String doubanUserId) {
71 | this.doubanUserId = doubanUserId;
72 | }
73 |
74 | public AccessToken() {
75 |
76 | }
77 |
78 | public AccessToken (String accessToken) {
79 | this.accessToken = accessToken;
80 | }
81 |
82 | public AccessToken (String accessToken, int expiresIn, String refreshToken, String doubanUserId) {
83 | this.accessToken = accessToken;
84 | this.doubanUserId = doubanUserId;
85 | this.expiresIn = expiresIn;
86 | this.refreshToken = refreshToken;
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/app/DoubanException.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.app;
2 |
3 | /**
4 | *
5 | * @author Zhibo Wei
6 | */
7 | public class DoubanException extends Exception {
8 |
9 | private static final long serialVersionUID = 1L;
10 |
11 | private int errorCode;
12 | private String errorMsg;
13 |
14 | /**
15 | * @return the errorCode
16 | */
17 | public int getErrorCode() {
18 | return errorCode;
19 | }
20 |
21 | /**
22 | * @param errorCode the errorCode to set
23 | */
24 | public void setErrorCode(int errorCode) {
25 | this.errorCode = errorCode;
26 | }
27 |
28 | /**
29 | * @return the errorMsg
30 | */
31 | public String getErrorMsg() {
32 | return errorMsg;
33 | }
34 |
35 | /**
36 | * @param errorMsg the errorMsg to set
37 | */
38 | public void setErrorMsg(String errorMsg) {
39 | this.errorMsg = errorMsg;
40 | }
41 |
42 | public DoubanException (int code, String msg) {
43 | super(msg);
44 | this.errorCode = code;
45 | this.errorMsg = msg;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/app/RequestGrantScope.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.app;
2 |
3 | /**
4 | *
5 | * @author Zhibo Wei
6 | */
7 | public class RequestGrantScope {
8 |
9 | private String description;
10 | private String value;
11 | private String name;
12 |
13 | private static final String SCOPE_SHUO_READ = "shuo_basic_r";
14 | private static final String SCOPE_SHUO_WRITE = "shuo_basic_w";
15 | private static final String SCOPE_MAIL_READ = "community_advanced_doumail_r";
16 | private static final String SCOPE_MAIL_WRITE = "community_advanced_doumail_w";
17 | private static final String SCOPE_BASIC_COMMON = "douban_basic_common";
18 | private static final String SCOPE_BASIC_NOTE = "community_basic_note";
19 | private static final String SCOPE_BOOK_READ = "book_basic_r";
20 | private static final String SCOPE_MOVIE_READ = "movie_basic_r";
21 | private static final String SCOPE_MUSIC_READ = "music_basic_r";
22 | private static final String SCOPE_EVENT_READ = "event_basic_r";
23 | private static final String SCOPE_EVENT_WRITE = "event_basic_w";
24 |
25 | public static final RequestGrantScope SHUO_READ_SCOPE = new RequestGrantScope("DoubanShuoRead", RequestGrantScope.SCOPE_SHUO_READ, "豆瓣说读取权限");
26 | public static final RequestGrantScope SHUO_WRITE_SCOPE = new RequestGrantScope("DoubanShuoWrite", RequestGrantScope.SCOPE_SHUO_WRITE, "豆瓣说写入权限");
27 | public static final RequestGrantScope BASIC_COMMON_SCOPE = new RequestGrantScope("BasicCommon", RequestGrantScope.SCOPE_BASIC_COMMON, "豆瓣基本权限");
28 | public static final RequestGrantScope MAIL_READ_SCOPE = new RequestGrantScope("MailRead", RequestGrantScope.SCOPE_MAIL_READ, "豆邮读权限");
29 | public static final RequestGrantScope MAIL_WRITE_SCOPE = new RequestGrantScope("DoubanShuoWrite", RequestGrantScope.SCOPE_MAIL_WRITE, "豆邮写权限");
30 | public static final RequestGrantScope BASIC_NOTE_SCOPE = new RequestGrantScope("BasicNote", RequestGrantScope.SCOPE_BASIC_NOTE, "日记读写权限");
31 | public static final RequestGrantScope BOOK_READ_SCOPE = new RequestGrantScope("BookRead", RequestGrantScope.SCOPE_BOOK_READ, "豆瓣读书");
32 | public static final RequestGrantScope MOVIE_READ_SCOPE = new RequestGrantScope("MovieRead", RequestGrantScope.SCOPE_MOVIE_READ, "豆瓣电影");
33 | public static final RequestGrantScope MUSIC_READ_SCOPE = new RequestGrantScope("MusicRead", RequestGrantScope.SCOPE_MUSIC_READ, "豆瓣音乐");
34 | public static final RequestGrantScope EVENT_READ_SCOPE = new RequestGrantScope("EventRead", RequestGrantScope.SCOPE_EVENT_READ, "豆瓣同城读权限");
35 | public static final RequestGrantScope EVENT_WRITE_SCOPE = new RequestGrantScope("EventWrite", RequestGrantScope.SCOPE_EVENT_WRITE, "豆瓣同城写权限");
36 |
37 | private RequestGrantScope (String name, String value, String description) {
38 | this.description = description;
39 | this.name = name;
40 | this.value = value;
41 | }
42 |
43 | /**
44 | * @return the description
45 | */
46 | public String getDescription() {
47 | return description;
48 | }
49 |
50 | /**
51 | * @return the value
52 | */
53 | public String getValue() {
54 | return value;
55 | }
56 |
57 | /**
58 | * @return the name
59 | */
60 | public String getName() {
61 | return name;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/collection/DoubanCollectionFeedObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.collection;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.dongxuexidu.douban4j.model.IDoubanObject;
7 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
8 | import com.google.api.client.util.Key;
9 |
10 | /**
11 | *
12 | * @author Zhibo Wei
13 | */
14 | public class DoubanCollectionFeedObj implements IDoubanObject{
15 |
16 | @Key("entry")
17 | private List collections = new ArrayList();
18 |
19 | @Key("author")
20 | private DoubanAuthorObj author;
21 |
22 | @Key
23 | private String title;
24 |
25 | @Key("opensearch:itemsPerPage")
26 | private int itemsPerPage;
27 |
28 | @Key("opensearch:startIndex")
29 | private int startIndex;
30 |
31 | @Key("opensearch:totalResults")
32 | private int totalResult;
33 |
34 | @Override
35 | public String getObjName() {
36 | return "doubancollectionfeed";
37 | }
38 |
39 | /**
40 | * @return the collections
41 | */
42 | public List getCollections() {
43 | return collections;
44 | }
45 |
46 | /**
47 | * @param collections the collections to set
48 | */
49 | public void setCollections(List collections) {
50 | this.collections = collections;
51 | }
52 |
53 | /**
54 | * @return the author
55 | */
56 | public DoubanAuthorObj getAuthor() {
57 | return author;
58 | }
59 |
60 | /**
61 | * @param author the author to set
62 | */
63 | public void setAuthor(DoubanAuthorObj author) {
64 | this.author = author;
65 | }
66 |
67 | /**
68 | * @return the title
69 | */
70 | public String getTitle() {
71 | return title;
72 | }
73 |
74 | /**
75 | * @param title the title to set
76 | */
77 | public void setTitle(String title) {
78 | this.title = title;
79 | }
80 |
81 | /**
82 | * @return the itemsPerPage
83 | */
84 | public int getItemsPerPage() {
85 | return itemsPerPage;
86 | }
87 |
88 | /**
89 | * @param itemsPerPage the itemsPerPage to set
90 | */
91 | public void setItemsPerPage(int itemsPerPage) {
92 | this.itemsPerPage = itemsPerPage;
93 | }
94 |
95 | /**
96 | * @return the startIndex
97 | */
98 | public int getStartIndex() {
99 | return startIndex;
100 | }
101 |
102 | /**
103 | * @param startIndex the startIndex to set
104 | */
105 | public void setStartIndex(int startIndex) {
106 | this.startIndex = startIndex;
107 | }
108 |
109 | /**
110 | * @return the totalResult
111 | */
112 | public int getTotalResult() {
113 | return totalResult;
114 | }
115 |
116 | /**
117 | * @param totalResult the totalResult to set
118 | */
119 | public void setTotalResult(int totalResult) {
120 | this.totalResult = totalResult;
121 | }
122 |
123 | public boolean hasCollectionEntries () {
124 | return (this.collections != null && this.collections.size() > 0);
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/collection/DoubanCollectionObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.collection;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.dongxuexidu.douban4j.model.IDoubanObject;
7 | import com.dongxuexidu.douban4j.model.common.DoubanAttributeObj;
8 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
9 | import com.dongxuexidu.douban4j.model.common.DoubanRatingObj;
10 | import com.dongxuexidu.douban4j.model.common.DoubanTagObj;
11 | import com.dongxuexidu.douban4j.model.subject.DoubanSubjectObj;
12 | import com.dongxuexidu.douban4j.model.user.DoubanUserObj;
13 | import com.google.api.client.util.Key;
14 |
15 | /**
16 | *
17 | * @author Zhibo Wei
18 | */
19 | public class DoubanCollectionObj implements IDoubanObject{
20 |
21 | @Override
22 | public String getObjName() {
23 | return "doubancollection";
24 | }
25 |
26 | @Key("updated")
27 | private String updateTime = null;
28 |
29 | @Key("db:tag")
30 | private List tags = new ArrayList();
31 |
32 | @Key("author")
33 | private DoubanUserObj author = null;
34 |
35 | @Key
36 | private String title = "";
37 |
38 | @Key("link")
39 | private List links = new ArrayList();
40 |
41 | @Key
42 | private String id;
43 |
44 | @Key("db:subject")
45 | private DoubanSubjectObj subject = null;
46 |
47 | @Key("db:status")
48 | private String status;
49 |
50 | @Key("gd:rating")
51 | private DoubanRatingObj rating = null;
52 |
53 | @Key("content")
54 | private String content;
55 |
56 | @Key("db:attribute")
57 | private List att;
58 |
59 |
60 | @Key("summary")
61 | private String summary;
62 |
63 | /**
64 | * @return user summary on current collection
65 | * */
66 | public String getSummary() {
67 | return summary;
68 | }
69 |
70 | /**
71 | * @param summary to set
72 | * */
73 | public void setSummary(String summary) {
74 | this.summary = summary;
75 | }
76 |
77 |
78 | /**
79 | * @return the updateTime
80 | */
81 | public String getUpdateTime() {
82 | return updateTime;
83 | }
84 |
85 | /**
86 | * @param updateTime the updateTime to set
87 | */
88 | public void setUpdateTime(String updateTime) {
89 | this.updateTime = updateTime;
90 | }
91 |
92 | /**
93 | * @return the tags
94 | */
95 | public List getTags() {
96 | return tags;
97 | }
98 |
99 | /**
100 | * @param tags the tags to set
101 | */
102 | public void setTags(List tags) {
103 | this.tags = tags;
104 | }
105 |
106 | public void addTag (DoubanTagObj tag) {
107 | this.tags.add(tag);
108 | }
109 |
110 | /**
111 | * @return the author
112 | */
113 | public DoubanUserObj getAuthor() {
114 | return author;
115 | }
116 |
117 | /**
118 | * @param author the author to set
119 | */
120 | public void setAuthor(DoubanUserObj author) {
121 | this.author = author;
122 | }
123 |
124 | /**
125 | * @return the title
126 | */
127 | public String getTitle() {
128 | return title;
129 | }
130 |
131 | /**
132 | * @param title the title to set
133 | */
134 | public void setTitle(String title) {
135 | this.title = title;
136 | }
137 |
138 | public void setLinks (List links) {
139 | this.links = links;
140 | }
141 |
142 | public void addLink(DoubanLinkObj link) {
143 | this.links.add(link);
144 | }
145 |
146 | public String getLinkByRel (String rel) {
147 | for (DoubanLinkObj obj : this.links) {
148 | if (obj.getRel().equalsIgnoreCase(rel)) {
149 | return obj.getHref();
150 | }
151 | }
152 | return null;
153 | }
154 |
155 | public List getLinks() {
156 | return this.links;
157 | }
158 |
159 | /**
160 | * @return the id
161 | */
162 | public String getId() {
163 | return id;
164 | }
165 |
166 | /**
167 | * @param id the id to set
168 | */
169 | public void setId(String id) {
170 | this.id = id;
171 | }
172 |
173 | /**
174 | * @return the subject
175 | */
176 | public DoubanSubjectObj getSubject() {
177 | return subject;
178 | }
179 |
180 | /**
181 | * @param subject the subject to set
182 | */
183 | public void setSubject(DoubanSubjectObj subject) {
184 | this.subject = subject;
185 | }
186 |
187 | /**
188 | * @return the status
189 | */
190 | public String getStatus() {
191 | return status;
192 | }
193 |
194 | /**
195 | * @param status the status to set
196 | */
197 | public void setStatus(String status) {
198 | this.status = status;
199 | }
200 |
201 | /**
202 | * @return the rating
203 | */
204 | public DoubanRatingObj getRating() {
205 | return rating;
206 | }
207 |
208 | /**
209 | * @param rating the rating to set
210 | */
211 | public void setRating(DoubanRatingObj rating) {
212 | this.rating = rating;
213 | }
214 |
215 | /**
216 | * @return the content
217 | */
218 | public String getContent() {
219 | return content;
220 | }
221 |
222 | /**
223 | * @param content the content to set
224 | */
225 | public void setContent(String content) {
226 | this.content = content;
227 | }
228 |
229 | /**
230 | * @return the att
231 | */
232 | public List getAtt() {
233 | return att;
234 | }
235 |
236 | /**
237 | * @param att the att to set
238 | */
239 | public void setAtt(List att) {
240 | this.att = att;
241 | }
242 |
243 | }
244 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanAttributeObj.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.model.common;
6 |
7 | import com.dongxuexidu.douban4j.model.IDoubanObject;
8 | import com.google.api.client.util.Key;
9 |
10 | /**
11 | *
12 | * @author Zhibo Wei
13 | */
14 | public class DoubanAttributeObj implements IDoubanObject {
15 |
16 | @Override
17 | public String getObjName() {
18 | return "attribute";
19 | }
20 |
21 | @Key ("@name")
22 | private String name;
23 |
24 | @Key ("text()")
25 | private String value;
26 |
27 | /**
28 | * @return the name
29 | */
30 | public String getName() {
31 | return name;
32 | }
33 |
34 | /**
35 | * @param name the name to set
36 | */
37 | public void setName(String name) {
38 | this.name = name;
39 | }
40 |
41 | /**
42 | * @return the value
43 | */
44 | public String getValue() {
45 | return value;
46 | }
47 |
48 | /**
49 | * @param value the value to set
50 | */
51 | public void setValue(String value) {
52 | this.value = value;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanAuthorObj.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.model.common;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import com.dongxuexidu.douban4j.model.IDoubanObject;
11 | import com.google.api.client.util.Key;
12 |
13 | /**
14 | *
15 | * @author Zhibo Wei
16 | */
17 | public class DoubanAuthorObj implements IDoubanObject {
18 |
19 | @Override
20 | public String getObjName() {
21 | return "author";
22 | }
23 |
24 | @Key
25 | private String name;
26 |
27 | @Key
28 | private String uri;
29 |
30 | @Key ("link")
31 | private List links = new ArrayList();
32 |
33 | /**
34 | * @return the name
35 | */
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | /**
41 | * @param name the name to set
42 | */
43 | public void setName(String name) {
44 | this.name = name;
45 | }
46 |
47 | /**
48 | * @return the uri
49 | */
50 | public String getUri() {
51 | return uri;
52 | }
53 |
54 | /**
55 | * @param uri the uri to set
56 | */
57 | public void setUri(String uri) {
58 | this.uri = uri;
59 | }
60 |
61 | public List getLinks () {
62 | return this.links;
63 | }
64 |
65 | /**
66 | * @return the links
67 | */
68 | public void addLink(String rel, String href) {
69 | this.links.add(new DoubanLinkObj(href, rel));
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanCategoryObj.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.model.common;
6 |
7 | import com.dongxuexidu.douban4j.model.IDoubanObject;
8 | import com.google.api.client.util.Key;
9 |
10 | /**
11 | *
12 | * @author Zhibo Wei
13 | */
14 | public class DoubanCategoryObj implements IDoubanObject {
15 |
16 | @Override
17 | public String getObjName() {
18 | return "category";
19 | }
20 | @Key("@scheme")
21 | private String scheme;
22 |
23 | @Key("@term")
24 | private String term;
25 |
26 | /**
27 | * @return the scheme
28 | */
29 | public String getScheme() {
30 | return scheme;
31 | }
32 |
33 | /**
34 | * @param scheme the scheme to set
35 | */
36 | public void setScheme(String scheme) {
37 | this.scheme = scheme;
38 | }
39 |
40 | /**
41 | * @return the term
42 | */
43 | public String getTerm() {
44 | return term;
45 | }
46 |
47 | /**
48 | * @param term the term to set
49 | */
50 | public void setTerm(String term) {
51 | this.term = term;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanCountObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.common;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | *
8 | * @author Zhibo Wei
9 | */
10 | public class DoubanCountObj implements IDoubanObject{
11 |
12 | @Override
13 | public String getObjName() {
14 | return "doubancommentscount";
15 | }
16 |
17 | @Key("@value")
18 | private int value;
19 |
20 | /**
21 | * @return the value
22 | */
23 | public int getValue() {
24 | return value;
25 | }
26 |
27 | /**
28 | * @param value the value to set
29 | */
30 | public void setValue(int value) {
31 | this.value = value;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanEntityObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.common;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.google.api.client.util.Key;
7 |
8 | /**
9 | *
10 | * @author Zhibo Wei
11 | */
12 | public class DoubanEntityObj implements IDoubanObject {
13 |
14 | @Key("@name")
15 | private String name;
16 |
17 | @Key("link")
18 | private List links;
19 |
20 | @Key("name")
21 | private String displayName;
22 |
23 | @Key("uri")
24 | private String uri;
25 |
26 | @Override
27 | public String getObjName() {
28 | return "doubanentity";
29 | }
30 |
31 | /**
32 | * @return the name
33 | */
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | /**
39 | * @param name the name to set
40 | */
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 |
45 | public void setLinks (List links) {
46 | this.links = links;
47 | }
48 |
49 | public void addLink(DoubanLinkObj link) {
50 | this.links.add(link);
51 | }
52 |
53 | public String getLinkByRel (String rel) {
54 | for (DoubanLinkObj obj : this.links) {
55 | if (obj.getRel().equalsIgnoreCase(rel)) {
56 | return obj.getHref();
57 | }
58 | }
59 | return null;
60 | }
61 |
62 | public List getLinks() {
63 | return this.links;
64 | }
65 |
66 | /**
67 | * @return the displayName
68 | */
69 | public String getDisplayName() {
70 | return displayName;
71 | }
72 |
73 | /**
74 | * @param displayName the displayName to set
75 | */
76 | public void setDisplayName(String displayName) {
77 | this.displayName = displayName;
78 | }
79 |
80 | /**
81 | * @return the uri
82 | */
83 | public String getUri() {
84 | return uri;
85 | }
86 |
87 | /**
88 | * @param uri the uri to set
89 | */
90 | public void setUri(String uri) {
91 | this.uri = uri;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanImageObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.common;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | *
8 | * @author Sean Guo
9 | *
10 | */
11 | public class DoubanImageObj implements IDoubanObject {
12 |
13 | @Override
14 | public String getObjName() {
15 | return "image";
16 | }
17 |
18 | @Key("small")
19 | private String small;
20 |
21 | @Key("medium")
22 | private String media;
23 |
24 | @Key("large")
25 | private String large;
26 |
27 | public String getSmall() {
28 | return small;
29 | }
30 |
31 | public void setSmall(String small) {
32 | this.small = small;
33 | }
34 |
35 | public String getMedia() {
36 | return media;
37 | }
38 |
39 | public void setMedia(String media) {
40 | this.media = media;
41 | }
42 |
43 | public String getLarge() {
44 | return large;
45 | }
46 |
47 | public void setLarge(String large) {
48 | this.large = large;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "DoubanImageObj [small=" + small + ", media=" + media
54 | + ", large=" + large + "]";
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanLinkObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.common;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | *
8 | * @author Zhibo Wei
9 | */
10 | public class DoubanLinkObj implements IDoubanObject{
11 |
12 | @Key("@href")
13 | private String href;
14 |
15 | @Key("@rel")
16 | private String rel;
17 |
18 | public DoubanLinkObj (String href, String rel) {
19 | this.href = href;
20 | this.rel = rel;
21 | }
22 |
23 | public DoubanLinkObj() {
24 | //do nothing here at this point
25 | }
26 |
27 | /**
28 | * @return the href
29 | */
30 | public String getHref() {
31 | return href;
32 | }
33 |
34 | /**
35 | * @param href the href to set
36 | */
37 | public void setHref(String href) {
38 | this.href = href;
39 | }
40 |
41 | /**
42 | * @return the rel
43 | */
44 | public String getRel() {
45 | return rel;
46 | }
47 |
48 | /**
49 | * @param rel the rel to set
50 | */
51 | public void setRel(String rel) {
52 | this.rel = rel;
53 | }
54 |
55 | @Override
56 | public String getObjName() {
57 | return "doubanlink";
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanLocationObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.common;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | *
8 | * @author Zhibo Wei
9 | */
10 | public class DoubanLocationObj implements IDoubanObject{
11 |
12 | @Override
13 | public String getObjName() {
14 | return "doubanlocation";
15 | }
16 |
17 | @Key("@id")
18 | private String id;
19 |
20 | @Key("text()")
21 | private String value;
22 |
23 | /**
24 | * @return the id
25 | */
26 | public String getId() {
27 | return id;
28 | }
29 |
30 | /**
31 | * @param id the id to set
32 | */
33 | public void setId(String id) {
34 | this.id = id;
35 | }
36 |
37 | /**
38 | * @return the value
39 | */
40 | public String getValue() {
41 | return value;
42 | }
43 |
44 | /**
45 | * @param value the value to set
46 | */
47 | public void setValue(String value) {
48 | this.value = value;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanRatingObj.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.model.common;
6 |
7 | import com.dongxuexidu.douban4j.model.IDoubanObject;
8 | import com.google.api.client.util.Key;
9 | /**
10 | *
11 | * @author Zhibo Wei
12 | */
13 | public class DoubanRatingObj implements IDoubanObject{
14 |
15 | @Override
16 | public String getObjName() {
17 | return "rating";
18 | }
19 |
20 | @Key("@min")
21 | private int min = 1;
22 |
23 | @Key("@max")
24 | private int max = 5;
25 |
26 | @Key("@value")
27 | private int value = 0;
28 |
29 | @Key("@average")
30 | private float average = 0.0f;
31 |
32 | @Key("@numRaters")
33 | private int numberOfRaters = 0;
34 |
35 | /**
36 | * @return the min
37 | */
38 | public int getMin() {
39 | return min;
40 | }
41 |
42 | /**
43 | * @param min the min to set
44 | */
45 | public void setMin(int min) {
46 | this.min = min;
47 | }
48 |
49 | /**
50 | * @return the max
51 | */
52 | public int getMax() {
53 | return max;
54 | }
55 |
56 | /**
57 | * @param max the max to set
58 | */
59 | public void setMax(int max) {
60 | this.max = max;
61 | }
62 |
63 | /**
64 | * @return the value
65 | */
66 | public int getValue() {
67 | return value;
68 | }
69 |
70 | /**
71 | * @return the numberOfRaters
72 | */
73 | public int getNumberOfRaters() {
74 | return numberOfRaters;
75 | }
76 |
77 | /**
78 | * @param numberOfRaters the numberOfRaters to set
79 | */
80 | public void setNumberOfRaters(int numberOfRaters) {
81 | this.numberOfRaters = numberOfRaters;
82 | }
83 |
84 | /**
85 | * @param value the value to set
86 | */
87 | public void setValue(int value) {
88 | this.value = value;
89 | }
90 |
91 | /**
92 | * @return the average
93 | */
94 | public float getAverage() {
95 | return average;
96 | }
97 |
98 | /**
99 | * @param average the average to set
100 | */
101 | public void setAverage(float average) {
102 | this.average = average;
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanTagObj.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.model.common;
6 |
7 | import com.dongxuexidu.douban4j.model.IDoubanObject;
8 | import com.google.api.client.util.Key;
9 |
10 | /**
11 | *
12 | * @author Zhibo Wei
13 | */
14 | public class DoubanTagObj implements IDoubanObject{
15 |
16 | @Override
17 | public String getObjName() {
18 | return "tag";
19 | }
20 |
21 | @Key("@name")
22 | private String name;
23 |
24 | @Key("@count")
25 | private String count;
26 |
27 | /**
28 | * @return the name
29 | */
30 | public String getName() {
31 | return name;
32 | }
33 |
34 | /**
35 | * @param name the name to set
36 | */
37 | public void setName(String name) {
38 | this.name = name;
39 | }
40 |
41 | /**
42 | * @return the count
43 | */
44 | public String getCount() {
45 | return count;
46 | }
47 |
48 | /**
49 | * @param count the count to set
50 | */
51 | public void setCount(String count) {
52 | this.count = count;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanWhenObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.common;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | *
8 | * @author Zhibo Wei
9 | */
10 | public class DoubanWhenObj implements IDoubanObject{
11 |
12 | @Key("@endTime")
13 | private String endTime;
14 |
15 | @Key("@startTime")
16 | private String startTime;
17 |
18 | @Override
19 | public String getObjName() {
20 | return "doubanwhen";
21 | }
22 |
23 | /**
24 | * @return the endTime
25 | */
26 | public String getEndTime() {
27 | return endTime;
28 | }
29 |
30 | /**
31 | * @param endTime the endTime to set
32 | */
33 | public void setEndTime(String endTime) {
34 | this.endTime = endTime;
35 | }
36 |
37 | /**
38 | * @return the startTime
39 | */
40 | public String getStartTime() {
41 | return startTime;
42 | }
43 |
44 | /**
45 | * @param startTime the startTime to set
46 | */
47 | public void setStartTime(String startTime) {
48 | this.startTime = startTime;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/common/DoubanWhereObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.common;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | *
8 | * @author Zhibo Wei
9 | */
10 | public class DoubanWhereObj implements IDoubanObject{
11 |
12 | @Key("@valueString")
13 | private String value;
14 |
15 | @Override
16 | public String getObjName() {
17 | return "doubanwhere";
18 | }
19 |
20 | /**
21 | * @return the value
22 | */
23 | public String getValue() {
24 | return value;
25 | }
26 |
27 | /**
28 | * @param value the value to set
29 | */
30 | public void setValue(String value) {
31 | this.value = value;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/doumail/DoubanMailEntryObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.doumail;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.dongxuexidu.douban4j.model.common.DoubanAttributeObj;
7 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
8 | import com.dongxuexidu.douban4j.model.common.DoubanEntityObj;
9 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
10 | import com.google.api.client.util.Key;
11 |
12 | /**
13 | *
14 | * @author Zhibo Wei
15 | */
16 | public class DoubanMailEntryObj implements IDoubanObject{
17 |
18 | @Key
19 | private String id;
20 |
21 | @Key
22 | private String title;
23 |
24 | @Key("author")
25 | private DoubanAuthorObj author;
26 |
27 | @Key("published")
28 | private String published;
29 |
30 | @Key("link")
31 | private List links;
32 |
33 | @Key("content")
34 | private String content;
35 |
36 | @Key("db:entity")
37 | private DoubanEntityObj entity;
38 |
39 | @Key("db:attribute")
40 | private DoubanAttributeObj attr;
41 |
42 | @Override
43 | public String getObjName() {
44 | return "doubanmailentry";
45 | }
46 |
47 | /**
48 | * @return the id
49 | */
50 | public String getId() {
51 | return id;
52 | }
53 |
54 | /**
55 | * @param id the id to set
56 | */
57 | public void setId(String id) {
58 | this.id = id;
59 | }
60 |
61 | /**
62 | * @return the title
63 | */
64 | public String getTitle() {
65 | return title;
66 | }
67 |
68 | /**
69 | * @param title the title to set
70 | */
71 | public void setTitle(String title) {
72 | this.title = title;
73 | }
74 |
75 | /**
76 | * @return the author
77 | */
78 | public DoubanAuthorObj getAuthor() {
79 | return author;
80 | }
81 |
82 | /**
83 | * @param author the author to set
84 | */
85 | public void setAuthor(DoubanAuthorObj author) {
86 | this.author = author;
87 | }
88 |
89 | /**
90 | * @return the published
91 | */
92 | public String getPublished() {
93 | return published;
94 | }
95 |
96 | /**
97 | * @param published the published to set
98 | */
99 | public void setPublished(String published) {
100 | this.published = published;
101 | }
102 |
103 | public void setLinks (List links) {
104 | this.links = links;
105 | }
106 |
107 | public void addLink(DoubanLinkObj link) {
108 | this.links.add(link);
109 | }
110 |
111 | public String getLinkByRel (String rel) {
112 | for (DoubanLinkObj obj : this.links) {
113 | if (obj.getRel().equalsIgnoreCase(rel)) {
114 | return obj.getHref();
115 | }
116 | }
117 | return null;
118 | }
119 |
120 | public List getLinks() {
121 | return this.links;
122 | }
123 |
124 | /**
125 | * @return the content
126 | */
127 | public String getContent() {
128 | return content;
129 | }
130 |
131 | /**
132 | * @param content the content to set
133 | */
134 | public void setContent(String content) {
135 | this.content = content;
136 | }
137 |
138 | /**
139 | * @return the entity
140 | */
141 | public DoubanEntityObj getEntity() {
142 | return entity;
143 | }
144 |
145 | /**
146 | * @param entity the entity to set
147 | */
148 | public void setEntity(DoubanEntityObj entity) {
149 | this.entity = entity;
150 | }
151 |
152 | /**
153 | * @return the attr
154 | */
155 | public DoubanAttributeObj getAttr() {
156 | return attr;
157 | }
158 |
159 | /**
160 | * @param attr the attr to set
161 | */
162 | public void setAttr(DoubanAttributeObj attr) {
163 | this.attr = attr;
164 | }
165 |
166 | }
167 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/doumail/DoubanMailFeedObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.doumail;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
7 | import com.google.api.client.util.Key;
8 |
9 | /**
10 | *
11 | * @author Zhibo Wei
12 | */
13 | public class DoubanMailFeedObj implements IDoubanObject{
14 |
15 | @Key
16 | private String title;
17 |
18 | @Key("author")
19 | private DoubanAuthorObj author;
20 |
21 | @Key("opensearch:itemsPerPage")
22 | private int itemsPerPage;
23 |
24 | @Key("opensearch:startIndex")
25 | private int startIndex;
26 |
27 | @Key("opensearch:totalResults")
28 | private int totalResult;
29 |
30 | @Key("entry")
31 | private List entries;
32 |
33 | @Override
34 | public String getObjName() {
35 | return "doubanmailfeed";
36 | }
37 |
38 | /**
39 | * @return the title
40 | */
41 | public String getTitle() {
42 | return title;
43 | }
44 |
45 | /**
46 | * @param title the title to set
47 | */
48 | public void setTitle(String title) {
49 | this.title = title;
50 | }
51 |
52 | /**
53 | * @return the author
54 | */
55 | public DoubanAuthorObj getAuthor() {
56 | return author;
57 | }
58 |
59 | /**
60 | * @param author the author to set
61 | */
62 | public void setAuthor(DoubanAuthorObj author) {
63 | this.author = author;
64 | }
65 |
66 | /**
67 | * @return the itemsPerPage
68 | */
69 | public int getItemsPerPage() {
70 | return itemsPerPage;
71 | }
72 |
73 | /**
74 | * @param itemsPerPage the itemsPerPage to set
75 | */
76 | public void setItemsPerPage(int itemsPerPage) {
77 | this.itemsPerPage = itemsPerPage;
78 | }
79 |
80 | /**
81 | * @return the startIndex
82 | */
83 | public int getStartIndex() {
84 | return startIndex;
85 | }
86 |
87 | /**
88 | * @param startIndex the startIndex to set
89 | */
90 | public void setStartIndex(int startIndex) {
91 | this.startIndex = startIndex;
92 | }
93 |
94 | /**
95 | * @return the entries
96 | */
97 | public List getEntries() {
98 | return entries;
99 | }
100 |
101 | /**
102 | * @param entries the entries to set
103 | */
104 | public void setEntries(List entries) {
105 | this.entries = entries;
106 | }
107 |
108 | /**
109 | * @return the totalResult
110 | */
111 | public int getTotalResult() {
112 | return totalResult;
113 | }
114 |
115 | /**
116 | * @param totalResult the totalResult to set
117 | */
118 | public void setTotalResult(int totalResult) {
119 | this.totalResult = totalResult;
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/event/DoubanEventEntryObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.event;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.dongxuexidu.douban4j.model.common.DoubanAttributeObj;
7 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
8 | import com.dongxuexidu.douban4j.model.common.DoubanCategoryObj;
9 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
10 | import com.dongxuexidu.douban4j.model.common.DoubanLocationObj;
11 | import com.dongxuexidu.douban4j.model.common.DoubanWhenObj;
12 | import com.dongxuexidu.douban4j.model.common.DoubanWhereObj;
13 | import com.google.api.client.util.Key;
14 |
15 | /**
16 | *
17 | * @author Zhibo Wei
18 | */
19 | public class DoubanEventEntryObj implements IDoubanObject{
20 |
21 | @Override
22 | public String getObjName() {
23 | return "doubanevent";
24 | }
25 |
26 | @Key
27 | private String id;
28 |
29 | @Key
30 | private String title;
31 |
32 | @Key("category")
33 | private DoubanCategoryObj category;
34 |
35 | @Key("author")
36 | private DoubanAuthorObj author;
37 |
38 | @Key("link")
39 | private List links;
40 |
41 | @Key("summary")
42 | private String summary;
43 |
44 | @Key("content")
45 | private String content;
46 |
47 | @Key("db:attribute")
48 | private List attrs;
49 |
50 | @Key("db:location")
51 | private DoubanLocationObj locaiton;
52 |
53 | @Key("gd:when")
54 | private DoubanWhenObj when;
55 |
56 | @Key("gd:where")
57 | private DoubanWhereObj where;
58 |
59 | /**
60 | * @return the id
61 | */
62 | public String getId() {
63 | return id;
64 | }
65 |
66 | /**
67 | * @param id the id to set
68 | */
69 | public void setId(String id) {
70 | this.id = id;
71 | }
72 |
73 | /**
74 | * @return the title
75 | */
76 | public String getTitle() {
77 | return title;
78 | }
79 |
80 | /**
81 | * @param title the title to set
82 | */
83 | public void setTitle(String title) {
84 | this.title = title;
85 | }
86 |
87 | /**
88 | * @return the category
89 | */
90 | public DoubanCategoryObj getCategory() {
91 | return category;
92 | }
93 |
94 | /**
95 | * @param category the category to set
96 | */
97 | public void setCategory(DoubanCategoryObj category) {
98 | this.category = category;
99 | }
100 |
101 | /**
102 | * @return the author
103 | */
104 | public DoubanAuthorObj getAuthor() {
105 | return author;
106 | }
107 |
108 | /**
109 | * @param author the author to set
110 | */
111 | public void setAuthor(DoubanAuthorObj author) {
112 | this.author = author;
113 | }
114 |
115 | public void setLinks (List links) {
116 | this.links = links;
117 | }
118 |
119 | public void addLink(DoubanLinkObj link) {
120 | this.links.add(link);
121 | }
122 |
123 | public String getLinkByRel (String rel) {
124 | for (DoubanLinkObj obj : this.links) {
125 | if (obj.getRel().equalsIgnoreCase(rel)) {
126 | return obj.getHref();
127 | }
128 | }
129 | return null;
130 | }
131 |
132 | public List getLinks() {
133 | return this.links;
134 | }
135 |
136 | /**
137 | * @return the summary
138 | */
139 | public String getSummary() {
140 | return summary;
141 | }
142 |
143 | /**
144 | * @param summary the summary to set
145 | */
146 | public void setSummary(String summary) {
147 | this.summary = summary;
148 | }
149 |
150 | /**
151 | * @return the content
152 | */
153 | public String getContent() {
154 | return content;
155 | }
156 |
157 | /**
158 | * @param content the content to set
159 | */
160 | public void setContent(String content) {
161 | this.content = content;
162 | }
163 |
164 | /**
165 | * @return the attrs
166 | */
167 | public List getAttrs() {
168 | return attrs;
169 | }
170 |
171 | /**
172 | * @param attrs the attrs to set
173 | */
174 | public void setAttrs(List attrs) {
175 | this.attrs = attrs;
176 | }
177 |
178 | /**
179 | * @return the locaiton
180 | */
181 | public DoubanLocationObj getLocaiton() {
182 | return locaiton;
183 | }
184 |
185 | /**
186 | * @param locaiton the locaiton to set
187 | */
188 | public void setLocaiton(DoubanLocationObj locaiton) {
189 | this.locaiton = locaiton;
190 | }
191 |
192 | /**
193 | * @return the when
194 | */
195 | public DoubanWhenObj getWhen() {
196 | return when;
197 | }
198 |
199 | /**
200 | * @param when the when to set
201 | */
202 | public void setWhen(DoubanWhenObj when) {
203 | this.when = when;
204 | }
205 |
206 | /**
207 | * @return the where
208 | */
209 | public DoubanWhereObj getWhere() {
210 | return where;
211 | }
212 |
213 | /**
214 | * @param where the where to set
215 | */
216 | public void setWhere(DoubanWhereObj where) {
217 | this.where = where;
218 | }
219 |
220 | }
221 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/event/DoubanEventFeedObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.event;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
7 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
8 | import com.google.api.client.util.Key;
9 |
10 | /**
11 | *
12 | * @author Zhibo Wei
13 | */
14 | public class DoubanEventFeedObj implements IDoubanObject{
15 |
16 | @Key
17 | private String title;
18 |
19 | @Key("author")
20 | private DoubanAuthorObj author;
21 |
22 | @Key("link")
23 | private List links;
24 |
25 | @Key("opensearch:itemsPerPage")
26 | private int itemsPerPage;
27 |
28 | @Key("opensearch:startIndex")
29 | private int startIndex;
30 |
31 | @Key("opensearch:totalResults")
32 | private int totalResult;
33 |
34 | @Key("entry")
35 | private List entries;
36 |
37 | @Override
38 | public String getObjName() {
39 | return "doubaneventfeed";
40 | }
41 |
42 | /**
43 | * @return the title
44 | */
45 | public String getTitle() {
46 | return title;
47 | }
48 |
49 | /**
50 | * @param title the title to set
51 | */
52 | public void setTitle(String title) {
53 | this.title = title;
54 | }
55 |
56 | /**
57 | * @return the author
58 | */
59 | public DoubanAuthorObj getAuthor() {
60 | return author;
61 | }
62 |
63 | /**
64 | * @param author the author to set
65 | */
66 | public void setAuthor(DoubanAuthorObj author) {
67 | this.author = author;
68 | }
69 |
70 | public void setLinks (List links) {
71 | this.links = links;
72 | }
73 |
74 | public void addLink(DoubanLinkObj link) {
75 | this.links.add(link);
76 | }
77 |
78 | public String getLinkByRel (String rel) {
79 | for (DoubanLinkObj obj : this.links) {
80 | if (obj.getRel().equalsIgnoreCase(rel)) {
81 | return obj.getHref();
82 | }
83 | }
84 | return null;
85 | }
86 |
87 | public List getLinks() {
88 | return this.links;
89 | }
90 |
91 | /**
92 | * @return the itemsPerPage
93 | */
94 | public int getItemsPerPage() {
95 | return itemsPerPage;
96 | }
97 |
98 | /**
99 | * @param itemsPerPage the itemsPerPage to set
100 | */
101 | public void setItemsPerPage(int itemsPerPage) {
102 | this.itemsPerPage = itemsPerPage;
103 | }
104 |
105 | /**
106 | * @return the startIndex
107 | */
108 | public int getStartIndex() {
109 | return startIndex;
110 | }
111 |
112 | /**
113 | * @param startIndex the startIndex to set
114 | */
115 | public void setStartIndex(int startIndex) {
116 | this.startIndex = startIndex;
117 | }
118 |
119 | /**
120 | * @return the totalResult
121 | */
122 | public int getTotalResult() {
123 | return totalResult;
124 | }
125 |
126 | /**
127 | * @param totalResult the totalResult to set
128 | */
129 | public void setTotalResult(int totalResult) {
130 | this.totalResult = totalResult;
131 | }
132 |
133 | /**
134 | * @return the entries
135 | */
136 | public List getEntries() {
137 | return entries;
138 | }
139 |
140 | /**
141 | * @param entries the entries to set
142 | */
143 | public void setEntries(List entries) {
144 | this.entries = entries;
145 | }
146 |
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/note/DoubanNoteEntryObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.note;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.dongxuexidu.douban4j.model.common.DoubanAttributeObj;
7 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
8 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
9 | import com.google.api.client.util.Key;
10 |
11 | /**
12 | *
13 | * @author Zhibo Wei
14 | */
15 | public class DoubanNoteEntryObj implements IDoubanObject{
16 |
17 | @Key
18 | private String id;
19 |
20 | @Key
21 | private String title;
22 |
23 | @Key("author")
24 | private DoubanAuthorObj author;
25 |
26 | @Key("published")
27 | private String published;
28 |
29 | @Key("updated")
30 | private String updated;
31 |
32 | @Key("link")
33 | private List links;
34 |
35 | @Key
36 | private String summary;
37 |
38 | @Key
39 | private String content;
40 |
41 | @Key("db:attribute")
42 | private List attributes;
43 |
44 | @Override
45 | public String getObjName() {
46 | return "doubannote";
47 | }
48 |
49 | /**
50 | * @return the id
51 | */
52 | public String getId() {
53 | return id;
54 | }
55 |
56 | /**
57 | * @param id the id to set
58 | */
59 | public void setId(String id) {
60 | this.id = id;
61 | }
62 |
63 | /**
64 | * @return the title
65 | */
66 | public String getTitle() {
67 | return title;
68 | }
69 |
70 | /**
71 | * @param title the title to set
72 | */
73 | public void setTitle(String title) {
74 | this.title = title;
75 | }
76 |
77 | /**
78 | * @return the author
79 | */
80 | public DoubanAuthorObj getAuthor() {
81 | return author;
82 | }
83 |
84 | /**
85 | * @param author the author to set
86 | */
87 | public void setAuthor(DoubanAuthorObj author) {
88 | this.author = author;
89 | }
90 |
91 | /**
92 | * @return the published
93 | */
94 | public String getPublished() {
95 | return published;
96 | }
97 |
98 | /**
99 | * @param published the published to set
100 | */
101 | public void setPublished(String published) {
102 | this.published = published;
103 | }
104 |
105 | /**
106 | * @return the updated
107 | */
108 | public String getUpdated() {
109 | return updated;
110 | }
111 |
112 | /**
113 | * @param updated the updated to set
114 | */
115 | public void setUpdated(String updated) {
116 | this.updated = updated;
117 | }
118 |
119 | public void setLinks (List links) {
120 | this.links = links;
121 | }
122 |
123 | public void addLink(DoubanLinkObj link) {
124 | this.links.add(link);
125 | }
126 |
127 | public String getLinkByRel (String rel) {
128 | for (DoubanLinkObj obj : this.links) {
129 | if (obj.getRel().equalsIgnoreCase(rel)) {
130 | return obj.getHref();
131 | }
132 | }
133 | return null;
134 | }
135 |
136 | public List getLinks() {
137 | return this.links;
138 | }
139 |
140 | /**
141 | * @return the summary
142 | */
143 | public String getSummary() {
144 | return summary;
145 | }
146 |
147 | /**
148 | * @param summary the summary to set
149 | */
150 | public void setSummary(String summary) {
151 | this.summary = summary;
152 | }
153 |
154 | /**
155 | * @return the content
156 | */
157 | public String getContent() {
158 | return content;
159 | }
160 |
161 | /**
162 | * @param content the content to set
163 | */
164 | public void setContent(String content) {
165 | this.content = content;
166 | }
167 |
168 | /**
169 | * @return the attributes
170 | */
171 | public List getAttributes() {
172 | return attributes;
173 | }
174 |
175 | /**
176 | * @param attributes the attributes to set
177 | */
178 | public void setAttributes(List attributes) {
179 | this.attributes = attributes;
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/note/DoubanNoteFeedObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.note;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
7 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
8 | import com.google.api.client.util.Key;
9 |
10 | /**
11 | *
12 | * @author Zhibo Wei
13 | */
14 | public class DoubanNoteFeedObj implements IDoubanObject {
15 |
16 | @Key
17 | private String title;
18 |
19 | @Key("author")
20 | private DoubanAuthorObj author;
21 |
22 | @Key("link")
23 | private List links;
24 |
25 | @Key("opensearch:itemsPerPage")
26 | private int itemsPerPage;
27 |
28 | @Key("opensearch:startIndex")
29 | private int startIndex;
30 |
31 | @Key("entry")
32 | private List entries;
33 |
34 | @Override
35 | public String getObjName() {
36 | return "doubannotefeed";
37 | }
38 |
39 | /**
40 | * @return the title
41 | */
42 | public String getTitle() {
43 | return title;
44 | }
45 |
46 | /**
47 | * @param title the title to set
48 | */
49 | public void setTitle(String title) {
50 | this.title = title;
51 | }
52 |
53 | /**
54 | * @return the author
55 | */
56 | public DoubanAuthorObj getAuthor() {
57 | return author;
58 | }
59 |
60 | /**
61 | * @param author the author to set
62 | */
63 | public void setAuthor(DoubanAuthorObj author) {
64 | this.author = author;
65 | }
66 |
67 | public void setLinks (List links) {
68 | this.links = links;
69 | }
70 |
71 | public void addLink(DoubanLinkObj link) {
72 | this.links.add(link);
73 | }
74 |
75 | public String getLinkByRel (String rel) {
76 | for (DoubanLinkObj obj : this.links) {
77 | if (obj.getRel().equalsIgnoreCase(rel)) {
78 | return obj.getHref();
79 | }
80 | }
81 | return null;
82 | }
83 |
84 | public List getLinks() {
85 | return this.links;
86 | }
87 |
88 | /**
89 | * @return the itemsPerPage
90 | */
91 | public int getItemsPerPage() {
92 | return itemsPerPage;
93 | }
94 |
95 | /**
96 | * @param itemsPerPage the itemsPerPage to set
97 | */
98 | public void setItemsPerPage(int itemsPerPage) {
99 | this.itemsPerPage = itemsPerPage;
100 | }
101 |
102 | /**
103 | * @return the startIndex
104 | */
105 | public int getStartIndex() {
106 | return startIndex;
107 | }
108 |
109 | /**
110 | * @param startIndex the startIndex to set
111 | */
112 | public void setStartIndex(int startIndex) {
113 | this.startIndex = startIndex;
114 | }
115 |
116 | /**
117 | * @return the entries
118 | */
119 | public List getEntries() {
120 | return entries;
121 | }
122 |
123 | /**
124 | * @param entries the entries to set
125 | */
126 | public void setEntries(List entries) {
127 | this.entries = entries;
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/review/DoubanReviewEntryObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.review;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
7 | import com.dongxuexidu.douban4j.model.common.DoubanCountObj;
8 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
9 | import com.dongxuexidu.douban4j.model.common.DoubanRatingObj;
10 | import com.dongxuexidu.douban4j.model.subject.DoubanSubjectObj;
11 | import com.google.api.client.util.Key;
12 |
13 | /**
14 | *
15 | * @author Zhibo Wei
16 | */
17 | public class DoubanReviewEntryObj implements IDoubanObject {
18 |
19 | @Override
20 | public String getObjName() {
21 | return "doubanreviewentry";
22 | }
23 |
24 | @Key
25 | private String id;
26 |
27 | @Key
28 | private String title;
29 |
30 | @Key("author")
31 | private DoubanAuthorObj author;
32 |
33 | @Key("published")
34 | private String publishedTime;
35 |
36 | @Key("content")
37 | private String content;
38 |
39 | @Key("updated")
40 | private String updatedTime;
41 |
42 | @Key("link")
43 | private List links;
44 |
45 | @Key("summary")
46 | private String summary;
47 |
48 | @Key("db:comments")
49 | private DoubanCountObj commentsCount;
50 |
51 | @Key("db:subject")
52 | private DoubanSubjectObj subject;
53 |
54 | @Key("db:useless")
55 | private DoubanCountObj uselessCount;
56 |
57 | @Key("db:votes")
58 | private DoubanCountObj usefulCount;
59 |
60 | @Key("gd:rating")
61 | private DoubanRatingObj rating;
62 |
63 | /**
64 | * @return the id
65 | */
66 | public String getId() {
67 | return id;
68 | }
69 |
70 | /**
71 | * @param id the id to set
72 | */
73 | public void setId(String id) {
74 | this.id = id;
75 | }
76 |
77 | /**
78 | * @return the title
79 | */
80 | public String getTitle() {
81 | return title;
82 | }
83 |
84 | /**
85 | * @param title the title to set
86 | */
87 | public void setTitle(String title) {
88 | this.title = title;
89 | }
90 |
91 | /**
92 | * @return the author
93 | */
94 | public DoubanAuthorObj getAuthor() {
95 | return author;
96 | }
97 |
98 | /**
99 | * @param author the author to set
100 | */
101 | public void setAuthor(DoubanAuthorObj author) {
102 | this.author = author;
103 | }
104 |
105 | /**
106 | * @return the publishedTime
107 | */
108 | public String getPublishedTime() {
109 | return publishedTime;
110 | }
111 |
112 | /**
113 | * @param publishedTime the publishedTime to set
114 | */
115 | public void setPublishedTime(String publishedTime) {
116 | this.publishedTime = publishedTime;
117 | }
118 |
119 | /**
120 | * @return the updatedTime
121 | */
122 | public String getUpdatedTime() {
123 | return updatedTime;
124 | }
125 |
126 | /**
127 | * @param updatedTime the updatedTime to set
128 | */
129 | public void setUpdatedTime(String updatedTime) {
130 | this.updatedTime = updatedTime;
131 | }
132 |
133 | public void setLinks (List links) {
134 | this.links = links;
135 | }
136 |
137 | public void addLink(DoubanLinkObj link) {
138 | this.links.add(link);
139 | }
140 |
141 | public String getLinkByRel (String rel) {
142 | for (DoubanLinkObj obj : this.links) {
143 | if (obj.getRel().equalsIgnoreCase(rel)) {
144 | return obj.getHref();
145 | }
146 | }
147 | return null;
148 | }
149 |
150 | public List getLinks() {
151 | return this.links;
152 | }
153 |
154 | /**
155 | * @return the summary
156 | */
157 | public String getSummary() {
158 | return summary;
159 | }
160 |
161 | /**
162 | * @param summary the summary to set
163 | */
164 | public void setSummary(String summary) {
165 | this.summary = summary;
166 | }
167 |
168 | /**
169 | * @return the commentsCount
170 | */
171 | public DoubanCountObj getCommentsCount() {
172 | return commentsCount;
173 | }
174 |
175 | /**
176 | * @param commentsCount the commentsCount to set
177 | */
178 | public void setCommentsCount(DoubanCountObj commentsCount) {
179 | this.commentsCount = commentsCount;
180 | }
181 |
182 | /**
183 | * @return the subject
184 | */
185 | public DoubanSubjectObj getSubject() {
186 | return subject;
187 | }
188 |
189 | /**
190 | * @param subject the subject to set
191 | */
192 | public void setSubject(DoubanSubjectObj subject) {
193 | this.subject = subject;
194 | }
195 |
196 | /**
197 | * @return the uselessCount
198 | */
199 | public DoubanCountObj getUselessCount() {
200 | return uselessCount;
201 | }
202 |
203 | /**
204 | * @param uselessCount the uselessCount to set
205 | */
206 | public void setUselessCount(DoubanCountObj uselessCount) {
207 | this.uselessCount = uselessCount;
208 | }
209 |
210 | /**
211 | * @return the usefulCount
212 | */
213 | public DoubanCountObj getUsefulCount() {
214 | return usefulCount;
215 | }
216 |
217 | /**
218 | * @param usefulCount the usefulCount to set
219 | */
220 | public void setUsefulCount(DoubanCountObj usefulCount) {
221 | this.usefulCount = usefulCount;
222 | }
223 |
224 | /**
225 | * @return the rating
226 | */
227 | public DoubanRatingObj getRating() {
228 | return rating;
229 | }
230 |
231 | /**
232 | * @param rating the rating to set
233 | */
234 | public void setRating(DoubanRatingObj rating) {
235 | this.rating = rating;
236 | }
237 |
238 | /**
239 | * @return the content
240 | */
241 | public String getContent() {
242 | return content;
243 | }
244 |
245 | /**
246 | * @param content the content to set
247 | */
248 | public void setContent(String content) {
249 | this.content = content;
250 | }
251 |
252 | }
253 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/review/DoubanReviewFeedObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.review;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
7 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
8 | import com.google.api.client.util.Key;
9 |
10 | /**
11 | *
12 | * @author Zhibo Wei
13 | */
14 | public class DoubanReviewFeedObj implements IDoubanObject{
15 |
16 | @Override
17 | public String getObjName() {
18 | return "doubanreviewfeed";
19 | }
20 |
21 | @Key
22 | private String title;
23 |
24 | @Key("author")
25 | private DoubanAuthorObj author;
26 |
27 | @Key("link")
28 | private List links;
29 |
30 | @Key("opensearch:itemsPerPage")
31 | private int itemsPerPage;
32 |
33 | @Key("opensearch:startIndex")
34 | private int startIndex;
35 |
36 | @Key("opensearch:totalResults")
37 | private int totalResult;
38 |
39 | @Key("entry")
40 | private List reviews;
41 |
42 | /**
43 | * @return the title
44 | */
45 | public String getTitle() {
46 | return title;
47 | }
48 |
49 | /**
50 | * @param title the title to set
51 | */
52 | public void setTitle(String title) {
53 | this.title = title;
54 | }
55 |
56 | /**
57 | * @return the author
58 | */
59 | public DoubanAuthorObj getAuthor() {
60 | return author;
61 | }
62 |
63 | /**
64 | * @param author the author to set
65 | */
66 | public void setAuthor(DoubanAuthorObj author) {
67 | this.author = author;
68 | }
69 |
70 | public void setLinks (List links) {
71 | this.links = links;
72 | }
73 |
74 | public void addLink(DoubanLinkObj link) {
75 | this.links.add(link);
76 | }
77 |
78 | public String getLinkByRel (String rel) {
79 | for (DoubanLinkObj obj : this.links) {
80 | if (obj.getRel().equalsIgnoreCase(rel)) {
81 | return obj.getHref();
82 | }
83 | }
84 | return null;
85 | }
86 |
87 | public List getLinks() {
88 | return this.links;
89 | }
90 |
91 | /**
92 | * @return the itemsPerPage
93 | */
94 | public int getItemsPerPage() {
95 | return itemsPerPage;
96 | }
97 |
98 | /**
99 | * @param itemsPerPage the itemsPerPage to set
100 | */
101 | public void setItemsPerPage(int itemsPerPage) {
102 | this.itemsPerPage = itemsPerPage;
103 | }
104 |
105 | /**
106 | * @return the startIndex
107 | */
108 | public int getStartIndex() {
109 | return startIndex;
110 | }
111 |
112 | /**
113 | * @param startIndex the startIndex to set
114 | */
115 | public void setStartIndex(int startIndex) {
116 | this.startIndex = startIndex;
117 | }
118 |
119 | /**
120 | * @return the totalResult
121 | */
122 | public int getTotalResult() {
123 | return totalResult;
124 | }
125 |
126 | /**
127 | * @param totalResult the totalResult to set
128 | */
129 | public void setTotalResult(int totalResult) {
130 | this.totalResult = totalResult;
131 | }
132 |
133 | /**
134 | * @return the reviews
135 | */
136 | public List getReviews() {
137 | return reviews;
138 | }
139 |
140 | /**
141 | * @param reviews the reviews to set
142 | */
143 | public void setReviews(List reviews) {
144 | this.reviews = reviews;
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/shuo/DoubanShuoAttachementObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.shuo;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.dongxuexidu.douban4j.model.IDoubanObject;
7 | import com.google.api.client.util.Key;
8 |
9 | /**
10 | *
11 | * @author Zhibo Wei
12 | */
13 | public class DoubanShuoAttachementObj implements IDoubanObject {
14 |
15 | @Key("description")
16 | private String description;
17 |
18 | @Key("title")
19 | private String title;
20 |
21 | @Key("media")
22 | private List medias = new ArrayList();
23 |
24 | @Key("expaned_href")
25 | private String expanedHref;
26 |
27 | @Key("href")
28 | private String href;
29 |
30 | @Key("caption")
31 | private String caption;
32 |
33 | @Key("type")
34 | private String type;
35 |
36 | @Override
37 | public String getObjName() {
38 | return "doubanshuoattachement";
39 | }
40 |
41 | /**
42 | * @return the description
43 | */
44 | public String getDescription() {
45 | return description;
46 | }
47 |
48 | /**
49 | * @param description the description to set
50 | */
51 | public void setDescription(String description) {
52 | this.description = description;
53 | }
54 |
55 | /**
56 | * @return the title
57 | */
58 | public String getTitle() {
59 | return title;
60 | }
61 |
62 | /**
63 | * @param title the title to set
64 | */
65 | public void setTitle(String title) {
66 | this.title = title;
67 | }
68 |
69 | /**
70 | * @return the medias
71 | */
72 | public List getMedias() {
73 | return medias;
74 | }
75 |
76 | /**
77 | * @param medias the medias to set
78 | */
79 | public void setMedias(List medias) {
80 | this.medias = medias;
81 | }
82 |
83 | /**
84 | * @return the expanedHref
85 | */
86 | public String getExpanedHref() {
87 | return expanedHref;
88 | }
89 |
90 | /**
91 | * @param expanedHref the expanedHref to set
92 | */
93 | public void setExpanedHref(String expanedHref) {
94 | this.expanedHref = expanedHref;
95 | }
96 |
97 | /**
98 | * @return the href
99 | */
100 | public String getHref() {
101 | return href;
102 | }
103 |
104 | /**
105 | * @param href the href to set
106 | */
107 | public void setHref(String href) {
108 | this.href = href;
109 | }
110 |
111 | /**
112 | * @return the caption
113 | */
114 | public String getCaption() {
115 | return caption;
116 | }
117 |
118 | /**
119 | * @param caption the caption to set
120 | */
121 | public void setCaption(String caption) {
122 | this.caption = caption;
123 | }
124 |
125 | /**
126 | * @return the type
127 | */
128 | public String getType() {
129 | return type;
130 | }
131 |
132 | /**
133 | * @param type the type to set
134 | */
135 | public void setType(String type) {
136 | this.type = type;
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/shuo/DoubanShuoMediaObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.shuo;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | *
8 | * @author Zhibo Wei
9 | */
10 | public class DoubanShuoMediaObj implements IDoubanObject{
11 |
12 | @Key
13 | private String src;
14 |
15 | @Key
16 | private String href;
17 |
18 | @Key("original_src")
19 | private String originalSrc;
20 |
21 | @Key("type")
22 | private String type;
23 |
24 | @Override
25 | public String getObjName() {
26 | return "doubanshuomedia";
27 | }
28 |
29 | /**
30 | * @return the src
31 | */
32 | public String getSrc() {
33 | return src;
34 | }
35 |
36 | /**
37 | * @param src the src to set
38 | */
39 | public void setSrc(String src) {
40 | this.src = src;
41 | }
42 |
43 | /**
44 | * @return the href
45 | */
46 | public String getHref() {
47 | return href;
48 | }
49 |
50 | /**
51 | * @param href the href to set
52 | */
53 | public void setHref(String href) {
54 | this.href = href;
55 | }
56 |
57 | /**
58 | * @return the originalSrc
59 | */
60 | public String getOriginalSrc() {
61 | return originalSrc;
62 | }
63 |
64 | /**
65 | * @param originalSrc the originalSrc to set
66 | */
67 | public void setOriginalSrc(String originalSrc) {
68 | this.originalSrc = originalSrc;
69 | }
70 |
71 | /**
72 | * @return the type
73 | */
74 | public String getType() {
75 | return type;
76 | }
77 |
78 | /**
79 | * @param type the type to set
80 | */
81 | public void setType(String type) {
82 | this.type = type;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/shuo/DoubanShuoStatusObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.shuo;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.dongxuexidu.douban4j.model.IDoubanObject;
7 | import com.google.api.client.util.Key;
8 |
9 | /**
10 | *
11 | * @author Zhibo Wei
12 | */
13 | public class DoubanShuoStatusObj implements IDoubanObject{
14 |
15 | @Key("reshared_count")
16 | private int resharedCount = 0;
17 |
18 | @Key("text")
19 | private String text;
20 |
21 | @Key("liked")
22 | private boolean liked = false;
23 |
24 | @Key("like_count")
25 | private int likeCount = 0;
26 |
27 | @Key("object_id")
28 | private String objectId;
29 |
30 | @Key("id")
31 | private long id;
32 |
33 | @Key("category")
34 | private String category;
35 |
36 | //WTF with this one?
37 | // @Key("can_reply")
38 | // private boolean canReply;
39 |
40 | // @Key("layout")
41 | // private int layout;
42 |
43 | @Key("title")
44 | private String title;
45 |
46 | @Key("muted")
47 | private boolean muted = false;
48 |
49 | @Key("favorited")
50 | private boolean favorited = false;
51 |
52 | @Key("created_at")
53 | private String createdTime;
54 |
55 | @Key("target_type")
56 | private String targetType;
57 |
58 | @Key("short_title")
59 | private String shortTitle;
60 |
61 | @Key("comments_count")
62 | private int commentsCount;
63 |
64 | @Key("render_success")
65 | private boolean renderSuccess;
66 |
67 | @Key("action")
68 | private String action;
69 |
70 | // @Key("tmpl_ver")
71 | // private int tmplVer;
72 |
73 | @Key("type")
74 | private String type;
75 |
76 | @Key("source")
77 | private String source;
78 |
79 | @Key("user")
80 | private DoubanShuoUserObj user;
81 |
82 | @Key("attachments")
83 | private List attachements = new ArrayList();
84 |
85 | @Override
86 | public String getObjName() {
87 | return "doubanshuostatus";
88 | }
89 |
90 | /**
91 | * @return the resharedCount
92 | */
93 | public int getResharedCount() {
94 | return resharedCount;
95 | }
96 |
97 | /**
98 | * @param resharedCount the resharedCount to set
99 | */
100 | public void setResharedCount(int resharedCount) {
101 | this.resharedCount = resharedCount;
102 | }
103 |
104 | /**
105 | * @return the text
106 | */
107 | public String getText() {
108 | return text;
109 | }
110 |
111 | /**
112 | * @param text the text to set
113 | */
114 | public void setText(String text) {
115 | this.text = text;
116 | }
117 |
118 | /**
119 | * @return the liked
120 | */
121 | public boolean isLiked() {
122 | return liked;
123 | }
124 |
125 | /**
126 | * @param liked the liked to set
127 | */
128 | public void setLiked(boolean liked) {
129 | this.liked = liked;
130 | }
131 |
132 | /**
133 | * @return the likeCount
134 | */
135 | public int getLikeCount() {
136 | return likeCount;
137 | }
138 |
139 | /**
140 | * @param likeCount the likeCount to set
141 | */
142 | public void setLikeCount(int likeCount) {
143 | this.likeCount = likeCount;
144 | }
145 |
146 | /**
147 | * @return the objectId
148 | */
149 | public String getObjectId() {
150 | return objectId;
151 | }
152 |
153 | /**
154 | * @param objectId the objectId to set
155 | */
156 | public void setObjectId(String objectId) {
157 | this.objectId = objectId;
158 | }
159 |
160 | /**
161 | * @return the id
162 | */
163 | public long getId() {
164 | return id;
165 | }
166 |
167 | /**
168 | * @param id the id to set
169 | */
170 | public void setId(long id) {
171 | this.id = id;
172 | }
173 |
174 | /**
175 | * @return the category
176 | */
177 | public String getCategory() {
178 | return category;
179 | }
180 |
181 | /**
182 | * @param category the category to set
183 | */
184 | public void setCategory(String category) {
185 | this.category = category;
186 | }
187 |
188 | // /**
189 | // * @return the canReply
190 | // */
191 | // public boolean canReply() {
192 | // return canReply;
193 | // }
194 | //
195 | // /**
196 | // * @param canReply the canReply to set
197 | // */
198 | // public void setCanReply(boolean canReply) {
199 | // this.canReply = canReply;
200 | // }
201 |
202 | // /**
203 | // * @return the layout
204 | // */
205 | // public int getLayout() {
206 | // return layout;
207 | // }
208 | //
209 | // /**
210 | // * @param layout the layout to set
211 | // */
212 | // public void setLayout(int layout) {
213 | // this.layout = layout;
214 | // }
215 |
216 | /**
217 | * @return the title
218 | */
219 | public String getTitle() {
220 | return title;
221 | }
222 |
223 | /**
224 | * @param title the title to set
225 | */
226 | public void setTitle(String title) {
227 | this.title = title;
228 | }
229 |
230 | /**
231 | * @return the muted
232 | */
233 | public boolean isMuted() {
234 | return muted;
235 | }
236 |
237 | /**
238 | * @param muted the muted to set
239 | */
240 | public void setMuted(boolean muted) {
241 | this.muted = muted;
242 | }
243 |
244 | /**
245 | * @return the createdTime
246 | */
247 | public String getCreatedTime() {
248 | return createdTime;
249 | }
250 |
251 | /**
252 | * @param createdTime the createdTime to set
253 | */
254 | public void setCreatedTime(String createdTime) {
255 | this.createdTime = createdTime;
256 | }
257 |
258 | /**
259 | * @return the targetType
260 | */
261 | public String getTargetType() {
262 | return targetType;
263 | }
264 |
265 | /**
266 | * @param targetType the targetType to set
267 | */
268 | public void setTargetType(String targetType) {
269 | this.targetType = targetType;
270 | }
271 |
272 | /**
273 | * @return the shortTitle
274 | */
275 | public String getShortTitle() {
276 | return shortTitle;
277 | }
278 |
279 | /**
280 | * @param shortTitle the shortTitle to set
281 | */
282 | public void setShortTitle(String shortTitle) {
283 | this.shortTitle = shortTitle;
284 | }
285 |
286 | /**
287 | * @return the commentsCount
288 | */
289 | public int getCommentsCount() {
290 | return commentsCount;
291 | }
292 |
293 | /**
294 | * @param commentsCount the commentsCount to set
295 | */
296 | public void setCommentsCount(int commentsCount) {
297 | this.commentsCount = commentsCount;
298 | }
299 |
300 | /**
301 | * @return the renderSuccess
302 | */
303 | public boolean isRenderSuccess() {
304 | return renderSuccess;
305 | }
306 |
307 | /**
308 | * @param renderSuccess the renderSuccess to set
309 | */
310 | public void setRenderSuccess(boolean renderSuccess) {
311 | this.renderSuccess = renderSuccess;
312 | }
313 |
314 | /**
315 | * @return the action
316 | */
317 | public String getAction() {
318 | return action;
319 | }
320 |
321 | /**
322 | * @param action the action to set
323 | */
324 | public void setAction(String action) {
325 | this.action = action;
326 | }
327 |
328 | // /**
329 | // * @return the tmplVer
330 | // */
331 | // public int getTmplVer() {
332 | // return tmplVer;
333 | // }
334 | //
335 | // /**
336 | // * @param tmplVer the tmplVer to set
337 | // */
338 | // public void setTmplVer(int tmplVer) {
339 | // this.tmplVer = tmplVer;
340 | // }
341 |
342 | /**
343 | * @return the type
344 | */
345 | public String getType() {
346 | return type;
347 | }
348 |
349 | /**
350 | * @param type the type to set
351 | */
352 | public void setType(String type) {
353 | this.type = type;
354 | }
355 |
356 | /**
357 | * @return the user
358 | */
359 | public DoubanShuoUserObj getUser() {
360 | return user;
361 | }
362 |
363 | /**
364 | * @param user the user to set
365 | */
366 | public void setUser(DoubanShuoUserObj user) {
367 | this.user = user;
368 | }
369 |
370 | /**
371 | * @return the attachements
372 | */
373 | public List getAttachements() {
374 | return attachements;
375 | }
376 |
377 | /**
378 | * @param attachements the attachements to set
379 | */
380 | public void setAttachements(List attachements) {
381 | this.attachements = attachements;
382 | }
383 |
384 | /**
385 | * @return the favorited
386 | */
387 | public boolean isFavorited() {
388 | return favorited;
389 | }
390 |
391 | /**
392 | * @param favorited the favorited to set
393 | */
394 | public void setFavorited(boolean favorited) {
395 | this.favorited = favorited;
396 | }
397 |
398 | /**
399 | * @return the source
400 | */
401 | public String getSource() {
402 | return source;
403 | }
404 |
405 | /**
406 | * @param source the source to set
407 | */
408 | public void setSource(String source) {
409 | this.source = source;
410 | }
411 |
412 | }
413 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/shuo/DoubanShuoUserObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.shuo;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | *
8 | * @author Zhibo Wei
9 | */
10 | public class DoubanShuoUserObj implements IDoubanObject{
11 |
12 | @Key("city")
13 | private String city;
14 |
15 | @Key("icon_avatar")
16 | private String iconNormal;
17 |
18 | @Key("statuses_count")
19 | private int totalStatusCount = 0;
20 |
21 | @Key("uid")
22 | private String uid;
23 |
24 | @Key("url")
25 | private String url;
26 |
27 | @Key("created_at")
28 | private String createdDate;
29 |
30 | //What the hell is this?
31 | @Key("new_site_to_vu_count")
32 | private int newSiteCount = 0;
33 |
34 | @Key("large_avatar")
35 | private String iconLarge;
36 |
37 | @Key("screen_name")
38 | private String screenName;
39 |
40 | @Key("location")
41 | private String location;
42 |
43 | @Key("small_avatar")
44 | private String iconSmall;
45 |
46 | @Key("following")
47 | private boolean following = false;
48 |
49 | @Key("verified")
50 | private boolean verified = false;
51 |
52 | @Key("is_first_visit")
53 | private boolean isFirstVisit = false;
54 |
55 | @Key("type")
56 | private String type;
57 |
58 | @Key("id")
59 | private String id;
60 |
61 | @Key("description")
62 | private String description;
63 |
64 | @Key("original_site_url")
65 | private String siteUrl;
66 |
67 | @Override
68 | public String getObjName() {
69 | throw new UnsupportedOperationException("Not supported yet.");
70 | }
71 |
72 | /**
73 | * @return the city
74 | */
75 | public String getCity() {
76 | return city;
77 | }
78 |
79 | /**
80 | * @param city the city to set
81 | */
82 | public void setCity(String city) {
83 | this.city = city;
84 | }
85 |
86 | /**
87 | * @return the iconNormal
88 | */
89 | public String getIconNormal() {
90 | return iconNormal;
91 | }
92 |
93 | /**
94 | * @param iconNormal the iconNormal to set
95 | */
96 | public void setIconNormal(String iconNormal) {
97 | this.iconNormal = iconNormal;
98 | }
99 |
100 | /**
101 | * @return the totalStatusCount
102 | */
103 | public int getTotalStatusCount() {
104 | return totalStatusCount;
105 | }
106 |
107 | /**
108 | * @param totalStatusCount the totalStatusCount to set
109 | */
110 | public void setTotalStatusCount(int totalStatusCount) {
111 | this.totalStatusCount = totalStatusCount;
112 | }
113 |
114 | /**
115 | * @return the uid
116 | */
117 | public String getUid() {
118 | return uid;
119 | }
120 |
121 | /**
122 | * @param uid the uid to set
123 | */
124 | public void setUid(String uid) {
125 | this.uid = uid;
126 | }
127 |
128 | /**
129 | * @return the url
130 | */
131 | public String getUrl() {
132 | return url;
133 | }
134 |
135 | /**
136 | * @param url the url to set
137 | */
138 | public void setUrl(String url) {
139 | this.url = url;
140 | }
141 |
142 | /**
143 | * @return the createdDate
144 | */
145 | public String getCreatedDate() {
146 | return createdDate;
147 | }
148 |
149 | /**
150 | * @param createdDate the createdDate to set
151 | */
152 | public void setCreatedDate(String createdDate) {
153 | this.createdDate = createdDate;
154 | }
155 |
156 | /**
157 | * @return the newSiteCount
158 | */
159 | public int getNewSiteCount() {
160 | return newSiteCount;
161 | }
162 |
163 | /**
164 | * @param newSiteCount the newSiteCount to set
165 | */
166 | public void setNewSiteCount(int newSiteCount) {
167 | this.newSiteCount = newSiteCount;
168 | }
169 |
170 | /**
171 | * @return the iconLarge
172 | */
173 | public String getIconLarge() {
174 | return iconLarge;
175 | }
176 |
177 | /**
178 | * @param iconLarge the iconLarge to set
179 | */
180 | public void setIconLarge(String iconLarge) {
181 | this.iconLarge = iconLarge;
182 | }
183 |
184 | /**
185 | * @return the screenName
186 | */
187 | public String getScreenName() {
188 | return screenName;
189 | }
190 |
191 | /**
192 | * @param screenName the screenName to set
193 | */
194 | public void setScreenName(String screenName) {
195 | this.screenName = screenName;
196 | }
197 |
198 | /**
199 | * @return the location
200 | */
201 | public String getLocation() {
202 | return location;
203 | }
204 |
205 | /**
206 | * @param location the location to set
207 | */
208 | public void setLocation(String location) {
209 | this.location = location;
210 | }
211 |
212 | /**
213 | * @return the iconSmall
214 | */
215 | public String getIconSmall() {
216 | return iconSmall;
217 | }
218 |
219 | /**
220 | * @param iconSmall the iconSmall to set
221 | */
222 | public void setIconSmall(String iconSmall) {
223 | this.iconSmall = iconSmall;
224 | }
225 |
226 | /**
227 | * @return the following
228 | */
229 | public boolean isFollowing() {
230 | return following;
231 | }
232 |
233 | /**
234 | * @param following the following to set
235 | */
236 | public void setFollowing(boolean following) {
237 | this.following = following;
238 | }
239 |
240 | /**
241 | * @return the verified
242 | */
243 | public boolean isVerified() {
244 | return verified;
245 | }
246 |
247 | /**
248 | * @param verified the verified to set
249 | */
250 | public void setVerified(boolean verified) {
251 | this.verified = verified;
252 | }
253 |
254 | /**
255 | * @return the isFirstVisit
256 | */
257 | public boolean isIsFirstVisit() {
258 | return isFirstVisit;
259 | }
260 |
261 | /**
262 | * @param isFirstVisit the isFirstVisit to set
263 | */
264 | public void setIsFirstVisit(boolean isFirstVisit) {
265 | this.isFirstVisit = isFirstVisit;
266 | }
267 |
268 | /**
269 | * @return the type
270 | */
271 | public String getType() {
272 | return type;
273 | }
274 |
275 | /**
276 | * @param type the type to set
277 | */
278 | public void setType(String type) {
279 | this.type = type;
280 | }
281 |
282 | /**
283 | * @return the id
284 | */
285 | public String getId() {
286 | return id;
287 | }
288 |
289 | /**
290 | * @param id the id to set
291 | */
292 | public void setId(String id) {
293 | this.id = id;
294 | }
295 |
296 | /**
297 | * @return the description
298 | */
299 | public String getDescription() {
300 | return description;
301 | }
302 |
303 | /**
304 | * @param description the description to set
305 | */
306 | public void setDescription(String description) {
307 | this.description = description;
308 | }
309 |
310 | /**
311 | * @return the siteUrl
312 | */
313 | public String getSiteUrl() {
314 | return siteUrl;
315 | }
316 |
317 | /**
318 | * @param siteUrl the siteUrl to set
319 | */
320 | public void setSiteUrl(String siteUrl) {
321 | this.siteUrl = siteUrl;
322 | }
323 |
324 |
325 | }
326 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/subject/DoubanSubjectFeedObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.subject;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.google.api.client.util.Key;
7 |
8 | /**
9 | *
10 | * @author Zhibo Wei
11 | */
12 | public class DoubanSubjectFeedObj implements IDoubanObject{
13 |
14 | @Key
15 | private String title;
16 |
17 | @Key("opensearch:itemsPerPage")
18 | private int itemsPerPage;
19 |
20 | @Key("opensearch:startIndex")
21 | private int startIndex;
22 |
23 | @Key("opensearch:totalResults")
24 | private int totalResult;
25 |
26 | @Key("entry")
27 | private List subjects;
28 |
29 | @Override
30 | public String getObjName() {
31 | return "subjectfeed";
32 | }
33 |
34 | /**
35 | * @return the title
36 | */
37 | public String getTitle() {
38 | return title;
39 | }
40 |
41 | /**
42 | * @param title the title to set
43 | */
44 | public void setTitle(String title) {
45 | this.title = title;
46 | }
47 |
48 | /**
49 | * @return the itemsPerPage
50 | */
51 | public int getItemsPerPage() {
52 | return itemsPerPage;
53 | }
54 |
55 | /**
56 | * @param itemsPerPage the itemsPerPage to set
57 | */
58 | public void setItemsPerPage(int itemsPerPage) {
59 | this.itemsPerPage = itemsPerPage;
60 | }
61 |
62 | /**
63 | * @return the startIndex
64 | */
65 | public int getStartIndex() {
66 | return startIndex;
67 | }
68 |
69 | /**
70 | * @param startIndex the startIndex to set
71 | */
72 | public void setStartIndex(int startIndex) {
73 | this.startIndex = startIndex;
74 | }
75 |
76 | /**
77 | * @return the totalResult
78 | */
79 | public int getTotalResult() {
80 | return totalResult;
81 | }
82 |
83 | /**
84 | * @param totalResult the totalResult to set
85 | */
86 | public void setTotalResult(int totalResult) {
87 | this.totalResult = totalResult;
88 | }
89 |
90 | /**
91 | * @return the subjects
92 | */
93 | public List getSubjects() {
94 | return subjects;
95 | }
96 |
97 | /**
98 | * @param subjects the subjects to set
99 | */
100 | public void setSubjects(List subjects) {
101 | this.subjects = subjects;
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/subject/DoubanSubjectObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.subject;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.dongxuexidu.douban4j.model.IDoubanObject;
7 | import com.dongxuexidu.douban4j.model.common.DoubanAttributeObj;
8 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
9 | import com.dongxuexidu.douban4j.model.common.DoubanCategoryObj;
10 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
11 | import com.dongxuexidu.douban4j.model.common.DoubanRatingObj;
12 | import com.dongxuexidu.douban4j.model.common.DoubanTagObj;
13 | import com.google.api.client.util.Key;
14 |
15 | /**
16 | *
17 | * @author Zhibo Wei
18 | */
19 | public class DoubanSubjectObj implements IDoubanObject {
20 |
21 | @Override
22 | public String getObjName() {
23 | return "subject";
24 | }
25 |
26 | @Key("category")
27 | private DoubanCategoryObj category;
28 |
29 | @Key("author")
30 | private List authors = new ArrayList();
31 |
32 | @Key
33 | private String title;
34 |
35 | @Key("summary")
36 | private String summary;
37 |
38 | @Key("link")
39 | private List links = new ArrayList();
40 |
41 | @Key("db:tag")
42 | private List tags = new ArrayList();
43 |
44 | @Key("db:attribute")
45 | private List attributes = new ArrayList();
46 |
47 | @Key
48 | private String id;
49 |
50 | @Key("gd:rating")
51 | private DoubanRatingObj rating;
52 |
53 | /**
54 | * @return the category
55 | */
56 | public DoubanCategoryObj getCategory() {
57 | return category;
58 | }
59 |
60 | /**
61 | * @param category the category to set
62 | */
63 | public void setCategory(DoubanCategoryObj category) {
64 | this.category = category;
65 | }
66 |
67 | /**
68 | * @return the authors
69 | */
70 | public List getAuthors() {
71 | return authors;
72 | }
73 |
74 | /**
75 | * @param authors the authors to set
76 | */
77 | public void setAuthors(List authors) {
78 | this.authors = authors;
79 | }
80 |
81 | public void addAuthor(DoubanAuthorObj author) {
82 | this.authors.add(author);
83 | }
84 |
85 | /**
86 | * @return the title
87 | */
88 | public String getTitle() {
89 | return title;
90 | }
91 |
92 | /**
93 | * @param title the title to set
94 | */
95 | public void setTitle(String title) {
96 | this.title = title;
97 | }
98 |
99 | /**
100 | * @param links the links to set
101 | */
102 | public void setLinks(List links) {
103 | this.links = links;
104 | }
105 |
106 | public void addLink(DoubanLinkObj link) {
107 | this.links.add(link);
108 | }
109 |
110 | public String getLinkByRel (String rel) {
111 | for (DoubanLinkObj obj : this.links) {
112 | if (obj.getRel().equalsIgnoreCase(rel)) {
113 | return obj.getHref();
114 | }
115 | }
116 | return null;
117 | }
118 |
119 | public List getLinks() {
120 | return this.links;
121 | }
122 |
123 | /**
124 | * @return the attributes
125 | */
126 | public List getAttributes() {
127 | return attributes;
128 | }
129 |
130 | /**
131 | * @param attributes the attributes to set
132 | */
133 | public void addAttribute(DoubanAttributeObj attribute) {
134 | this.attributes.add(attribute);
135 | }
136 |
137 | /**
138 | * @return the id
139 | */
140 | public String getId() {
141 | return id;
142 | }
143 |
144 | /**
145 | * @param id the id to set
146 | */
147 | public void setId(String id) {
148 | this.id = id;
149 | }
150 |
151 | /**
152 | * @return the rating
153 | */
154 | public DoubanRatingObj getRating() {
155 | return rating;
156 | }
157 |
158 | /**
159 | * @param rating the rating to set
160 | */
161 | public void setRating(DoubanRatingObj rating) {
162 | this.rating = rating;
163 | }
164 |
165 | /**
166 | * @return the tags
167 | */
168 | public List getTags() {
169 | return tags;
170 | }
171 |
172 | /**
173 | * @param tags the tags to set
174 | */
175 | public void setTags(List tags) {
176 | this.tags = tags;
177 | }
178 |
179 | public void addTag (DoubanTagObj tag) {
180 | if (this.tags == null) {
181 | this.tags = new ArrayList();
182 | }
183 | this.tags.add(tag);
184 | }
185 |
186 | /**
187 | * @return the summary
188 | */
189 | public String getSummary() {
190 | return summary;
191 | }
192 |
193 | /**
194 | * @param summary the summary to set
195 | */
196 | public void setSummary(String summary) {
197 | this.summary = summary;
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/user/DoubanUserFeedObj.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.model.user;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import com.dongxuexidu.douban4j.model.IDoubanObject;
11 | import com.dongxuexidu.douban4j.model.common.DoubanAuthorObj;
12 | import com.google.api.client.util.Key;
13 |
14 | /**
15 | *
16 | * @author Zhibo Wei
17 | */
18 | public class DoubanUserFeedObj implements IDoubanObject {
19 |
20 | @Key("entry")
21 | private List users = new ArrayList();
22 |
23 | @Key("author")
24 | private DoubanAuthorObj author;
25 |
26 | @Key
27 | private String title;
28 |
29 | @Key("openSearch:itemsPerPage")
30 | private int itemsPerPage;
31 |
32 | @Key("openSearch:startIndex")
33 | private int startIndex;
34 |
35 | @Key("openSearch:totalResults")
36 | private int totalResult;
37 |
38 | /**
39 | * @return the users
40 | */
41 | public List getUsers() {
42 | return users;
43 | }
44 |
45 | /**
46 | * @param users the users to set
47 | */
48 | public void setUsers(List users) {
49 | this.users = users;
50 | }
51 |
52 | /**
53 | * @return the title
54 | */
55 | public String getTitle() {
56 | return title;
57 | }
58 |
59 | /**
60 | * @param title the title to set
61 | */
62 | public void setTitle(String title) {
63 | this.title = title;
64 | }
65 |
66 | /**
67 | * @return the itemsPerPage
68 | */
69 | public int getItemsPerPage() {
70 | return itemsPerPage;
71 | }
72 |
73 | /**
74 | * @param itemsPerPage the itemsPerPage to set
75 | */
76 | public void setItemsPerPage(int itemsPerPage) {
77 | this.itemsPerPage = itemsPerPage;
78 | }
79 |
80 | /**
81 | * @return the startIndex
82 | */
83 | public int getStartIndex() {
84 | return startIndex;
85 | }
86 |
87 | /**
88 | * @param startIndex the startIndex to set
89 | */
90 | public void setStartIndex(int startIndex) {
91 | this.startIndex = startIndex;
92 | }
93 |
94 | /**
95 | * @return the totalResult
96 | */
97 | public int getTotalResult() {
98 | return totalResult;
99 | }
100 |
101 | /**
102 | * @param totalResult the totalResult to set
103 | */
104 | public void setTotalResult(int totalResult) {
105 | this.totalResult = totalResult;
106 | }
107 |
108 | @Override
109 | public String getObjName() {
110 | return "doubanuserfeed";
111 | }
112 |
113 | /**
114 | * @return the author
115 | */
116 | public DoubanAuthorObj getAuthor() {
117 | return author;
118 | }
119 |
120 | /**
121 | * @param author the author to set
122 | */
123 | public void setAuthor(DoubanAuthorObj author) {
124 | this.author = author;
125 | }
126 |
127 | public boolean hasUserEntries () {
128 | return (this.users != null && this.users.size() > 0);
129 | }
130 |
131 | }
132 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/user/DoubanUserObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.user;
2 |
3 | import java.util.List;
4 |
5 | import com.dongxuexidu.douban4j.model.IDoubanObject;
6 | import com.dongxuexidu.douban4j.model.common.DoubanLinkObj;
7 | import com.dongxuexidu.douban4j.model.common.DoubanLocationObj;
8 | import com.google.api.client.util.Key;
9 |
10 | /**
11 | *
12 | * @author Zhibo Wei
13 | */
14 | public class DoubanUserObj implements IDoubanObject {
15 |
16 | @Key
17 | private String id;
18 |
19 | @Key
20 | private String title;
21 |
22 | @Key ("link")
23 | private List links;
24 |
25 | @Key
26 | private String content;
27 |
28 | @Key ("db:location")
29 | private DoubanLocationObj location;
30 |
31 | @Key ("db:signature")
32 | private String signature;
33 |
34 | @Key ("db:uid")
35 | private String uid;
36 |
37 | @Key
38 | private String uri;
39 |
40 | @Override
41 | public String getObjName() {
42 | return "doubanuser";
43 | }
44 |
45 | /**
46 | * @return the id
47 | */
48 | public String getId() {
49 | return id;
50 | }
51 |
52 | /**
53 | * @param id the id to set
54 | */
55 | public void setId(String id) {
56 | this.id = id;
57 | }
58 |
59 | /**
60 | * @return the title
61 | */
62 | public String getTitle() {
63 | return title;
64 | }
65 |
66 | /**
67 | * @param title the title to set
68 | */
69 | public void setTitle(String title) {
70 | this.title = title;
71 | }
72 |
73 | /**
74 | * @return the links
75 | */
76 | public List getLinks() {
77 | return links;
78 | }
79 |
80 | public void setLinks (List links) {
81 | this.links = links;
82 | }
83 |
84 | /**
85 | * @param links the links to set
86 | */
87 | public void addLink(String href, String rel) {
88 | this.links.add(new DoubanLinkObj(href, rel));
89 | }
90 |
91 | public String getLinkByRel (String rel) {
92 | for (DoubanLinkObj obj : this.links) {
93 | if (obj.getRel().equalsIgnoreCase(rel)) {
94 | return obj.getHref();
95 | }
96 | }
97 | return null;
98 | }
99 |
100 | /**
101 | * @return the content
102 | */
103 | public String getContent() {
104 | return content;
105 | }
106 |
107 | /**
108 | * @param content the content to set
109 | */
110 | public void setContent(String content) {
111 | this.content = content;
112 | }
113 |
114 | /**
115 | * @return the location
116 | */
117 | public DoubanLocationObj getLocation() {
118 | return location;
119 | }
120 |
121 | /**
122 | * @param location the location to set
123 | */
124 | public void setLocation(DoubanLocationObj location) {
125 | this.location = location;
126 | }
127 |
128 | /**
129 | * @return the signature
130 | */
131 | public String getSignature() {
132 | return signature;
133 | }
134 |
135 | /**
136 | * @param signature the signature to set
137 | */
138 | public void setSignature(String signature) {
139 | this.signature = signature;
140 | }
141 |
142 | /**
143 | * @return the uid
144 | */
145 | public String getUid() {
146 | return uid;
147 | }
148 |
149 | /**
150 | * @param uid the uid to set
151 | */
152 | public void setUid(String uid) {
153 | this.uid = uid;
154 | }
155 |
156 | /**
157 | * @return the uri
158 | */
159 | public String getUri() {
160 | return uri;
161 | }
162 |
163 | /**
164 | * @param uri the uri to set
165 | */
166 | public void setUri(String uri) {
167 | this.uri = uri;
168 | }
169 |
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/v2/DoubanCastObject.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.v2;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.dongxuexidu.douban4j.model.common.DoubanImageObj;
5 | import com.google.api.client.util.Key;
6 |
7 | /**
8 | *
9 | * @author Sean Guo
10 | *
11 | */
12 | public class DoubanCastObject implements IDoubanObject {
13 |
14 | private DoubanImageObj avatars;
15 |
16 | @Key
17 | private String alt;
18 |
19 | @Key
20 | private String id;
21 |
22 | @Key
23 | private String name;
24 |
25 | @Override
26 | public String getObjName() {
27 | return "DoubanCastObject";
28 | }
29 |
30 | public DoubanImageObj getAvatars() {
31 | return avatars;
32 | }
33 |
34 | public String getAlt() {
35 | return alt;
36 | }
37 |
38 | public String getId() {
39 | return id;
40 | }
41 |
42 | public String getName() {
43 | return name;
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return "DoubanCastObject [avatars=" + avatars + ", alt=" + alt + ", id=" + id + ", name=" + name + "]";
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/v2/DoubanDirectorObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.v2;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.dongxuexidu.douban4j.model.common.DoubanImageObj;
5 | import com.google.api.client.util.Key;
6 |
7 | /**
8 | *
9 | * @author Sean Guo
10 | *
11 | */
12 | public class DoubanDirectorObj implements IDoubanObject {
13 |
14 | @Key
15 | private DoubanImageObj avatars;
16 |
17 | @Key
18 | private String alt;
19 |
20 | @Key
21 | private String id;
22 |
23 | @Key
24 | private String name;
25 |
26 | @Override
27 | public String getObjName() {
28 | return "DoubanDirectorObj";
29 | }
30 |
31 | public DoubanImageObj getAvatars() {
32 | return avatars;
33 | }
34 |
35 | public String getAlt() {
36 | return alt;
37 | }
38 |
39 | public String getId() {
40 | return id;
41 | }
42 |
43 | public String getName() {
44 | return name;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "DoubanDirectorObj [avatars=" + avatars + ", alt=" + alt + ", id=" + id + ", name=" + name + "]";
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/v2/DoubanRatingObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.v2;
2 |
3 | import com.dongxuexidu.douban4j.model.IDoubanObject;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | *
8 | * @author Sean Guo
9 | *
10 | */
11 | public class DoubanRatingObj implements IDoubanObject {
12 |
13 | @Key
14 | private int max;
15 |
16 | @Key
17 | private float average;
18 |
19 | @Key
20 | private int stars;
21 |
22 | @Key
23 | private int min;
24 |
25 | @Override
26 | public String getObjName() {
27 | return "DoubanRatingObj";
28 | }
29 |
30 | public int getMax() {
31 | return max;
32 | }
33 |
34 | public float getAverage() {
35 | return average;
36 | }
37 |
38 | public int getStars() {
39 | return stars;
40 | }
41 |
42 | public int getMin() {
43 | return min;
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return "DoubanRatingObj [max=" + max + ", average=" + average + ", stars=" + stars + ", min=" + min + "]";
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/v2/DoubanSubjectListObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.v2;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.dongxuexidu.douban4j.model.IDoubanObject;
7 | import com.google.api.client.util.Key;
8 |
9 | /**
10 | *
11 | * @author Sean Guo
12 | *
13 | */
14 | public class DoubanSubjectListObj implements IDoubanObject {
15 |
16 | @Key
17 | private int count;
18 |
19 | @Key
20 | private int start;
21 |
22 | @Key
23 | private int total;
24 |
25 | @Key
26 | private List subjects = new ArrayList();
27 |
28 | @Key
29 | private String title;
30 |
31 | @Override
32 | public String getObjName() {
33 | return "DoubanSubjectList";
34 | }
35 |
36 | public int getCount() {
37 | return count;
38 | }
39 |
40 | public int getStart() {
41 | return start;
42 | }
43 |
44 | public int getTotal() {
45 | return total;
46 | }
47 |
48 | public List getSubjects() {
49 | return subjects;
50 | }
51 |
52 | public String getTitle() {
53 | return title;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/model/v2/DoubanSubjectObj.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.model.v2;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.dongxuexidu.douban4j.model.IDoubanObject;
7 | import com.dongxuexidu.douban4j.model.common.DoubanImageObj;
8 | import com.google.api.client.util.Key;
9 |
10 | /**
11 | *
12 | * @author Sean Guo
13 | *
14 | */
15 | public class DoubanSubjectObj implements IDoubanObject {
16 |
17 | @Key
18 | private DoubanRatingObj rating;
19 |
20 | @Key
21 | private String title;
22 |
23 | @Key
24 | private String original_title;
25 |
26 | @Key
27 | private String year;
28 |
29 | @Key
30 | private String subtype;
31 |
32 | @Key
33 | private DoubanImageObj images;
34 |
35 | @Key
36 | private String alt;
37 |
38 | @Key
39 | private String id;
40 |
41 | @Key
42 | private String summary;
43 |
44 | @Key
45 | private List casts = new ArrayList();
46 |
47 | @Key
48 | private List directors = new ArrayList();
49 |
50 | @Key
51 | private List aka = new ArrayList();
52 |
53 | @Key
54 | private List genres = new ArrayList();
55 |
56 | @Key
57 | private List countries = new ArrayList();
58 |
59 | @Key
60 | private int comments_count;
61 |
62 | @Key
63 | private int ratings_count;
64 |
65 | @Override
66 | public String getObjName() {
67 | return "DoubanSubjectObj";
68 | }
69 |
70 | public DoubanRatingObj getRating() {
71 | return rating;
72 | }
73 |
74 | public String getTitle() {
75 | return title;
76 | }
77 |
78 | public String getOriginal_title() {
79 | return original_title;
80 | }
81 |
82 | public String getYear() {
83 | return year;
84 | }
85 |
86 | public String getSubtype() {
87 | return subtype;
88 | }
89 |
90 | public DoubanImageObj getImages() {
91 | return images;
92 | }
93 |
94 | public String getAlt() {
95 | return alt;
96 | }
97 |
98 | public String getId() {
99 | return id;
100 | }
101 |
102 | public String getSummary() {
103 | return summary;
104 | }
105 |
106 | public List getCasts() {
107 | return casts;
108 | }
109 |
110 | public List getAka() {
111 | return aka;
112 | }
113 |
114 | public int getComments_count() {
115 | return comments_count;
116 | }
117 |
118 | public int getRatings_count() {
119 | return ratings_count;
120 | }
121 |
122 | public List getGenres() {
123 | return genres;
124 | }
125 |
126 | public List getCountries() {
127 | return countries;
128 | }
129 |
130 | public List getDirectors() {
131 | return directors;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/playground/BrowserLauncher.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.playground;
2 |
3 | /////////////////////////////////////////////////////////
4 | //Bare Bones Browser Launch //
5 | //Version 1.5 (December 10, 2005) //
6 | //By Dem Pilafian //
7 | //Supports: Mac OS X, GNU/Linux, Unix, Windows XP //
8 | //Example Usage: //
9 | // String url = "http://www.centerkey.com/"; //
10 | // BareBonesBrowserLaunch.openURL(url); //
11 | //Public Domain Software -- Free to Use as You Like //
12 | /////////////////////////////////////////////////////////
13 | /**
14 | * @author Dem Pilafian
15 | * @author John Kristian
16 | */
17 | import java.io.IOException;
18 | import java.lang.reflect.InvocationTargetException;
19 | import java.lang.reflect.Method;
20 |
21 | import javax.swing.JOptionPane;
22 |
23 | public class BrowserLauncher {
24 |
25 | public static void openURL(String url) {
26 | try {
27 | browse(url);
28 | } catch (Exception e) {
29 | JOptionPane.showMessageDialog(null, "Error attempting to launch web browser:\n" + e.getLocalizedMessage());
30 | }
31 | }
32 |
33 | private static void browse(String url) throws ClassNotFoundException, IllegalAccessException,
34 | IllegalArgumentException, InterruptedException, InvocationTargetException, IOException,
35 | NoSuchMethodException {
36 | String osName = System.getProperty("os.name", "");
37 | if (osName.startsWith("Mac OS")) {
38 | Class fileMgr = Class.forName("com.apple.eio.FileManager");
39 | Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[]{String.class});
40 | openURL.invoke(null, new Object[]{url});
41 | } else if (osName.startsWith("Windows")) {
42 | Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
43 | } else { // assume Unix or Linux
44 | String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"};
45 | String browser = null;
46 | for (int count = 0; count < browsers.length && browser == null; count++) {
47 | if (Runtime.getRuntime().exec(new String[]{"which", browsers[count]}).waitFor() == 0) {
48 | browser = browsers[count];
49 | }
50 | }
51 | if (browser == null) {
52 | throw new NoSuchMethodException("Could not find web browser");
53 | } else {
54 | Runtime.getRuntime().exec(new String[]{browser, url});
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/playground/DoubanPeopleEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.playground;
6 |
7 | import java.util.List;
8 |
9 | import com.google.api.client.util.Key;
10 |
11 | /**
12 | *
13 | * @author Zhibo Wei
14 | */
15 | public class DoubanPeopleEntry {
16 |
17 | @Key
18 | private String id;
19 |
20 | @Key
21 | private String title;
22 |
23 | @Key ("link")
24 | private List links;
25 |
26 | @Key
27 | private String content;
28 |
29 | @Key ("db:location")
30 | private Location location;
31 |
32 | // @Key ("db:location/@id")
33 | // private String locationId;
34 |
35 | @Key ("db:signature")
36 | private String signature;
37 |
38 | @Key ("db:uid")
39 | private String uid;
40 |
41 | @Key
42 | private String uri;
43 |
44 | @Override
45 | public String toString() {
46 |
47 | String result = "id : " + id + "\n"
48 | + "title : " + title + "\n";
49 | for (Link l : links) {
50 | result = result + l.toString() + "\n";
51 | }
52 | result = result + "content : " + content + "\n"
53 | + "location : " + location + "\n"
54 | //+ "location id : " + locationId + "\n"
55 | + "sign : " + signature + "\n"
56 | + "uid : " + uid + "\n"
57 | + "uri : " + uri;
58 | return result;
59 | }
60 |
61 | /**
62 | * @return the id
63 | */
64 | public String getId() {
65 | return id;
66 | }
67 |
68 | /**
69 | * @param id the id to set
70 | */
71 | public void setId(String id) {
72 | this.id = id;
73 | }
74 |
75 | /**
76 | * @return the title
77 | */
78 | public String getTitle() {
79 | return title;
80 | }
81 |
82 | /**
83 | * @param title the title to set
84 | */
85 | public void setTitle(String title) {
86 | this.title = title;
87 | }
88 |
89 | /**
90 | * @return the links
91 | */
92 | public List getLinks() {
93 | return links;
94 | }
95 |
96 | /**
97 | * @param links the links to set
98 | */
99 | public void addLink(String href, String rel) {
100 | this.links.add(new Link(href, rel));
101 | }
102 |
103 | /**
104 | * @return the content
105 | */
106 | public String getContent() {
107 | return content;
108 | }
109 |
110 | /**
111 | * @param content the content to set
112 | */
113 | public void setContent(String content) {
114 | this.content = content;
115 | }
116 |
117 | /**
118 | * @return the location
119 | */
120 | // public String getLocation() {
121 | // return location;
122 | // }
123 |
124 | /**
125 | * @param location the location to set
126 | */
127 | // public void setLocation(String location) {
128 | // this.location = location;
129 | // }
130 |
131 | /**
132 | * @return the signature
133 | */
134 | public String getSignature() {
135 | return signature;
136 | }
137 |
138 | /**
139 | * @param signature the signature to set
140 | */
141 | public void setSignature(String signature) {
142 | this.signature = signature;
143 | }
144 |
145 | /**
146 | * @return the uid
147 | */
148 | public String getUid() {
149 | return uid;
150 | }
151 |
152 | /**
153 | * @param uid the uid to set
154 | */
155 | public void setUid(String uid) {
156 | this.uid = uid;
157 | }
158 |
159 | /**
160 | * @return the uri
161 | */
162 | public String getUri() {
163 | return uri;
164 | }
165 |
166 | /**
167 | * @param uri the uri to set
168 | */
169 | public void setUri(String uri) {
170 | this.uri = uri;
171 | }
172 |
173 | }
174 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/playground/Link.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.playground;
6 |
7 | import com.google.api.client.util.Key;
8 |
9 | /**
10 | *
11 | * @author Zhibo Wei
12 | */
13 | public class Link {
14 |
15 | @Key("@href")
16 | private String href;
17 |
18 | @Key("@rel")
19 | private String rel;
20 |
21 | public Link(String href, String rel) {
22 | this.href = href;
23 | this.rel = rel;
24 | }
25 |
26 | @Override
27 | public String toString() {
28 |
29 | return "\thref : " + getHref() + " , rel : " + getRel();
30 |
31 | }
32 |
33 | /**
34 | * @return the href
35 | */
36 | public String getHref() {
37 | return href;
38 | }
39 |
40 | /**
41 | * @param href the href to set
42 | */
43 | public void setHref(String href) {
44 | this.href = href;
45 | }
46 |
47 | /**
48 | * @return the rel
49 | */
50 | public String getRel() {
51 | return rel;
52 | }
53 |
54 | /**
55 | * @param rel the rel to set
56 | */
57 | public void setRel(String rel) {
58 | this.rel = rel;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/playground/Location.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.playground;
6 |
7 | import com.google.api.client.util.Key;
8 |
9 | /**
10 | *
11 | * @author Zhibo Wei
12 | */
13 | public class Location {
14 |
15 | @Key("@id")
16 | public String id;
17 |
18 | @Key("text()")
19 | private String value;
20 |
21 | @Override
22 | public String toString() {
23 |
24 | return "\tlocation id : " + id + " , value : " + value;
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/provider/OAuthDoubanProvider.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.provider;
2 |
3 | import java.io.IOException;
4 | import java.io.UnsupportedEncodingException;
5 | import java.util.ArrayList;
6 | import java.util.HashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.logging.Logger;
10 |
11 | import com.dongxuexidu.douban4j.constants.DefaultConfigs;
12 | import com.dongxuexidu.douban4j.model.app.AccessToken;
13 | import com.dongxuexidu.douban4j.model.app.DoubanException;
14 | import com.dongxuexidu.douban4j.model.app.RequestGrantScope;
15 | import com.dongxuexidu.douban4j.utils.Converters;
16 | import com.dongxuexidu.douban4j.utils.ErrorHandler;
17 | import com.dongxuexidu.douban4j.utils.HttpManager;
18 |
19 | /**
20 | *
21 | * @author Zhibo Wei
22 | */
23 | public class OAuthDoubanProvider {
24 |
25 | private String apiKey = DefaultConfigs.API_KEY;
26 | private String secretKey = DefaultConfigs.SECRET_KEY;
27 | private String authUrl = DefaultConfigs.AUTH_URL;
28 | private String redirectUrl = null;
29 | private String responseType = "code";
30 | private String grantType = "authorization_code";
31 |
32 | private List scopes = new ArrayList();
33 |
34 | static final private Logger logger = Logger.getLogger(OAuthDoubanProvider.class.getName());
35 |
36 | /**
37 | * @return the apiKey
38 | */
39 | public String getApiKey() {
40 | return apiKey;
41 | }
42 |
43 | /**
44 | * @param apiKey the apiKey to set
45 | */
46 | public OAuthDoubanProvider setApiKey(String apiKey) {
47 | this.apiKey = apiKey;
48 | return this;
49 | }
50 |
51 | /**
52 | * @return the secretKey
53 | */
54 | public String getSecretKey() {
55 | return secretKey;
56 | }
57 |
58 | /**
59 | * @param secretKey the secretKey to set
60 | */
61 | public OAuthDoubanProvider setSecretKey(String secretKey) {
62 | this.secretKey = secretKey;
63 | return this;
64 | }
65 |
66 | /**
67 | * @return the authUrl
68 | */
69 | public String getAuthUrl() {
70 | return authUrl;
71 | }
72 |
73 | /**
74 | * @param authUrl the authUrl to set
75 | */
76 | public OAuthDoubanProvider setAuthUrl(String authUrl) {
77 | this.authUrl = authUrl;
78 | return this;
79 | }
80 |
81 | /**
82 | * @return the redirectUrl
83 | */
84 | public String getRedirectUrl() {
85 | return redirectUrl;
86 | }
87 |
88 | /**
89 | * @param redirectUrl the redirectUrl to set
90 | */
91 | public OAuthDoubanProvider setRedirectUrl(String redirectUrl) {
92 | this.redirectUrl = redirectUrl;
93 | return this;
94 | }
95 |
96 | /**
97 | * @return the type
98 | */
99 | public String getResponseType() {
100 | return responseType;
101 | }
102 |
103 | /**
104 | * @param type the type to set
105 | */
106 | public OAuthDoubanProvider setResponseType(String type) {
107 | this.responseType = type;
108 | return this;
109 | }
110 |
111 | /**
112 | * @return the grantType
113 | */
114 | public String getGrantType() {
115 | return grantType;
116 | }
117 |
118 | /**
119 | * @param grantType the grantType to set
120 | */
121 | public OAuthDoubanProvider setGrantType(String grantType) {
122 | this.grantType = grantType;
123 | return this;
124 | }
125 |
126 | public OAuthDoubanProvider addScope (RequestGrantScope scope) {
127 | this.scopes.add(scope);
128 | return this;
129 | }
130 |
131 | public String getGetCodeRedirectUrl () {
132 | if (this.redirectUrl == null || this.redirectUrl.isEmpty()) {
133 | logger.warning("Redirect url cannot be null or empty, did you forget to set it?");
134 | return null;
135 | }
136 | StringBuilder getCodeUrl = new StringBuilder(this.authUrl);
137 | getCodeUrl.append("?client_id=").append(this.apiKey).append("&redirect_uri=").append(this.redirectUrl).append("&response_type=").append(this.responseType);
138 | if (!this.scopes.isEmpty()) {
139 | getCodeUrl.append("&scope=").append(generateScopeString());
140 | }
141 | return getCodeUrl.toString();
142 | }
143 |
144 | public AccessToken tradeAccessTokenWithCode (String code) throws DoubanException {
145 | try {
146 | Map params = new HashMap();
147 | params.put("client_id", this.apiKey);
148 | params.put("client_secret", this.secretKey);
149 | params.put("redirect_uri", this.redirectUrl);
150 | params.put("grant_type", "authorization_code");
151 | params.put("code", code);
152 | String responseStr = new HttpManager().postEncodedEntry(DefaultConfigs.ACCESS_TOKEN_URL, params, false);
153 | return Converters.stringToAccessToken(responseStr);
154 | } catch (UnsupportedEncodingException ex) {
155 | throw ErrorHandler.getCustomDoubanException(100, "Exception in trading access token : " + ex.toString());
156 | } catch (IOException ex) {
157 | throw ErrorHandler.getCustomDoubanException(100, "Exception in trading access token : " + ex.toString());
158 | }
159 | }
160 |
161 | private String generateScopeString() {
162 | if (this.scopes == null || this.scopes.isEmpty()) {
163 | return "";
164 | } else {
165 | StringBuilder scopeStr = new StringBuilder();
166 | for (RequestGrantScope sco : this.scopes) {
167 | scopeStr.append(sco.getValue()).append(",");
168 | }
169 | scopeStr.deleteCharAt(scopeStr.length() - 1); // Get rid of the last comma
170 | return scopeStr.toString();
171 | }
172 | }
173 |
174 | }
175 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/service/DoubanBookMovieMusicService.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.service;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 | import java.util.logging.Logger;
7 |
8 | import org.apache.http.NameValuePair;
9 | import org.apache.http.message.BasicNameValuePair;
10 |
11 | import com.dongxuexidu.douban4j.constants.RequestUrls;
12 | import com.dongxuexidu.douban4j.model.app.DoubanException;
13 | import com.dongxuexidu.douban4j.model.subject.DoubanSubjectFeedObj;
14 | import com.dongxuexidu.douban4j.model.subject.DoubanSubjectObj;
15 | import com.dongxuexidu.douban4j.model.v2.DoubanSubjectListObj;
16 | import com.dongxuexidu.douban4j.utils.ErrorHandler;
17 |
18 | /**
19 | *
20 | * @author Zhibo Wei
21 | */
22 | public class DoubanBookMovieMusicService extends DoubanService {
23 |
24 | final static Logger logger = Logger.getLogger(DoubanBookMovieMusicService.class.getName());
25 |
26 | public DoubanBookMovieMusicService(String accessToken) {
27 | super(accessToken);
28 | }
29 |
30 | public DoubanBookMovieMusicService() {
31 | super();
32 | }
33 |
34 | public DoubanSubjectObj getBookInfoById (long bookId) throws DoubanException, IOException {
35 | String url = RequestUrls.DOUBAN_BOOK_SUBJECT_PREFIX + "/" + bookId;
36 | DoubanSubjectObj book = this.client.getResponse(url, null, DoubanSubjectObj.class, false);
37 | return book;
38 | }
39 |
40 | public DoubanSubjectObj getBookInfoByISBN (String isbn) throws DoubanException, IOException {
41 | String url = RequestUrls.DOUBAN_BOOK_SUBJECT_PREFIX + "/isbn/" + isbn;
42 | DoubanSubjectObj book = this.client.getResponse(url, null, DoubanSubjectObj.class, false);
43 | return book;
44 | }
45 |
46 | public DoubanSubjectObj getMovieInfoById (long movieId) throws DoubanException, IOException {
47 | String url = RequestUrls.DOUBAN_MOVIE_SUBJECT_PREFIX + "/" + movieId;
48 | DoubanSubjectObj movie = this.client.getResponse(url, null, DoubanSubjectObj.class, false);
49 | return movie;
50 | }
51 |
52 | public DoubanSubjectObj getMovieInfoByIMDBId (String imdbId) throws DoubanException, IOException {
53 | String url = RequestUrls.DOUBAN_MOVIE_SUBJECT_PREFIX + "/imdb/" + imdbId;
54 | DoubanSubjectObj movie = this.client.getResponse(url, null, DoubanSubjectObj.class, false);
55 | return movie;
56 | }
57 |
58 | public DoubanSubjectListObj getMoviesTop250(int start, int count) throws DoubanException, IOException {
59 | String url = RequestUrls.DOUBAN_MOVIE_V2_PREFIX + "/" + "top250?count=" + count;
60 | DoubanSubjectListObj movie = this.client.getResponseInJson(url, null, DoubanSubjectListObj.class, false);
61 | return movie;
62 | }
63 |
64 | public com.dongxuexidu.douban4j.model.v2.DoubanSubjectObj getV2MovieInfoById(long movieId) throws DoubanException, IOException {
65 | String url = RequestUrls.DOUBAN_MOVIE_V2_SUBJECT_PREFIX + "/" + movieId;
66 | com.dongxuexidu.douban4j.model.v2.DoubanSubjectObj movie = this.client.getResponseInJson(url, null, com.dongxuexidu.douban4j.model.v2.DoubanSubjectObj.class, false);
67 | return movie;
68 | }
69 |
70 | public DoubanSubjectObj getMusicInfoById (long musicId) throws DoubanException, IOException {
71 | String url = RequestUrls.DOUBAN_MUSIC_SUBJECT_PREFIX + "/" + musicId;
72 | DoubanSubjectObj music = this.client.getResponse(url, null, DoubanSubjectObj.class, false);
73 | return music;
74 | }
75 |
76 | public DoubanSubjectFeedObj searchBook (String q, String tag) throws DoubanException, IOException {
77 | String url = RequestUrls.DOUBAN_BOOK_SUBJECT_PREFIX + "s";
78 | return searchSubject(url, q, tag, null, null);
79 | }
80 |
81 | public DoubanSubjectFeedObj searchBook (String q, String tag, int startIndex, int maxResult) throws DoubanException, IOException {
82 | String url = RequestUrls.DOUBAN_BOOK_SUBJECT_PREFIX + "s";
83 | return searchSubject(url, q, tag, startIndex, maxResult);
84 | }
85 |
86 | public DoubanSubjectFeedObj searchMovie (String q, String tag) throws DoubanException, IOException {
87 | String url = RequestUrls.DOUBAN_MOVIE_SUBJECT_PREFIX + "s";
88 | return searchSubject(url, q, tag, null, null);
89 | }
90 |
91 | public DoubanSubjectFeedObj searchMovie (String q, String tag, int startIndex, int maxResult) throws DoubanException, IOException {
92 | String url = RequestUrls.DOUBAN_MOVIE_SUBJECT_PREFIX + "s";
93 | return searchSubject(url, q, tag, startIndex, maxResult);
94 | }
95 |
96 | public DoubanSubjectFeedObj searchMusic (String q, String tag) throws DoubanException, IOException {
97 | String url = RequestUrls.DOUBAN_MUSIC_SUBJECT_PREFIX + "s";
98 | return searchSubject(url, q, tag, null, null);
99 | }
100 |
101 | public DoubanSubjectFeedObj searchMusic (String q, String tag, int startIndex, int maxResult) throws DoubanException, IOException {
102 | String url = RequestUrls.DOUBAN_MUSIC_SUBJECT_PREFIX + "s";
103 | return searchSubject(url, q, tag, startIndex, maxResult);
104 | }
105 |
106 | private DoubanSubjectFeedObj searchSubject (String url, String q, String tag, Integer startIndex, Integer maxResult) throws DoubanException, IOException {
107 | List params = new ArrayList();
108 | if (q != null && q.length() > 0) {
109 | params.add(new BasicNameValuePair("q", q));
110 | }
111 | if (tag != null && tag.length() > 0) {
112 | params.add(new BasicNameValuePair("tag", tag));
113 | }
114 | if (params.isEmpty()) {
115 | throw ErrorHandler.missingRequiredParam();
116 | }
117 | if (startIndex != null) {
118 | params.add(new BasicNameValuePair("start-index", startIndex.toString()));
119 | }
120 | if (maxResult != null) {
121 | params.add(new BasicNameValuePair("max-results", maxResult.toString()));
122 | }
123 | DoubanSubjectFeedObj result = this.client.getResponse(url, params, DoubanSubjectFeedObj.class, false);
124 | return result;
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/service/DoubanNoteService.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.service;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 | import java.util.logging.Logger;
7 |
8 | import org.apache.http.NameValuePair;
9 | import org.apache.http.message.BasicNameValuePair;
10 |
11 | import com.dongxuexidu.douban4j.constants.RequestUrls;
12 | import com.dongxuexidu.douban4j.constants.StatusCode;
13 | import com.dongxuexidu.douban4j.model.app.DoubanException;
14 | import com.dongxuexidu.douban4j.model.common.DoubanAttributeObj;
15 | import com.dongxuexidu.douban4j.model.note.DoubanNoteEntryObj;
16 | import com.dongxuexidu.douban4j.model.note.DoubanNoteFeedObj;
17 | import com.dongxuexidu.douban4j.utils.ErrorHandler;
18 |
19 | /**
20 | *
21 | * @author Zhibo Wei
22 | */
23 | public class DoubanNoteService extends DoubanService {
24 |
25 | final static Logger logger = Logger.getLogger(DoubanNoteService.class.getName());
26 |
27 | public DoubanNoteService() {
28 | super();
29 | }
30 |
31 | public DoubanNoteService(String accessToken) {
32 | super(accessToken);
33 | }
34 |
35 | public DoubanNoteEntryObj getNoteById(long noteId) throws DoubanException, IOException {
36 | String url = RequestUrls.DOUBAN_NOTE_PREFIX + "/" + noteId;
37 | DoubanNoteEntryObj result = this.client.getResponse(url, null, DoubanNoteEntryObj.class, false);
38 | return result;
39 | }
40 |
41 | public DoubanNoteFeedObj getAllNotesFromUser(String userId) throws DoubanException, IOException {
42 | return getAllNotesFromUser(userId, null, null);
43 | }
44 |
45 | public DoubanNoteFeedObj getAllNotesFromUser (String userId, Integer startIndex, Integer maxResult) throws DoubanException, IOException {
46 | String url = RequestUrls.DOUBAN_USER_PREFIX + "/" + userId + "/notes";
47 | List params = new ArrayList();
48 | if (startIndex != null) {
49 | params.add(new BasicNameValuePair("start-index", "" + startIndex));
50 | }
51 | if (maxResult != null) {
52 | params.add(new BasicNameValuePair("max-results", "" + maxResult));
53 | }
54 | DoubanNoteFeedObj result = this.client.getResponse(url, params, DoubanNoteFeedObj.class, false);
55 | return result;
56 | }
57 |
58 | public boolean createNewNote (String title, String content, boolean isPrivate, boolean canReply, String accessToken) throws DoubanException, IOException {
59 | setAccessToken(accessToken);
60 | DoubanNoteEntryObj entry = generateDoubanNoteEntry(title, content, isPrivate, canReply);
61 | if (entry == null) {
62 | throw ErrorHandler.getCustomDoubanException(100, "Note data is not correct, please double check");
63 | }
64 | try {
65 | int responseCode = this.client.postResponseCodeOnly(RequestUrls.DOUBAN_NOTE_PREFIX + "s", entry, true);
66 | if (responseCode != StatusCode.HTTP_STATUS_CREATED) {
67 | return false;
68 | }
69 | return true;
70 | } catch (DoubanException ex) {
71 | if (ex.getErrorCode() == ErrorHandler.HTTP_RESPONSE_ERROR_STATUS_CODE) {
72 | logger.warning(ex.getErrorMsg());
73 | return false;
74 | } else {
75 | throw ex;
76 | }
77 | }
78 | }
79 |
80 | public boolean updateNote (long noteId, String title, String content, boolean isPrivate, boolean canReply, String accessToken) throws DoubanException, IOException {
81 | setAccessToken(accessToken);
82 | DoubanNoteEntryObj entry = generateDoubanNoteEntry(title, content, isPrivate, canReply);
83 | if (entry == null) {
84 | throw ErrorHandler.getCustomDoubanException(100, "Note data is not correct, please double check");
85 | }
86 | try {
87 | int responseCode = this.client.putResponseCodeOnly(RequestUrls.DOUBAN_NOTE_PREFIX + "/" + noteId, entry, true);
88 | if (responseCode != StatusCode.HTTP_STATUS_ACCEPTED) {
89 | return false;
90 | }
91 | return true;
92 | } catch (DoubanException ex) {
93 | if (ex.getErrorCode() == ErrorHandler.HTTP_RESPONSE_ERROR_STATUS_CODE) {
94 | logger.warning(ex.getErrorMsg());
95 | return false;
96 | } else {
97 | throw ex;
98 | }
99 | }
100 | }
101 |
102 | public boolean deleteNote (long noteId, String accessToken) throws DoubanException, IOException {
103 | setAccessToken(accessToken);
104 | try {
105 | int responseCode = this.client.deleteResponse(RequestUrls.DOUBAN_NOTE_PREFIX + "/" + noteId, true);
106 | if (responseCode != StatusCode.HTTP_STATUS_OK) {
107 | return false;
108 | }
109 | return true;
110 | } catch (DoubanException ex) {
111 | if (ex.getErrorCode() == ErrorHandler.HTTP_RESPONSE_ERROR_STATUS_CODE) {
112 | logger.warning(ex.getErrorMsg());
113 | return false;
114 | } else {
115 | throw ex;
116 | }
117 | }
118 | }
119 |
120 | private DoubanNoteEntryObj generateDoubanNoteEntry (String title, String content, boolean isPrivate, boolean canReply) {
121 | DoubanNoteEntryObj entry = new DoubanNoteEntryObj();
122 | if (title != null && title.length() > 0) {
123 | entry.setTitle(title);
124 | } else {
125 | return null;
126 | }
127 | if (content != null && content.length() > 0) {
128 | entry.setContent(content);
129 | } else {
130 | return null;
131 | }
132 | List atts = new ArrayList();
133 | DoubanAttributeObj privateAtt = new DoubanAttributeObj();
134 | privateAtt.setName("privacy");
135 | if (isPrivate) {
136 | privateAtt.setValue("private");
137 | } else {
138 | privateAtt.setValue("public");
139 | }
140 | atts.add(privateAtt);
141 | DoubanAttributeObj replyAtt = new DoubanAttributeObj();
142 | replyAtt.setName("can_reply");
143 | replyAtt.setValue(canReply ? "yes" : "no");
144 | atts.add(replyAtt);
145 | entry.setAttributes(atts);
146 | return entry;
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/service/DoubanReviewService.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.service;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 | import java.util.logging.Logger;
7 |
8 | import org.apache.http.NameValuePair;
9 | import org.apache.http.message.BasicNameValuePair;
10 |
11 | import com.dongxuexidu.douban4j.constants.RequestUrls;
12 | import com.dongxuexidu.douban4j.constants.StatusCode;
13 | import com.dongxuexidu.douban4j.model.app.DoubanException;
14 | import com.dongxuexidu.douban4j.model.common.DoubanRatingObj;
15 | import com.dongxuexidu.douban4j.model.review.DoubanReviewEntryObj;
16 | import com.dongxuexidu.douban4j.model.review.DoubanReviewFeedObj;
17 | import com.dongxuexidu.douban4j.model.subject.DoubanSubjectObj;
18 | import com.dongxuexidu.douban4j.utils.ErrorHandler;
19 |
20 | /**
21 | *
22 | * @author Zhibo Wei
23 | */
24 | public class DoubanReviewService extends DoubanService {
25 |
26 | Logger logger = Logger.getLogger(DoubanReviewService.class.getName());
27 |
28 | public enum ReviewOrderBy {
29 | Time {
30 | @Override
31 | public String getValue() {
32 | return "time";
33 | }
34 | },
35 | Score {
36 | @Override
37 | public String getValue() {
38 | return "score";
39 | }
40 | };
41 | public abstract String getValue();
42 | }
43 |
44 | public DoubanReviewService () {
45 | super();
46 | }
47 |
48 | public DoubanReviewService (String accessToken) {
49 | super(accessToken);
50 | }
51 |
52 | public DoubanReviewEntryObj getReviewById (long reviewId) throws DoubanException, IOException {
53 | String url = RequestUrls.DOUBAN_REVIEW_PREFIX + "/" + reviewId;
54 | DoubanReviewEntryObj result = this.client.getResponse(url, null, DoubanReviewEntryObj.class, false);
55 | return result;
56 | }
57 |
58 | public DoubanReviewFeedObj getUsersReview (String userId) throws DoubanException, IOException {
59 | String url = RequestUrls.DOUBAN_USER_PREFIX + "/" + userId + "/reviews";
60 | DoubanReviewFeedObj result = this.client.getResponse(url, null, DoubanReviewFeedObj.class, false);
61 | return result;
62 | }
63 |
64 | /**
65 | * Book
66 | */
67 |
68 | public DoubanReviewFeedObj getBookReviewsBySubjectId (long subjectId) throws DoubanException, IOException {
69 | String url = RequestUrls.DOUBAN_BOOK_SUBJECT_PREFIX + "/" + subjectId + "/reviews";
70 | return getReviewList(url, null, null, null);
71 | }
72 |
73 | public DoubanReviewFeedObj getBookReviewsBySubjectId (long subjectId, int startIndex, int maxResult, ReviewOrderBy orderBy) throws DoubanException, IOException {
74 | String url = RequestUrls.DOUBAN_BOOK_SUBJECT_PREFIX + "/" + subjectId + "/reviews";
75 | return getReviewList(url, startIndex, maxResult, orderBy);
76 | }
77 |
78 | public DoubanReviewFeedObj getBookReviewsByISBNId (String isbnId) throws DoubanException, IOException {
79 | String url = RequestUrls.DOUBAN_BOOK_SUBJECT_PREFIX + "/isbn/" + isbnId + "/reviews";
80 | return getReviewList(url, null, null, null);
81 | }
82 |
83 | public DoubanReviewFeedObj getBookReviewsByISBNId (String isbnId, int startIndex, int maxResult, ReviewOrderBy orderBy) throws DoubanException, IOException {
84 | String url = RequestUrls.DOUBAN_BOOK_SUBJECT_PREFIX + "/isbn/" + isbnId + "/reviews";
85 | return getReviewList(url, startIndex, maxResult, orderBy);
86 | }
87 |
88 | /**
89 | * Movie
90 | */
91 |
92 | public DoubanReviewFeedObj getMovieReviewsBySubjectId (long subjectId) throws DoubanException, IOException {
93 | String url = RequestUrls.DOUBAN_MOVIE_SUBJECT_PREFIX + "/" + subjectId + "/reviews";
94 | return getReviewList(url, null, null, null);
95 | }
96 |
97 | public DoubanReviewFeedObj getMovieReviewsBySubjectId (long subjectId, int startIndex, int maxResult, ReviewOrderBy orderBy) throws DoubanException, IOException {
98 | String url = RequestUrls.DOUBAN_MOVIE_SUBJECT_PREFIX + "/" + subjectId + "/reviews";
99 | return getReviewList(url, startIndex, maxResult, orderBy);
100 | }
101 |
102 | public DoubanReviewFeedObj getMovieReviewsByIMDBId (String imdbId) throws DoubanException, IOException {
103 | String url = RequestUrls.DOUBAN_MOVIE_SUBJECT_PREFIX + "/imdb/" + imdbId + "/reviews";
104 | return getReviewList(url, null, null, null);
105 | }
106 |
107 | public DoubanReviewFeedObj getMovieReviewsByIMDBId (String imdbId, int startIndex, int maxResult, ReviewOrderBy orderBy) throws DoubanException, IOException {
108 | String url = RequestUrls.DOUBAN_MOVIE_SUBJECT_PREFIX + "/imdb/" + imdbId + "/reviews";
109 | return getReviewList(url, startIndex, maxResult, orderBy);
110 | }
111 |
112 | /**
113 | * Music
114 | */
115 |
116 | public DoubanReviewFeedObj getMusicReviewsBySubjectId (long subjectId) throws DoubanException, IOException {
117 | String url = RequestUrls.DOUBAN_MUSIC_SUBJECT_PREFIX + "/" + subjectId + "/reviews";
118 | return getReviewList(url, null, null, null);
119 | }
120 |
121 | public DoubanReviewFeedObj getMusicReviewsBySubjectId (long subjectId, int startIndex, int maxResult, ReviewOrderBy orderBy) throws DoubanException, IOException {
122 | String url = RequestUrls.DOUBAN_MUSIC_SUBJECT_PREFIX + "/" + subjectId + "/reviews";
123 | return getReviewList(url, startIndex, maxResult, orderBy);
124 | }
125 |
126 | private DoubanReviewFeedObj getReviewList (String url, Integer startIndex, Integer maxResult, ReviewOrderBy orderBy) throws DoubanException, IOException {
127 | List params = new ArrayList();
128 | if (startIndex != null) {
129 | params.add(new BasicNameValuePair("start-index", startIndex.toString()));
130 | }
131 | if (maxResult != null) {
132 | params.add(new BasicNameValuePair("max-results", maxResult.toString()));
133 | }
134 | if (orderBy != null) {
135 | params.add(new BasicNameValuePair("orderby", orderBy.getValue()));
136 | }
137 | DoubanReviewFeedObj result = this.client.getResponse(url, params, DoubanReviewFeedObj.class, false);
138 | return result;
139 | }
140 |
141 | public boolean addNewReview (long subjectId, String content, int rating, String title, String accessToken) throws DoubanException, IOException {
142 | setAccessToken(accessToken);
143 | DoubanReviewEntryObj obj = generateReviewObj(subjectId, content, rating, title, null);
144 | if (obj == null) {
145 | throw ErrorHandler.getCustomDoubanException(100, "Review data is not correct, please double check");
146 | }
147 | try {
148 | int responseCode = this.client.postResponseCodeOnly(RequestUrls.DOUBAN_REVIEW_PREFIX + "s", obj, true);
149 | if (responseCode != StatusCode.HTTP_STATUS_CREATED) {
150 | return false;
151 | }
152 | return true;
153 | } catch (DoubanException ex) {
154 | if (ex.getErrorCode() == ErrorHandler.HTTP_RESPONSE_ERROR_STATUS_CODE) {
155 | logger.warning(ex.getErrorMsg());
156 | return false;
157 | } else {
158 | throw ex;
159 | }
160 | }
161 | }
162 |
163 | public boolean updateReview (long reviewId, long subjectId, String content, String title, int rating, String accessToken) throws DoubanException, IOException {
164 | setAccessToken(accessToken);
165 | DoubanReviewEntryObj obj = generateReviewObj(subjectId, content, rating, title, reviewId);
166 | if (obj == null) {
167 | throw ErrorHandler.getCustomDoubanException(100, "Review data is not correct, please double check");
168 | }
169 | try {
170 | int responseCode = this.client.putResponseCodeOnly(RequestUrls.DOUBAN_REVIEW_PREFIX + "/" + reviewId, obj, true);
171 | if (responseCode != StatusCode.HTTP_STATUS_ACCEPTED) {
172 | return false;
173 | }
174 | return true;
175 | } catch (DoubanException ex) {
176 | if (ex.getErrorCode() == ErrorHandler.HTTP_RESPONSE_ERROR_STATUS_CODE) {
177 | logger.warning(ex.getErrorMsg());
178 | return false;
179 | } else {
180 | throw ex;
181 | }
182 | }
183 | }
184 |
185 | public boolean deleteReview (long reviewId, String accessToken) throws DoubanException, IOException {
186 | setAccessToken(accessToken);
187 | try {
188 | int responseCode = this.client.deleteResponse(RequestUrls.DOUBAN_REVIEW_PREFIX + "/" + reviewId, true);
189 | if (responseCode != StatusCode.HTTP_STATUS_OK) {
190 | return false;
191 | }
192 | return true;
193 | } catch (DoubanException ex) {
194 | if (ex.getErrorCode() == ErrorHandler.HTTP_RESPONSE_ERROR_STATUS_CODE) {
195 | logger.warning(ex.getErrorMsg());
196 | return false;
197 | } else {
198 | throw ex;
199 | }
200 | }
201 | }
202 |
203 | private DoubanReviewEntryObj generateReviewObj (long subjectId, String content, int rating, String title, Long reviewUrl) {
204 | DoubanReviewEntryObj obj = new DoubanReviewEntryObj();
205 | if (reviewUrl != null) {
206 | obj.setId(RequestUrls.DOUBAN_REVIEW_PREFIX + "/" + reviewUrl);
207 | }
208 | DoubanSubjectObj sub = new DoubanSubjectObj();
209 | sub.setId("" + subjectId);
210 | obj.setSubject(sub);
211 | if (content != null && content.length() > 0) {
212 | obj.setContent(content);
213 | } else {
214 | obj.setContent("");
215 | }
216 | if (title != null && title.length() > 0) {
217 | obj.setTitle(title);
218 | } else {
219 | obj.setTitle("");
220 | }
221 | DoubanRatingObj rat = new DoubanRatingObj();
222 | if (rating > 5) {
223 | rating = 5;
224 | } else if (rating < 1) {
225 | rating = 1;
226 | }
227 | rat.setValue(rating);
228 | obj.setRating(rat);
229 | return obj;
230 | }
231 |
232 | }
233 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/service/DoubanService.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.service;
2 |
3 | import com.dongxuexidu.douban4j.model.app.DoubanException;
4 | import com.dongxuexidu.douban4j.utils.ErrorHandler;
5 | import com.dongxuexidu.douban4j.utils.HttpManager;
6 |
7 | /**
8 | *
9 | * @author Zhibo Wei
10 | */
11 | public abstract class DoubanService {
12 |
13 | protected HttpManager client = null;
14 |
15 | protected DoubanService () {
16 | this.client = new HttpManager();
17 | }
18 |
19 | protected DoubanService (String accessToken) {
20 | this.client = new HttpManager(accessToken);
21 | }
22 |
23 | protected void setAccessToken (String accessToken) throws DoubanException {
24 | if (accessToken == null || accessToken.isEmpty()) {
25 | throw ErrorHandler.accessTokenNotSet();
26 | }
27 | this.client.setAccessToken(accessToken);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/service/DoubanShuoService.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.service;
2 |
3 | import java.io.IOException;
4 | import java.io.UnsupportedEncodingException;
5 | import java.util.ArrayList;
6 | import java.util.HashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.logging.Logger;
10 |
11 | import net.sf.json.JSONObject;
12 |
13 | import org.apache.http.NameValuePair;
14 | import org.apache.http.message.BasicNameValuePair;
15 |
16 | import com.dongxuexidu.douban4j.constants.RequestUrls;
17 | import com.dongxuexidu.douban4j.model.app.DoubanException;
18 | import com.dongxuexidu.douban4j.model.shuo.DoubanShuoAttachementObj;
19 | import com.dongxuexidu.douban4j.model.shuo.DoubanShuoStatusObj;
20 | import com.dongxuexidu.douban4j.model.shuo.DoubanShuoUserObj;
21 | import com.dongxuexidu.douban4j.utils.Converters;
22 | import com.dongxuexidu.douban4j.utils.ErrorHandler;
23 |
24 | /**
25 | *
26 | * @author Zhibo Wei
27 | */
28 | public class DoubanShuoService extends DoubanService {
29 |
30 | public static enum DoubanShuoCategory {
31 |
32 | Article {
33 | @Override
34 | public String getValue() {
35 | return "article";
36 | }
37 | },
38 | Photo {
39 | @Override
40 | public String getValue() {
41 | return "photo";
42 | }
43 | },
44 | Culture {
45 | @Override
46 | public String getValue() {
47 | return "culture";
48 | }
49 | },
50 | Shopping {
51 | @Override
52 | public String getValue() {
53 | return "shopping";
54 | }
55 | };
56 |
57 | public abstract String getValue();
58 | }
59 |
60 | public static enum DoubanShuoRelation {
61 |
62 | FollowingOnly,
63 | BeFollowedOnly,
64 | Stranger,
65 | Friend;
66 |
67 | }
68 |
69 | final static Logger logger = Logger.getLogger(DoubanShuoService.class.getName());
70 |
71 | public DoubanShuoService(String accessToken) {
72 | super(accessToken);
73 | }
74 |
75 | public DoubanShuoService() {
76 | super();
77 | }
78 |
79 | public DoubanShuoStatusObj[] getHomeTimelineForLoggedInUser (String accessToken) throws DoubanException, IOException {
80 | return getHomeTimelineForLoggedInUser(accessToken, null, null, null, null);
81 | }
82 |
83 | public DoubanShuoStatusObj[] getHomeTimelineForLoggedInUser (String accessToken, Long sinceId, Long untilId, Integer count, DoubanShuoCategory category) throws DoubanException, IOException {
84 | setAccessToken(accessToken);
85 | String url = RequestUrls.DOUBAN_SHUO_STATUS_PREFIX + "/home_timeline";
86 | List params = generateParams(sinceId, untilId, count, category);
87 | DoubanShuoStatusObj[] result = this.client.getResponseInJsonArray(url, params, DoubanShuoStatusObj[].class, true);
88 | return result;
89 | }
90 |
91 | public DoubanShuoStatusObj[] getStatusesByUserId (String uid) throws DoubanException, IOException {
92 | return getStatusesByUserId(uid, null, null);
93 | }
94 |
95 | public DoubanShuoStatusObj[] getStatusesByUserId (String uid, Long sinceId, Long untilId) throws DoubanException, IOException {
96 | String url = RequestUrls.DOUBAN_SHUO_STATUS_PREFIX + "/user_timeline/" + uid;
97 | List params = generateParams(sinceId, untilId, null, null);
98 | DoubanShuoStatusObj[] result = this.client.getResponseInJsonArray(url, params, DoubanShuoStatusObj[].class, false);
99 | return result;
100 | }
101 |
102 | public boolean postNewStatus (String content, DoubanShuoAttachementObj att, String appKey, String accessToken) throws DoubanException, IOException {
103 | setAccessToken(accessToken);
104 | if (content == null || content.isEmpty()) {
105 | throw ErrorHandler.missingRequiredParam();
106 | }
107 | Map params = new HashMap();
108 | params.put("source", appKey);
109 | params.put("text", content);
110 | if (att != null) {
111 | DoubanShuoAttachementObj[] atts = {att};
112 | String attStr = Converters.parseDoubanObjToJSONStr(atts);
113 | System.out.println("attstr : " + attStr);
114 | params.put("attachments", attStr);
115 | }
116 | try {
117 | String result = this.client.postEncodedEntry(RequestUrls.DOUBAN_SHUO_STATUS_PREFIX + "/", params, true);
118 | logger.info("new post : " + result);
119 | return true;
120 | } catch (UnsupportedEncodingException ex) {
121 | logger.warning(ex.getMessage());
122 | return false;
123 | }
124 | }
125 |
126 | public DoubanShuoUserObj getUserInfoById (String userId) throws DoubanException, IOException {
127 | String url = RequestUrls.DOUBAN_SHUO_USER_PREFIX + "/" + userId;
128 | DoubanShuoUserObj result = this.client.getResponseInJson(url, null, DoubanShuoUserObj.class, false);
129 | return result;
130 | }
131 |
132 | public DoubanShuoUserObj[] getFollowingUserByUserId (String userId) throws DoubanException, IOException {
133 | String url = RequestUrls.DOUBAN_SHUO_USER_PREFIX + "/" + userId + "/following";
134 | DoubanShuoUserObj[] result = this.client.getResponseInJsonArray(url, null, DoubanShuoUserObj[].class, false);
135 | return result;
136 | }
137 |
138 | public DoubanShuoUserObj[] getFollowersByUserId (String userId) throws DoubanException, IOException {
139 | String url = RequestUrls.DOUBAN_SHUO_USER_PREFIX + "/" + userId + "/followers";
140 | DoubanShuoUserObj[] result = this.client.getResponseInJsonArray(url, null, DoubanShuoUserObj[].class, false);
141 | return result;
142 | }
143 |
144 | public boolean followUser (String targetId, String appKey, String accessToken) throws DoubanException, IOException {
145 | setAccessToken(accessToken);
146 | if (targetId == null || targetId.isEmpty()) {
147 | throw ErrorHandler.missingRequiredParam();
148 | }
149 | Map params = new HashMap();
150 | params.put("source", appKey);
151 | params.put("user_id", targetId);
152 | String url = RequestUrls.DOUBAN_SHUO_FRIENDSHIP_PREFIX + "/create";
153 | try {
154 | String result = this.client.postEncodedEntry(url, params, true);
155 | logger.info("new following user : " + result);
156 | return true;
157 | } catch (UnsupportedEncodingException ex) {
158 | logger.warning(ex.getMessage());
159 | return false;
160 | }
161 | }
162 |
163 | public DoubanShuoRelation getRelationship (String sourceId, String targetId, String appKey) throws DoubanException, IOException {
164 | String url = RequestUrls.DOUBAN_SHUO_FRIENDSHIP_PREFIX + "/show";
165 | Map params = new HashMap();
166 | params.put("source", appKey);
167 | params.put("source_id", sourceId);
168 | params.put("target_id", targetId);
169 | try {
170 | String result = this.client.postEncodedEntry(url, params, false);
171 | DoubanShuoRelation relation = determineRelation(result);
172 | return relation;
173 | } catch (UnsupportedEncodingException ex) {
174 | logger.warning(ex.getMessage());
175 | return null;
176 | }
177 | }
178 |
179 | private DoubanShuoRelation determineRelation (String result) {
180 | JSONObject obj = JSONObject.fromObject(result.trim());
181 | if (obj.containsKey("source") && obj.containsKey("target")) {
182 | JSONObject source = obj.getJSONObject("source");
183 | boolean following = source.getBoolean("following");
184 | boolean followedBy = source.getBoolean("followed_by");
185 | if (following && (!followedBy)) {
186 | return DoubanShuoRelation.FollowingOnly;
187 | } else if ((!following) && followedBy) {
188 | return DoubanShuoRelation.BeFollowedOnly;
189 | } else if (following && followedBy) {
190 | return DoubanShuoRelation.Friend;
191 | } else {
192 | return DoubanShuoRelation.Stranger;
193 | }
194 | } else {
195 | return null;
196 | }
197 | }
198 |
199 | private List generateParams (Long sinceId, Long untilId, Integer count, DoubanShuoCategory category) {
200 | List params = new ArrayList();
201 | if (sinceId != null) {
202 | params.add(new BasicNameValuePair("since_id", "" + sinceId));
203 | }
204 | if (untilId != null) {
205 | params.add(new BasicNameValuePair("until_id", "" + untilId));
206 | }
207 | if (count != null) {
208 | params.add(new BasicNameValuePair("count", "" + count));
209 | }
210 | if (category != null) {
211 | params.add(new BasicNameValuePair("category", category.getValue()));
212 | }
213 | return params;
214 | }
215 |
216 | }
217 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/service/DoubanUserService.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.service;
2 |
3 | import java.io.IOException;
4 | import java.net.URLEncoder;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import org.apache.http.NameValuePair;
9 | import org.apache.http.message.BasicNameValuePair;
10 |
11 | import com.dongxuexidu.douban4j.constants.RequestUrls;
12 | import com.dongxuexidu.douban4j.model.app.DoubanException;
13 | import com.dongxuexidu.douban4j.model.user.DoubanUserFeedObj;
14 | import com.dongxuexidu.douban4j.model.user.DoubanUserObj;
15 | import com.dongxuexidu.douban4j.utils.ErrorHandler;
16 |
17 | /**
18 | *
19 | * @author Zhibo Wei
20 | */
21 |
22 | public class DoubanUserService extends DoubanService {
23 |
24 | public DoubanUserService () {
25 | super();
26 | }
27 |
28 | public DoubanUserService (String accessToken) {
29 | super(accessToken);
30 | }
31 |
32 | public DoubanUserObj getUserProfileByUid (String uid) throws DoubanException, IOException {
33 | String url = RequestUrls.DOUBAN_USER_PREFIX + "/" + uid;
34 | DoubanUserObj result = this.client.getResponse(url, null, DoubanUserObj.class, false);
35 | return result;
36 | }
37 |
38 | public DoubanUserObj getLoggedInUserProfile (String accessToken) throws DoubanException, IOException {
39 | setAccessToken(accessToken);
40 | DoubanUserObj result = this.client.getResponse(RequestUrls.DOUBAN_USER_PREFIX + URLEncoder.encode("/@me", "utf-8"), null, DoubanUserObj.class, true);
41 | return result;
42 | }
43 |
44 | public DoubanUserFeedObj searchUserProfile (String keyword) throws DoubanException, IOException {
45 | return searchUserProfile(keyword, null, null);
46 | }
47 |
48 | public DoubanUserFeedObj searchUserProfile (String keyword, Integer startIndex, Integer maxResultCount) throws DoubanException, IOException {
49 | List params = new ArrayList();
50 | if (keyword != null && keyword.length() > 0) {
51 | params.add(new BasicNameValuePair("q", keyword));
52 | } else {
53 | throw ErrorHandler.missingRequiredParam();
54 | }
55 | if (startIndex != null) {
56 | params.add(new BasicNameValuePair("start-index", startIndex.toString()));
57 | }
58 | if (maxResultCount != null) {
59 | params.add(new BasicNameValuePair("max-results", maxResultCount.toString()));
60 | }
61 | DoubanUserFeedObj result = this.client.getResponse(RequestUrls.DOUBAN_USER_PREFIX, params, DoubanUserFeedObj.class, false);
62 | return result;
63 | }
64 |
65 | public DoubanUserFeedObj getUsersFriendsList (String uid, String accessToken) throws DoubanException, IOException {
66 | return getUsersFriendsList(uid, null, null, accessToken);
67 | }
68 |
69 | public DoubanUserFeedObj getUsersFriendsList (String uid, Integer startIndex, Integer maxResultCount, String accessToken) throws DoubanException, IOException {
70 | setAccessToken(accessToken);
71 | List params = new ArrayList();
72 | if (uid == null || uid.isEmpty()) {
73 | throw ErrorHandler.getCustomDoubanException(100, "We cannot get the friend list from a ghost, please specify a user id");
74 | }
75 | if (startIndex != null) {
76 | params.add(new BasicNameValuePair("start-index", startIndex.toString()));
77 | }
78 | if (maxResultCount != null) {
79 | params.add(new BasicNameValuePair("max-results", maxResultCount.toString()));
80 | }
81 | String url = RequestUrls.DOUBAN_USER_PREFIX + "/" + uid + "/friends";
82 | DoubanUserFeedObj result = this.client.getResponse(url, params, DoubanUserFeedObj.class, true);
83 | return result;
84 | }
85 |
86 | public DoubanUserFeedObj getUsersContactsList (String uid) throws DoubanException, IOException {
87 | return getUsersContactsList(uid, null, null);
88 | }
89 |
90 | public DoubanUserFeedObj getUsersContactsList (String uid, Integer startIndex, Integer maxResultCount) throws DoubanException, IOException {
91 | List params = new ArrayList();
92 | if (uid == null || uid.isEmpty()) {
93 | throw ErrorHandler.getCustomDoubanException(100, "We cannot get the contact list from a ghost, please specify a user id");
94 | }
95 | if (startIndex != null) {
96 | params.add(new BasicNameValuePair("start-index", startIndex.toString()));
97 | }
98 | if (maxResultCount != null) {
99 | params.add(new BasicNameValuePair("max-results", maxResultCount.toString()));
100 | }
101 | String url = RequestUrls.DOUBAN_USER_PREFIX + "/" + uid + "/contacts";
102 | DoubanUserFeedObj result = this.client.getResponse(url, params, DoubanUserFeedObj.class, false);
103 | return result;
104 | }
105 |
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/utils/Converters.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.utils;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.IOException;
5 | import java.util.Date;
6 |
7 | import net.sf.json.JSONException;
8 | import net.sf.json.JSONObject;
9 |
10 | import com.dongxuexidu.douban4j.constants.DefaultConfigs;
11 | import com.dongxuexidu.douban4j.model.app.AccessToken;
12 | import com.dongxuexidu.douban4j.model.app.DoubanException;
13 | import com.google.api.client.http.json.JsonHttpContent;
14 | import com.google.api.client.http.xml.XmlHttpContent;
15 | import com.google.api.client.json.jackson.JacksonFactory;
16 | import com.google.api.client.util.DateTime;
17 |
18 | /**
19 | *
20 | * @author Zhibo Wei
21 | */
22 | public class Converters {
23 |
24 | public static AccessToken stringToAccessToken(String responseStr) throws DoubanException {
25 | if (responseStr == null) {
26 | throw ErrorHandler.cannotGetAccessToken();
27 | }
28 | System.out.println("got result !");
29 | System.out.println(responseStr);
30 | JSONObject jObj = Converters.toJsonObj(responseStr);
31 | AccessToken token = new AccessToken();
32 | if (jObj.containsKey("access_token")) {
33 | String accessToken = jObj.getString("access_token");
34 | token.setAccessToken(accessToken);
35 | } else {
36 | throw ErrorHandler.cannotGetAccessToken();
37 | }
38 | if (jObj.containsKey("expires_in")) {
39 | int expiresIn = jObj.getInt("expires_in");
40 | token.setExpiresIn(expiresIn);
41 | } else {
42 | throw ErrorHandler.cannotGetAccessToken();
43 | }
44 | if (jObj.containsKey("refresh_token")) {
45 | String refreshToken = jObj.getString("refresh_token");
46 | token.setRefreshToken(refreshToken);
47 | }
48 | if (jObj.containsKey("douban_user_id")) {
49 | String doubanUserId = jObj.getString("douban_user_id");
50 | token.setDoubanUserId(doubanUserId);
51 | }
52 | return token;
53 | }
54 |
55 | public static Date convertStringToDateTimeInRFC3339(String dateStr) {
56 | DateTime dt = DateTime.parseRfc3339(dateStr);
57 | return new Date(dt.getValue());
58 | }
59 |
60 | public static String convertDateToStringInRFC3339(Date date) {
61 | DateTime dt = new DateTime(date.getTime(), 480);
62 | String wholeFormat = dt.toString();
63 | //Do a little hack here for converting the date into the proper string
64 | String result = wholeFormat.substring(0, wholeFormat.indexOf(".")) + wholeFormat.substring(wholeFormat.indexOf(".") + 4);
65 | return result;
66 | }
67 |
68 | public static JSONObject toJsonObj(String jsonStr) throws DoubanException {
69 | try {
70 | JSONObject result = JSONObject.fromObject(jsonStr);
71 | return result;
72 | } catch (JSONException ex) {
73 | throw ErrorHandler.wrongJsonFormat(jsonStr);
74 | }
75 | }
76 |
77 | public static String parseDoubanObjToJSONStr(T obj) throws IOException {
78 | JsonHttpContent content = new JsonHttpContent(new JacksonFactory(), obj);
79 | ByteArrayOutputStream os = new ByteArrayOutputStream();
80 | content.writeTo(os);
81 | String result = new String(os.toByteArray());
82 | return result;
83 | }
84 |
85 | public static String parseDoubanObjToXMLStr(T obj) throws IOException {
86 | XmlHttpContent content = new XmlHttpContent(DefaultConfigs.DOUBAN_XML_NAMESPACE, "entry", obj);
87 | ByteArrayOutputStream os = new ByteArrayOutputStream();
88 | content.writeTo(os);
89 | String result = new String(os.toByteArray());
90 | return result;
91 | }
92 |
93 | public static void main(String[] args) {
94 | System.out.println(convertStringToDateTimeInRFC3339("2006-03-29T10:36:19+08:00"));
95 | System.out.println(convertDateToStringInRFC3339(new Date()));
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/utils/ErrorHandler.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.utils;
2 |
3 | import com.dongxuexidu.douban4j.model.app.DoubanException;
4 | import com.google.api.client.http.HttpResponseException;
5 |
6 | /**
7 | *
8 | * @author Zhibo Wei
9 | */
10 | public class ErrorHandler {
11 |
12 | public static final int HTTP_RESPONSE_ERROR_STATUS_CODE = 1015;
13 | public static final int ACCESS_TOKEN_NOT_SET = 727;
14 | public static final int MISSING_REQUIRED_PARAM = 728;
15 |
16 | public static DoubanException accessTokenNotSet () {
17 | return new DoubanException(ACCESS_TOKEN_NOT_SET, "This method needs access token to gain accessability");
18 | }
19 |
20 | public static DoubanException missingRequiredParam () {
21 | return new DoubanException(MISSING_REQUIRED_PARAM, "This method is missing required params");
22 | }
23 |
24 | public static DoubanException cannotGetAccessToken () {
25 | return new DoubanException(ACCESS_TOKEN_NOT_SET, "Cannot get access token, IO exception");
26 | }
27 |
28 | public static DoubanException getCustomDoubanException (int code, String msg) {
29 | return new DoubanException(code, msg);
30 | }
31 |
32 | public static DoubanException handleHttpResponseError (HttpResponseException ex) {
33 | return new DoubanException(HTTP_RESPONSE_ERROR_STATUS_CODE, "HttpResponseException : http status : " + ex.getStatusCode() + " message : " + ex.getMessage());
34 | }
35 |
36 | public static DoubanException wrongJsonFormat (String rawString) {
37 | return new DoubanException(100, "Illegal JSON format : " + rawString);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/dongxuexidu/douban4j/utils/HttpManager.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.utils;
2 |
3 | import java.io.IOException;
4 | import java.net.URLEncoder;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import org.apache.http.NameValuePair;
9 |
10 | import com.dongxuexidu.douban4j.constants.DefaultConfigs;
11 | import com.dongxuexidu.douban4j.model.IDoubanObject;
12 | import com.dongxuexidu.douban4j.model.app.DoubanException;
13 | import com.dongxuexidu.douban4j.model.user.DoubanUserObj;
14 | import com.google.api.client.http.GenericUrl;
15 | import com.google.api.client.http.HttpHeaders;
16 | import com.google.api.client.http.HttpRequest;
17 | import com.google.api.client.http.HttpRequestFactory;
18 | import com.google.api.client.http.HttpRequestInitializer;
19 | import com.google.api.client.http.HttpResponse;
20 | import com.google.api.client.http.HttpResponseException;
21 | import com.google.api.client.http.MultipartRelatedContent;
22 | import com.google.api.client.http.UrlEncodedContent;
23 | import com.google.api.client.http.apache.ApacheHttpTransport;
24 | import com.google.api.client.http.xml.atom.AtomContent;
25 | import com.google.api.client.json.JsonObjectParser;
26 | import com.google.api.client.json.jackson.JacksonFactory;
27 | import com.google.api.client.xml.XmlObjectParser;
28 |
29 |
30 | /**
31 | *
32 | * @author Zhibo Wei
33 | */
34 | public class HttpManager {
35 |
36 | private static final ApacheHttpTransport APACHE_HTTP_TRANSPORT = new ApacheHttpTransport();
37 | private static final String CHARSET = "UTF-8";
38 | private String accessToken = null;
39 | HttpRequestFactory requestFactory = null;
40 |
41 | public HttpManager() {
42 | requestFactory = APACHE_HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
43 | @Override
44 | public void initialize(HttpRequest hr) throws IOException {
45 | hr.setParser(new XmlObjectParser(DefaultConfigs.DOUBAN_XML_NAMESPACE));
46 | HttpHeaders header = new HttpHeaders();
47 | header.setUserAgent("Dongxuexidu - Douban Java SDK");
48 | hr.setHeaders(header);
49 | hr.setNumberOfRetries(3);
50 | }
51 | });
52 | }
53 |
54 | public HttpManager(String accessToken) {
55 | this();
56 | this.accessToken = accessToken;
57 | }
58 |
59 | public void setAccessToken(String accessToken) {
60 | this.accessToken = accessToken;
61 | }
62 |
63 | private boolean hasAccessTokenBeenSet() {
64 | return !(this.accessToken == null || this.accessToken.isEmpty());
65 | }
66 |
67 | public T getResponse(String url, List params, Class responseType, boolean needAccessToken) throws DoubanException, IOException {
68 | if (params != null && params.size() > 0) {
69 | String encodedParams = encodeParameters(params);
70 | url = url + "?" + encodedParams;
71 | }
72 | HttpRequest method = requestFactory.buildGetRequest(new GenericUrl(url));
73 | return httpRequest(method, needAccessToken).parseAs(responseType);
74 | }
75 |
76 | public T getResponseInJson(String url, List params, Class responseType, boolean needAccessToken) throws DoubanException, IOException {
77 | if (params != null && params.size() > 0) {
78 | String encodedParams = encodeParameters(params);
79 | url = url + "?" + encodedParams;
80 | }
81 | HttpRequest method = requestFactory.buildGetRequest(new GenericUrl(url));
82 | method.setParser(new JsonObjectParser(new JacksonFactory()));
83 | return httpRequest(method, needAccessToken).parseAs(responseType);
84 | }
85 |
86 | public T getResponseInJsonArray(String url, List params, Class responseType, boolean needAccessToken) throws DoubanException, IOException {
87 | if (params != null && params.size() > 0) {
88 | String encodedParams = encodeParameters(params);
89 | url = url + "?" + encodedParams;
90 | }
91 | HttpRequest method = requestFactory.buildGetRequest(new GenericUrl(url));
92 | method.setParser(new JsonObjectParser(new JacksonFactory()));
93 | return httpRequest(method, needAccessToken).parseAs(responseType);
94 | }
95 |
96 | public String postEncodedEntry (String url, Map params, boolean needAccessToken) throws DoubanException, IOException {
97 | UrlEncodedContent content = new UrlEncodedContent(params);
98 | HttpRequest method = requestFactory.buildPostRequest(new GenericUrl(url), content);
99 | return httpRequest(method, needAccessToken).parseAsString();
100 | }
101 |
102 | public String postMultipartEntry (String url, Map params, boolean needAccessToken) throws DoubanException, IOException {
103 | UrlEncodedContent uec = new UrlEncodedContent(params);
104 | MultipartRelatedContent content = new MultipartRelatedContent(uec);
105 | HttpRequest method = requestFactory.buildPostRequest(new GenericUrl(url), content);
106 | return httpRequest(method, needAccessToken).parseAsString();
107 | }
108 |
109 | public W postResponse(String url, T requestObj, Class responseType, boolean needAccessToken) throws DoubanException, IOException {
110 | AtomContent content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, requestObj);
111 | HttpRequest method = requestFactory.buildPostRequest(new GenericUrl(url), content);
112 | return httpRequest(method, needAccessToken).parseAs(responseType);
113 | }
114 |
115 | public W postResponseInJson(String url, T requestObj, Class responseType, boolean needAccessToken) throws DoubanException, IOException {
116 | AtomContent content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, requestObj);
117 | HttpRequest method = requestFactory.buildPostRequest(new GenericUrl(url), content);
118 | method.setParser(new JsonObjectParser(new JacksonFactory()));
119 | return httpRequest(method, needAccessToken).parseAs(responseType);
120 | }
121 |
122 | public int postResponseCodeOnly(String url, T requestObj, boolean needAccessToken) throws DoubanException, IOException {
123 | AtomContent content = null;
124 | if (requestObj != null) {
125 | content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, requestObj);
126 | } else {
127 | //Obviously the null content (proved) is not accecptable to Douban's API. Therefore, this empty obj is added for fooling Douban around, they don't care what's inside it anyway.
128 | content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, new DoubanUserObj());
129 | }
130 | HttpRequest method = requestFactory.buildPostRequest(new GenericUrl(url), content);
131 | HttpResponse response = httpRequest(method, needAccessToken);
132 | return response.getStatusCode();
133 | }
134 |
135 | public W putResponse(String url, T requestObj, Class responseType, boolean needAccessToken) throws DoubanException, IOException {
136 | AtomContent content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, requestObj);
137 | HttpRequest method = requestFactory.buildPutRequest(new GenericUrl(url), content);
138 | return httpRequest(method, needAccessToken).parseAs(responseType);
139 | }
140 |
141 | public W putResponseInJson(String url, T requestObj, Class responseType, boolean needAccessToken) throws DoubanException, IOException {
142 | AtomContent content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, requestObj);
143 | HttpRequest method = requestFactory.buildPutRequest(new GenericUrl(url), content);
144 | method.setParser(new JsonObjectParser(new JacksonFactory()));
145 | return httpRequest(method, needAccessToken).parseAs(responseType);
146 | }
147 |
148 | public int putResponseCodeOnly(String url, T requestObj, boolean needAccessToken) throws DoubanException, IOException {
149 | AtomContent content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, requestObj);
150 | HttpRequest method = requestFactory.buildPutRequest(new GenericUrl(url), content);
151 | return httpRequest(method, needAccessToken).getStatusCode();
152 | }
153 |
154 | public int deleteResponse(String url, boolean needAccessToken) throws DoubanException, IOException {
155 | HttpRequest method = requestFactory.buildDeleteRequest(new GenericUrl(url));
156 | return httpRequest(method, needAccessToken).getStatusCode();
157 | }
158 |
159 | private HttpResponse httpRequest(HttpRequest method, boolean needToken) throws DoubanException, IOException {
160 | try {
161 | if (needToken) {
162 | if (!hasAccessTokenBeenSet()) {
163 | throw ErrorHandler.accessTokenNotSet();
164 | }
165 | HttpHeaders headers = method.getHeaders();
166 | headers.setAuthorization("Bearer " + this.accessToken);
167 | }
168 | HttpResponse res = method.execute();
169 | return res;
170 | } catch (HttpResponseException ex) {
171 | throw ErrorHandler.handleHttpResponseError(ex);
172 | }
173 | }
174 |
175 | private static String encodeParameters(List params) {
176 | StringBuilder buf = new StringBuilder();
177 | int j = 0;
178 | for (NameValuePair nvp : params) {
179 | if (j != 0) {
180 | buf.append("&");
181 | }
182 | j++;
183 | try {
184 | buf.append(URLEncoder.encode(nvp.getName(), CHARSET)).append("=").append(URLEncoder.encode(nvp.getValue(), CHARSET));
185 | } catch (java.io.UnsupportedEncodingException ex) {
186 | System.out.println("Shouldn't go this far");
187 | }
188 | }
189 | return buf.toString();
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/src/test/java/com/dongxuexidu/douban4j/service/DoubanBookMovieMusicServiceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.service;
6 |
7 | import junit.framework.TestCase;
8 |
9 | import com.dongxuexidu.douban4j.model.subject.DoubanSubjectFeedObj;
10 | import com.dongxuexidu.douban4j.model.subject.DoubanSubjectObj;
11 | import com.dongxuexidu.douban4j.model.v2.DoubanSubjectListObj;
12 |
13 | /**
14 | *
15 | * @author Zhibo Wei
16 | */
17 | public class DoubanBookMovieMusicServiceTest extends TestCase {
18 |
19 | private String accessToken = "xxx";
20 |
21 | /**
22 | * Test of getBookInfoById method, of class DoubanBookMovieMusicService.
23 | */
24 | public void testGetBookInfoById() throws Exception {
25 | System.out.println("getBookInfoById");
26 | long bookId = 10440147L;
27 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
28 | DoubanSubjectObj result = instance.getBookInfoById(bookId);
29 | assertEquals(result.getTitle(), "世间的名字");
30 | }
31 |
32 | /**
33 | * Test of getBookInfoByISBN method, of class DoubanBookMovieMusicService.
34 | */
35 | public void testGetBookInfoByISBN() throws Exception {
36 | System.out.println("getBookInfoByISBN");
37 | String isbn = "9787208104815";
38 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
39 | DoubanSubjectObj result = instance.getBookInfoByISBN(isbn);
40 | assertEquals(result.getTitle(), "世间的名字");
41 | }
42 |
43 | /**
44 | * Test of getMovieInfoById method, of class DoubanBookMovieMusicService.
45 | */
46 | public void testGetMovieInfoById() throws Exception {
47 | System.out.println("getMovieInfoById");
48 | long movieId = 6041191L;
49 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
50 | DoubanSubjectObj result = instance.getMovieInfoById(movieId);
51 | System.out.println("title : " + result.getTitle());
52 | assertEquals(result.getTitle(), "听风者");
53 | }
54 |
55 | /**
56 | * Test of getMovieInfoByIMDBId method, of class DoubanBookMovieMusicService.
57 | */
58 | public void testGetMovieInfoByIMDBId() throws Exception {
59 | System.out.println("getMovieInfoByIMDBId");
60 | String imdbId = "tt2078768";
61 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
62 | DoubanSubjectObj result = instance.getMovieInfoByIMDBId(imdbId);
63 | System.out.println("title : " + result.getTitle());
64 | assertEquals(result.getTitle(), "听风者");
65 | }
66 |
67 | /**
68 | * Test of getMoviesTop250 method, of class DoubanBookMovieMusicService.
69 | */
70 | public void testGetMoviesTop250() throws Exception {
71 | System.out.println("getMoviesTop250");
72 | int start = 0;
73 | int count = 10;
74 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
75 | DoubanSubjectListObj result = instance.getMoviesTop250(start, count);
76 | System.out.println("title : " + result.getTitle());
77 | assertEquals(result.getTitle(), "豆瓣电影Top250");
78 | }
79 |
80 | /**
81 | * Test of getV2MovieInfoById method, of class DoubanBookMovieMusicService.
82 | */
83 | public void testGetV2MovieInfoById() throws Exception {
84 | System.out.println("getV2MovieInfoById");
85 | long movieId = 6041191L;
86 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
87 | com.dongxuexidu.douban4j.model.v2.DoubanSubjectObj result = instance.getV2MovieInfoById(movieId);
88 | System.out.println("title : " + result.getTitle());
89 | assertEquals(result.getTitle(), "听风者");
90 | }
91 |
92 | /**
93 | * Test of getMusicInfoById method, of class DoubanBookMovieMusicService.
94 | */
95 | public void testGetMusicInfoById() throws Exception {
96 | System.out.println("getMusicInfoById");
97 | long musicId = 4753298L;
98 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
99 | DoubanSubjectObj result = instance.getMusicInfoById(musicId);
100 | System.out.println("title : " + result.getTitle());
101 | assertEquals(result.getTitle(), "艺术男儿裆自强");
102 | }
103 |
104 | /**
105 | * Test of searchBook method, of class DoubanBookMovieMusicService.
106 | */
107 | public void testSearchBook_String_String() throws Exception {
108 | System.out.println("searchBook");
109 | String q = "C语言";
110 | String tag = null;
111 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
112 | DoubanSubjectFeedObj result = instance.searchBook(q, tag);
113 | assertTrue(result.getSubjects().size() > 0);
114 | }
115 |
116 | /**
117 | * Test of searchBook method, of class DoubanBookMovieMusicService.
118 | */
119 | public void testSearchBook_4args() throws Exception {
120 | System.out.println("searchBook");
121 | String q = "C语言";
122 | String tag = "C";
123 | int startIndex = 0;
124 | int maxResult = 2;
125 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
126 | DoubanSubjectFeedObj result = instance.searchBook(q, tag, startIndex, maxResult);
127 | assertTrue(result.getSubjects().size() == 2);
128 | }
129 |
130 | /**
131 | * Test of searchMovie method, of class DoubanBookMovieMusicService.
132 | */
133 | public void testSearchMovie_String_String() throws Exception {
134 | System.out.println("searchMovie");
135 | String q = "batman";
136 | String tag = null;
137 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
138 | DoubanSubjectFeedObj result = instance.searchMovie(q, tag);
139 | assertTrue(result.getSubjects().size() > 0);
140 | }
141 |
142 | /**
143 | * Test of searchMovie method, of class DoubanBookMovieMusicService.
144 | */
145 | public void testSearchMovie_4args() throws Exception {
146 | System.out.println("searchMovie");
147 | String q = "batman";
148 | String tag = "蝙蝠侠";
149 | int startIndex = 0;
150 | int maxResult = 2;
151 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
152 | DoubanSubjectFeedObj result = instance.searchMovie(q, tag, startIndex, maxResult);
153 | assertTrue(result.getSubjects().size() == 2);
154 | }
155 |
156 | /**
157 | * Test of searchMusic method, of class DoubanBookMovieMusicService.
158 | */
159 | public void testSearchMusic_String_String() throws Exception {
160 | System.out.println("searchMusic");
161 | String q = "歌";
162 | String tag = null;
163 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
164 | DoubanSubjectFeedObj result = instance.searchMusic(q, tag);
165 | assertTrue(result.getSubjects().size() > 0);
166 | }
167 |
168 | /**
169 | * Test of searchMusic method, of class DoubanBookMovieMusicService.
170 | */
171 | public void testSearchMusic_4args() throws Exception {
172 | System.out.println("searchMusic");
173 | String q = "歌";
174 | String tag = "歌";
175 | int startIndex = 0;
176 | int maxResult = 2;
177 | DoubanBookMovieMusicService instance = new DoubanBookMovieMusicService();
178 | DoubanSubjectFeedObj result = instance.searchMusic(q, tag, startIndex, maxResult);
179 | assertTrue(result.getSubjects().size() == 2);
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/src/test/java/com/dongxuexidu/douban4j/service/DoubanCollectionServiceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.service;
6 |
7 | import java.util.ArrayList;
8 | import java.util.Date;
9 | import java.util.List;
10 |
11 | import junit.framework.TestCase;
12 |
13 | import com.dongxuexidu.douban4j.model.collection.DoubanCollectionFeedObj;
14 | import com.dongxuexidu.douban4j.model.collection.DoubanCollectionObj;
15 | import com.dongxuexidu.douban4j.service.DoubanCollectionService.CollectionCategory;
16 | import com.dongxuexidu.douban4j.service.DoubanCollectionService.CollectionStatus;
17 |
18 | /**
19 | *
20 | * @author Zhibo Wei
21 | */
22 | public class DoubanCollectionServiceTest extends TestCase {
23 |
24 | private String accessToken = "xxx";
25 |
26 | /**
27 | * Test of getCollectionById method, of class DoubanCollectionService.
28 | */
29 | public void testGetCollectionById() throws Exception {
30 | System.out.println("getCollectionById");
31 | Long collectionId = 562332459L;
32 | DoubanCollectionService instance = new DoubanCollectionService();
33 | DoubanCollectionObj result = instance.getCollectionById(collectionId);
34 | assertEquals(result.getSubject().getTitle(), "你好,郑州");
35 | assertTrue(result.getSubject().getCategory().getTerm().contains("music"));
36 | }
37 |
38 | /**
39 | * Test of getUsersCollection method, of class DoubanCollectionService.
40 | */
41 | public void testGetUsersCollection_String() throws Exception {
42 | System.out.println("getUsersCollection");
43 | String userId = "xxx";
44 | DoubanCollectionService instance = new DoubanCollectionService();
45 | DoubanCollectionFeedObj result = instance.getUsersCollection(userId);
46 | for (DoubanCollectionObj col : result.getCollections()) {
47 | System.out.println("col title : " + col.getTitle());
48 | System.out.println("col id : " + col.getId());
49 | System.out.println("col subject title : " + col.getSubject().getTitle());
50 | }
51 | assertTrue(result.getCollections().size() > 0);
52 | }
53 |
54 | /**
55 | * Test of getUsersCollection method, of class DoubanCollectionService.
56 | */
57 | public void testGetUsersCollection_8args() throws Exception {
58 | System.out.println("getUsersCollection");
59 | String userId = "xxx";
60 | CollectionCategory category = CollectionCategory.Music;
61 | String tag = "";
62 | CollectionStatus status = CollectionStatus.MusicEd;
63 | Integer startIndex = 0;
64 | Integer maxResult = 2;
65 | Date startDate = null;
66 | Date endDate = null;
67 | DoubanCollectionService instance = new DoubanCollectionService();
68 | DoubanCollectionFeedObj result = instance.getUsersCollection(userId, category, tag, status, startIndex, maxResult, startDate, endDate);
69 | for (DoubanCollectionObj col : result.getCollections()) {
70 | System.out.println("col title : " + col.getTitle());
71 | System.out.println("col id : " + col.getId());
72 | System.out.println("col user summary : " + col.getSummary());
73 | // System.out.println("col subject title : " + col.getSubject().getTitle());
74 | }
75 | assertTrue(result.getCollections().size() > 0);
76 | }
77 |
78 | /**
79 | * Test of createNewCollection method, of class DoubanCollectionService.
80 | */
81 | public void testCreateNewCollection() throws Exception {
82 | System.out.println("createNewCollection");
83 | CollectionStatus status = CollectionStatus.MovieEd;
84 | List tags = new ArrayList();
85 | tags.add("test");
86 | tags.add("dongxuexidu");
87 | int rating = 5;
88 | String content = "Test From Dongxuexidu";
89 | long subjectId = 00000000l;
90 | boolean isPrivate = false;
91 | DoubanCollectionService instance = new DoubanCollectionService();
92 | boolean result = instance.createNewCollection(status, tags, rating, content, subjectId, isPrivate, accessToken);
93 | assertTrue(result);
94 | }
95 |
96 | /**
97 | * Test of updateCollection method, of class DoubanCollectionService.
98 | */
99 | public void testUpdateCollection() throws Exception {
100 | System.out.println("updateCollection");
101 | Long collectionId = 00000000L;
102 | CollectionStatus status = CollectionStatus.MusicEd;
103 | List tags = new ArrayList();
104 | tags.add("test");
105 | tags.add("dongxuexidu");
106 | int rating = 5;
107 | String content = "Test From Dongxuexidu";
108 | long subjectId = 00000000l;
109 | DoubanCollectionService instance = new DoubanCollectionService();
110 | boolean result = instance.updateCollection(collectionId, status, tags, rating, content, subjectId, accessToken);
111 | assertTrue(result);
112 | }
113 |
114 | /**
115 | * Test of deleteCollection method, of class DoubanCollectionService.
116 | */
117 | public void testDeleteCollection() throws Exception {
118 | System.out.println("deleteCollection");
119 | Long collectionId = 00000000l;
120 | DoubanCollectionService instance = new DoubanCollectionService();
121 | boolean result = instance.deleteCollection(collectionId, accessToken);
122 | assertTrue(result);
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/test/java/com/dongxuexidu/douban4j/service/DoubanMailServiceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.service;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import junit.framework.TestCase;
11 |
12 | import com.dongxuexidu.douban4j.model.doumail.DoubanMailEntryObj;
13 | import com.dongxuexidu.douban4j.model.doumail.DoubanMailFeedObj;
14 |
15 | /**
16 | *
17 | * @author Zhibo Wei
18 | */
19 | public class DoubanMailServiceTest extends TestCase {
20 |
21 | private String accessToken = "xxx";
22 |
23 | /**
24 | * Test of getMailsFromInbox method, of class DoubanMailService.
25 | */
26 | public void testGetMailsFromInbox_0args() throws Exception {
27 | System.out.println("getMailsFromInbox");
28 | DoubanMailService instance = new DoubanMailService(accessToken);
29 | DoubanMailFeedObj result = instance.getMailsFromInbox();
30 | for (DoubanMailEntryObj mail : result.getEntries()) {
31 | System.out.println("title : " + mail.getTitle());
32 | System.out.println("author : " + mail.getAuthor().getName());
33 | }
34 | assertTrue(result.getEntries().size() > 0);
35 | }
36 |
37 | /**
38 | * Test of getMailsFromInbox method, of class DoubanMailService.
39 | */
40 | public void testGetMailsFromInbox_Integer_Integer() throws Exception {
41 | System.out.println("getMailsFromInbox");
42 | Integer startIndex = 0;
43 | Integer maxResult = 2;
44 | DoubanMailService instance = new DoubanMailService(accessToken);
45 | DoubanMailFeedObj result = instance.getMailsFromInbox(startIndex, maxResult);
46 | assertEquals(result.getEntries().size(), 2);
47 | }
48 |
49 | /**
50 | * Test of getMailsFromOutbox method, of class DoubanMailService.
51 | */
52 | public void testGetMailsFromOutbox_0args() throws Exception {
53 | System.out.println("getMailsFromOutbox");
54 | DoubanMailService instance = new DoubanMailService(accessToken);
55 | DoubanMailFeedObj result = instance.getMailsFromOutbox();
56 | for (DoubanMailEntryObj mail : result.getEntries()) {
57 | System.out.println("title : " + mail.getTitle());
58 | }
59 | assertTrue(result.getEntries().size() > 0);
60 | }
61 |
62 | /**
63 | * Test of getMailsFromOutbox method, of class DoubanMailService.
64 | */
65 | public void testGetMailsFromOutbox_Integer_Integer() throws Exception {
66 | System.out.println("getMailsFromOutbox");
67 | Integer startIndex = 0;
68 | Integer maxResult = 2;
69 | DoubanMailService instance = new DoubanMailService(accessToken);
70 | DoubanMailFeedObj result = instance.getMailsFromOutbox(startIndex, maxResult);
71 | assertEquals(result.getEntries().size(), 2);
72 | }
73 |
74 | /**
75 | * Test of getUnreadMails method, of class DoubanMailService.
76 | */
77 | public void testGetUnreadMails_0args() throws Exception {
78 | System.out.println("getUnreadMails");
79 | DoubanMailService instance = new DoubanMailService(accessToken);
80 | DoubanMailFeedObj result = instance.getUnreadMails();
81 | assertTrue(result.getEntries() == null || result.getEntries().isEmpty());
82 | }
83 |
84 | /**
85 | * Test of getUnreadMails method, of class DoubanMailService.
86 | */
87 | public void testGetUnreadMails_Integer_Integer() throws Exception {
88 | System.out.println("getUnreadMails");
89 | Integer startIndex = 0;
90 | Integer maxResult = 2;
91 | DoubanMailService instance = new DoubanMailService(accessToken);
92 | DoubanMailFeedObj result = instance.getUnreadMails(startIndex, maxResult);
93 | assertTrue(result.getEntries() == null || result.getEntries().isEmpty());
94 | }
95 |
96 | /**
97 | * Test of getMailById method, of class DoubanMailService.
98 | */
99 | public void testGetMailById() throws Exception {
100 | System.out.println("getMailById");
101 | long mailId = 193287780L;
102 | boolean keepUnread = false;
103 | DoubanMailService instance = new DoubanMailService(accessToken);
104 | DoubanMailEntryObj result = instance.getMailById(mailId, keepUnread);
105 | assertEquals(result.getTitle(), "好资源分享——中国的iTune U");
106 | }
107 |
108 | /**
109 | * Test of sendMail method, of class DoubanMailService.
110 | */
111 | public void testSendMail() throws Exception {
112 | System.out.println("sendMail");
113 | String receiverId = "xxx";
114 | String content = "nihao";
115 | String title = "woshi zhu";
116 | DoubanMailService instance = new DoubanMailService(accessToken);
117 | boolean result = instance.sendMail(receiverId, content, title);
118 | assertTrue(result);
119 | }
120 |
121 | /**
122 | * Test of markMailAsRead method, of class DoubanMailService.
123 | */
124 | public void testMarkMailAsRead() throws Exception {
125 | System.out.println("markMailAsRead");
126 | long mailId = 263961976L;
127 | DoubanMailService instance = new DoubanMailService(accessToken);
128 | boolean result = instance.markMailAsRead(mailId);
129 | assertTrue(result);
130 | }
131 |
132 | /**
133 | * Test of deleteMail method, of class DoubanMailService.
134 | */
135 | public void testDeleteMail() throws Exception {
136 | System.out.println("deleteMail");
137 | long mailId = 201129794L;
138 | DoubanMailService instance = new DoubanMailService(accessToken);
139 | boolean result = instance.deleteMail(mailId);
140 | assertTrue(result);
141 | }
142 |
143 | /**
144 | * Test of markMailReadInBatch method, of class DoubanMailService.
145 | */
146 | public void testMarkMailReadInBatch() throws Exception {
147 | System.out.println("markMailReadInBatch");
148 | List ids = new ArrayList();
149 | DoubanMailService instance = new DoubanMailService(accessToken);
150 | boolean expResult = false;
151 | boolean result = instance.markMailReadInBatch(ids);
152 | assertEquals(expResult, result);
153 | // TODO review the generated test code and remove the default call to fail.
154 | fail("The test case is a prototype.");
155 | }
156 |
157 | /**
158 | * Test of deleteMailsInBatch method, of class DoubanMailService.
159 | */
160 | public void testDeleteMailsInBatch() throws Exception {
161 | System.out.println("deleteMailsInBatch");
162 | List ids = new ArrayList();
163 | ids.add(199384010L);
164 | ids.add(195886356L);
165 | DoubanMailService instance = new DoubanMailService(accessToken);
166 | boolean result = instance.deleteMailsInBatch(ids);
167 | assertTrue(result);
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/src/test/java/com/dongxuexidu/douban4j/service/DoubanNoteServiceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.service;
6 |
7 | import junit.framework.TestCase;
8 |
9 | import com.dongxuexidu.douban4j.model.note.DoubanNoteEntryObj;
10 | import com.dongxuexidu.douban4j.model.note.DoubanNoteFeedObj;
11 |
12 | /**
13 | *
14 | * @author Zhibo Wei
15 | */
16 | public class DoubanNoteServiceTest extends TestCase {
17 |
18 | private String accessToken = "xxx";
19 |
20 | /**
21 | * Test of getNoteById method, of class DoubanNoteService.
22 | */
23 | public void testGetNoteById() throws Exception {
24 | System.out.println("getNoteById");
25 | long noteId = 1231L;
26 | DoubanNoteService instance = new DoubanNoteService();
27 | DoubanNoteEntryObj result = instance.getNoteById(noteId);
28 | assertEquals(result.getAuthor().getName(),"张君雅");
29 | }
30 |
31 | /**
32 | * Test of getAllNotesFromUser method, of class DoubanNoteService.
33 | */
34 | public void testGetAllNotesFromUser_String() throws Exception {
35 | System.out.println("getAllNotesFromUser");
36 | String userId = "xxxx";
37 | DoubanNoteService instance = new DoubanNoteService();
38 | DoubanNoteFeedObj result = instance.getAllNotesFromUser(userId);
39 | assertTrue(result.getEntries().size() > 0);
40 | result = instance.getAllNotesFromUser("xxx");
41 | assertTrue(result.getEntries() == null || result.getEntries().isEmpty());
42 | }
43 |
44 | /**
45 | * Test of getAllNotesFromUser method, of class DoubanNoteService.
46 | */
47 | public void testGetAllNotesFromUser_3args() throws Exception {
48 | System.out.println("getAllNotesFromUser");
49 | String userId = "xxx";
50 | Integer startIndex = 0;
51 | Integer maxResult = 2;
52 | DoubanNoteService instance = new DoubanNoteService();
53 | DoubanNoteFeedObj result = instance.getAllNotesFromUser(userId, startIndex, maxResult);
54 | assertTrue(result.getEntries().size() <= 2);
55 | }
56 |
57 | /**
58 | * Test of createNewNote method, of class DoubanNoteService.
59 | */
60 | public void testCreateNewNote() throws Exception {
61 | System.out.println("createNewNote");
62 | String title = "Test from Dongxuexidu";
63 | String content = "Will be deleted in 1mins, whoever (you fxxking lucky bastard) sees this will get blessed.";
64 | boolean isPrivate = false;
65 | boolean canReply = true;
66 | DoubanNoteService instance = new DoubanNoteService();
67 | boolean result = instance.createNewNote(title, content, isPrivate, canReply, accessToken);
68 | assertTrue(result);
69 | }
70 |
71 | /**
72 | * Test of updateNote method, of class DoubanNoteService.
73 | */
74 | public void testUpdateNote() throws Exception {
75 | System.out.println("updateNote");
76 | long noteId = 234003718L;
77 | String title = "Test from Dongxuexidu again";
78 | String content = "Will be deleted in 1mins, whoever (you fxxking lucky boy) sees this will get blessed. A-men";
79 | boolean isPrivate = false;
80 | boolean canReply = true;
81 | DoubanNoteService instance = new DoubanNoteService();
82 | boolean result = instance.updateNote(noteId, title, content, isPrivate, canReply, accessToken);
83 | assertTrue(result);
84 | }
85 |
86 | /**
87 | * Test of deleteNote method, of class DoubanNoteService.
88 | */
89 | public void testDeleteNote() throws Exception {
90 | System.out.println("deleteNote");
91 | long noteId = 23412321313131718L;
92 | DoubanNoteService instance = new DoubanNoteService();
93 | boolean result = instance.deleteNote(noteId, accessToken);
94 | assertTrue(result);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/test/java/com/dongxuexidu/douban4j/service/DoubanShuoServiceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package com.dongxuexidu.douban4j.service;
6 |
7 | import junit.framework.TestCase;
8 |
9 | import com.dongxuexidu.douban4j.constants.DefaultConfigs;
10 | import com.dongxuexidu.douban4j.model.shuo.DoubanShuoStatusObj;
11 | import com.dongxuexidu.douban4j.model.shuo.DoubanShuoUserObj;
12 | import com.dongxuexidu.douban4j.service.DoubanShuoService.DoubanShuoCategory;
13 | import com.dongxuexidu.douban4j.service.DoubanShuoService.DoubanShuoRelation;
14 |
15 | /**
16 | *
17 | * @author Zhibo Wei
18 | */
19 | public class DoubanShuoServiceTest extends TestCase {
20 |
21 | private String accessToken = "783da7bbc18ce1af68b8f73344a6a50d";
22 |
23 | /**
24 | * Test of getStatusesForLoggedInUser method, of class DoubanShuoService.
25 | */
26 | public void testGetStatusesForLoggedInUser_String() throws Exception {
27 | System.out.println("getStatusesForLoggedInUser");
28 | DoubanShuoService instance = new DoubanShuoService();
29 | DoubanShuoStatusObj[] result = instance.getHomeTimelineForLoggedInUser(accessToken);
30 | for (DoubanShuoStatusObj obj : result) {
31 | System.out.println("obj id : " + obj.getId());
32 | System.out.println("obj.text : " + obj.getText());
33 | }
34 | assertTrue(result.length > 0);
35 | }
36 |
37 | /**
38 | * Test of getStatusesForLoggedInUser method, of class DoubanShuoService.
39 | */
40 | public void testGetStatusesForLoggedInUser_5args() throws Exception {
41 | System.out.println("getStatusesForLoggedInUser");
42 | Long sinceId = 998808639L;
43 | Long untilId = 998894357L;
44 | Integer count = 10;
45 | DoubanShuoCategory category = null;
46 | DoubanShuoService instance = new DoubanShuoService();
47 | DoubanShuoStatusObj[] result = instance.getHomeTimelineForLoggedInUser(accessToken, sinceId, untilId, count, category);
48 | System.out.println("length : " + result.length);
49 | assertEquals(result.length, 10);
50 | }
51 |
52 | /**
53 | * Test of getStatusesByUserId method, of class DoubanShuoService.
54 | */
55 | public void testGetStatusesByUserId_String() throws Exception {
56 | System.out.println("getStatusesByUserId");
57 | String uid = "xxx";
58 | DoubanShuoService instance = new DoubanShuoService();
59 | DoubanShuoStatusObj[] result = instance.getStatusesByUserId(uid);
60 | for (DoubanShuoStatusObj obj : result) {
61 | System.out.println("obj.text : " + obj.getText());
62 | }
63 | assertTrue(result.length > 0);
64 | }
65 |
66 | /**
67 | * Test of getStatusesByUserId method, of class DoubanShuoService.
68 | */
69 | public void testGetStatusesByUserId_3args() throws Exception {
70 | System.out.println("getStatusesByUserId");
71 | String uid = "xxx";
72 | Long sinceId = 998808639L;
73 | Long untilId = 998894357L;
74 | DoubanShuoService instance = new DoubanShuoService();
75 | DoubanShuoStatusObj[] result = instance.getStatusesByUserId(uid, sinceId, untilId);
76 | System.out.println("length : " + result.length);
77 | assertEquals(result.length, 20);
78 | }
79 |
80 | /**
81 | * Test of postNewStatus method, of class DoubanShuoService.
82 | *
83 | * Tested in playground
84 | */
85 | // public void testPostNewStatus() throws Exception {
86 | // System.out.println("postNewStatus");
87 | // String content = "Not again";
88 | // DoubanShuoAttachementObj att = null;
89 | // DoubanShuoService instance = new DoubanShuoService();
90 | // boolean expResult = false;
91 | // boolean result = instance.postNewStatus(content, att, accessToken);
92 | // assertEquals(expResult, result);
93 | // // TODO review the generated test code and remove the default call to fail.
94 | // fail("The test case is a prototype.");
95 | // }
96 |
97 | /**
98 | * Test of getUserInfoById method, of class DoubanShuoService.
99 | */
100 | public void testGetUserInfoById() throws Exception {
101 | System.out.println("getUserInfoById");
102 | String userId = "xxx";
103 | DoubanShuoService instance = new DoubanShuoService();
104 | DoubanShuoUserObj result = instance.getUserInfoById(userId);
105 | assertEquals(result.getScreenName(), "xxx");
106 | }
107 |
108 | /**
109 | * Test of getFollowingUserByUserId method, of class DoubanShuoService.
110 | *
111 | * Tested in playground
112 | */
113 | public void testGetFollowingUserByUserId() throws Exception {
114 | System.out.println("getFollowingUserByUserId");
115 | String userId = "xxx";
116 | DoubanShuoService instance = new DoubanShuoService();
117 | DoubanShuoUserObj[] result = instance.getFollowingUserByUserId(userId);
118 | for (DoubanShuoUserObj user : result) {
119 | System.out.println("user uid : " + user.getUid());
120 | System.out.println("user id : " + user.getId());
121 | System.out.println("user name : " + user.getScreenName());
122 | }
123 | }
124 |
125 | /**
126 | * Test of getFollowersByUserId method, of class DoubanShuoService.
127 | *
128 | * Tested in playground
129 | */
130 | public void testGetFollowersByUserId() throws Exception {
131 | System.out.println("getFollowersByUserId");
132 | String userId = "";
133 | DoubanShuoService instance = new DoubanShuoService();
134 | DoubanShuoUserObj[] expResult = null;
135 | DoubanShuoUserObj[] result = instance.getFollowersByUserId(userId);
136 | assertEquals(expResult, result);
137 | // TODO review the generated test code and remove the default call to fail.
138 | fail("The test case is a prototype.");
139 | }
140 |
141 | /**
142 | * Test of followUser method, of class DoubanShuoService.
143 | *
144 | * Tested in playground
145 | */
146 | public void testFollowUser() throws Exception {
147 | System.out.println("followUser");
148 | String targetId = "xxx";
149 | DoubanShuoService instance = new DoubanShuoService();
150 | boolean result = instance.followUser(targetId, DefaultConfigs.API_KEY, accessToken);
151 | assertTrue(result);
152 | }
153 |
154 | /**
155 | * Test of getRelationship method, of class DoubanShuoService.
156 | *
157 | * Tested in playground
158 | */
159 | public void testGetRelationship() throws Exception {
160 | System.out.println("getRelationship");
161 | String sourceId = "";
162 | String targetId = "";
163 | DoubanShuoService instance = new DoubanShuoService();
164 | DoubanShuoRelation expResult = null;
165 | DoubanShuoRelation result = instance.getRelationship(sourceId, targetId, DefaultConfigs.API_KEY);
166 | assertEquals(expResult, result);
167 | // TODO review the generated test code and remove the default call to fail.
168 | fail("The test case is a prototype.");
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/src/test/java/com/dongxuexidu/douban4j/service/DoubanUserServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.dongxuexidu.douban4j.service;
2 |
3 | import junit.framework.TestCase;
4 |
5 | import com.dongxuexidu.douban4j.model.user.DoubanUserFeedObj;
6 | import com.dongxuexidu.douban4j.model.user.DoubanUserObj;
7 | import com.dongxuexidu.douban4j.playground.PlayGround;
8 |
9 | /**
10 | *
11 | * @author Zhibo Wei
12 | */
13 | public class DoubanUserServiceTest extends TestCase {
14 |
15 | private String accessToken = "";
16 |
17 | @Override
18 | protected void setUp() throws Exception {
19 | super.setUp();
20 | if (accessToken == null) {
21 | this.accessToken = PlayGround.testAccessToken();
22 | }
23 | }
24 |
25 | /**
26 | * Test of getUserProfileByUid method, of class DoubanUserService.
27 | */
28 | public void testGetUserProfileByUid() throws Exception {
29 | System.out.println("getUserProfileByUid");
30 | String uid = "xxx";
31 | DoubanUserService instance = new DoubanUserService();
32 | DoubanUserObj result = instance.getUserProfileByUid(uid);
33 | assertEquals(result.getTitle(), "xxx");
34 | }
35 |
36 | /**
37 | * Test of getLoggedInUserProfile method, of class DoubanUserService.
38 | */
39 | public void testGetLoggedInUserProfile() throws Exception {
40 | System.out.println("getLoggedInUserProfile");
41 | if (accessToken == null) {
42 | accessToken = PlayGround.testAccessToken();
43 | }
44 | DoubanUserService instance = new DoubanUserService();
45 | DoubanUserObj result = instance.getLoggedInUserProfile(accessToken);
46 | assertEquals(result.getTitle(), "xxx");
47 | }
48 |
49 | /**
50 | * Test of searchUserProfile method, of class DoubanUserService.
51 | */
52 | public void testSearchUserProfile_String() throws Exception {
53 | System.out.println("searchUserProfile");
54 | String keyword = "xxx";
55 | DoubanUserService instance = new DoubanUserService();
56 | DoubanUserFeedObj result = instance.searchUserProfile(keyword);
57 | assertTrue(result.getUsers().size() > 0);
58 | }
59 |
60 | /**
61 | * Test of searchUserProfile method, of class DoubanUserService.
62 | */
63 | public void testSearchUserProfile_3args() throws Exception {
64 | System.out.println("searchUserProfile");
65 | String keyword = "douban";
66 | Integer startIndex = 0;
67 | Integer maxResultCount = 2;
68 | DoubanUserService instance = new DoubanUserService();
69 | DoubanUserFeedObj result = instance.searchUserProfile(keyword, startIndex, maxResultCount);
70 | //System.out.println("size : " + result.getUsers().size());
71 | assertTrue(result.getUsers().size() == 3); // This is the problem of their API, no my problem
72 | }
73 |
74 | /**
75 | * Test of getUsersFriendsList method, of class DoubanUserService.
76 | */
77 | public void testGetUsersFriendsList_String_String() throws Exception {
78 | System.out.println("getUsersFriendsList");
79 | String uid = "xxx";
80 | if (accessToken == null) {
81 | accessToken = PlayGround.testAccessToken();
82 | }
83 | DoubanUserService instance = new DoubanUserService();
84 | DoubanUserFeedObj result = instance.getUsersFriendsList(uid, accessToken);
85 | assertTrue(result.getUsers().size() > 0);
86 | }
87 |
88 | /**
89 | * Test of getUsersFriendsList method, of class DoubanUserService.
90 | */
91 | public void testGetUsersFriendsList_4args() throws Exception {
92 | System.out.println("getUsersFriendsList");
93 | String uid = "xxx";
94 | Integer startIndex = 0;
95 | Integer maxResultCount = 2;
96 | if (accessToken == null) {
97 | accessToken = PlayGround.testAccessToken();
98 | }
99 | DoubanUserService instance = new DoubanUserService();
100 | DoubanUserFeedObj result = instance.getUsersFriendsList(uid, startIndex, maxResultCount, accessToken);
101 | assertTrue(result.getUsers().size() == 2);
102 | }
103 |
104 | /**
105 | * Test of getUsersContactsList method, of class DoubanUserService.
106 | */
107 | public void testGetUsersContactsList_String() throws Exception {
108 | System.out.println("getUsersContactsList");
109 | String uid = "xxx";
110 | DoubanUserService instance = new DoubanUserService();
111 | DoubanUserFeedObj result = instance.getUsersContactsList(uid);
112 | assertTrue(result.getUsers().size() > 0);
113 | }
114 |
115 | /**
116 | * Test of getUsersContactsList method, of class DoubanUserService.
117 | */
118 | public void testGetUsersContactsList_3args() throws Exception {
119 | System.out.println("getUsersContactsList");
120 | String uid = "xxx";
121 | Integer startIndex = 0;
122 | Integer maxResultCount = 2;
123 | DoubanUserService instance = new DoubanUserService();
124 | DoubanUserFeedObj result = instance.getUsersContactsList(uid, startIndex, maxResultCount);
125 | assertTrue(result.getUsers().size() == 2);
126 | }
127 | }
128 |
--------------------------------------------------------------------------------