forked from Orange-OpenSource/spring-social-weibo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
602 additions
and
87 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
src/main/java/org/springframework/social/weibo/api/Favorite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright 2011 France Telecom R&D Beijing Co., Ltd 北京法国电信研发中心有限公司 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.weibo.api; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
public class Favorite { | ||
|
||
public static class Tag { | ||
private long id; | ||
private String value; | ||
private int count; | ||
|
||
/** | ||
* @return the id | ||
*/ | ||
public long getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* @param id | ||
* the id to set | ||
*/ | ||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* @return the value | ||
*/ | ||
public String getValue() { | ||
return value; | ||
} | ||
|
||
/** | ||
* @param value | ||
* the value to set | ||
*/ | ||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* @return the count | ||
*/ | ||
public int getCount() { | ||
return count; | ||
} | ||
|
||
/** | ||
* @param count | ||
* the count to set | ||
*/ | ||
public void setCount(int count) { | ||
this.count = count; | ||
} | ||
} | ||
|
||
private Status status; | ||
private List<Tag> tags; | ||
private Date favoritedTime; | ||
|
||
/** | ||
* @return the status | ||
*/ | ||
public Status getStatus() { | ||
return status; | ||
} | ||
|
||
/** | ||
* @param status | ||
* the status to set | ||
*/ | ||
public void setStatus(Status status) { | ||
this.status = status; | ||
} | ||
|
||
/** | ||
* @return the tags | ||
*/ | ||
public List<Tag> getTags() { | ||
return tags; | ||
} | ||
|
||
/** | ||
* @param tags | ||
* the tags to set | ||
*/ | ||
public void setTags(List<Tag> tags) { | ||
this.tags = tags; | ||
} | ||
|
||
/** | ||
* @return the favoritedTime | ||
*/ | ||
public Date getFavoritedTime() { | ||
return favoritedTime; | ||
} | ||
|
||
/** | ||
* @param favoritedTime | ||
* the favoritedTime to set | ||
*/ | ||
public void setFavoritedTime(Date favoritedTime) { | ||
this.favoritedTime = favoritedTime; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/springframework/social/weibo/api/FavoriteOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2011 France Telecom R&D Beijing Co., Ltd 北京法国电信研发中心有限公司 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.weibo.api; | ||
|
||
import org.springframework.social.weibo.api.Favorite.Tag; | ||
|
||
public interface FavoriteOperations { | ||
|
||
Favorite getFavorite(long id); | ||
|
||
CursoredList<Favorite> getFavorites(); | ||
|
||
CursoredList<Favorite> getFavorites(int pageSize, int pageNumber); | ||
|
||
CursoredList<Tag> getTags(); | ||
|
||
CursoredList<Tag> getTags(int pageSize, int pageNumber); | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/org/springframework/social/weibo/api/impl/FavoriteTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2011 France Telecom R&D Beijing Co., Ltd 北京法国电信研发中心有限公司 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.weibo.api.impl; | ||
|
||
import org.codehaus.jackson.JsonNode; | ||
import org.codehaus.jackson.map.ObjectMapper; | ||
import org.springframework.social.weibo.api.CursoredList; | ||
import org.springframework.social.weibo.api.Favorite; | ||
import org.springframework.social.weibo.api.Favorite.Tag; | ||
import org.springframework.social.weibo.api.FavoriteOperations; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
public class FavoriteTemplate extends AbstractWeiboOperations implements | ||
FavoriteOperations { | ||
|
||
protected FavoriteTemplate(ObjectMapper objectMapper, | ||
RestTemplate restTemplate, boolean isAuthorized) { | ||
super(objectMapper, restTemplate, isAuthorized); | ||
} | ||
|
||
@Override | ||
public CursoredList<Favorite> getFavorites() { | ||
requireAuthorization(); | ||
JsonNode jsonNode = restTemplate.getForObject( | ||
buildUri("favorites.json"), JsonNode.class); | ||
return deserializeCursoredList(jsonNode, Favorite.class, "favorites"); | ||
} | ||
|
||
@Override | ||
public CursoredList<Favorite> getFavorites(int pageSize, int pageNumber) { | ||
requireAuthorization(); | ||
JsonNode jsonNode = restTemplate | ||
.getForObject( | ||
uriBuilder("favorites.json") | ||
.queryParam("count", String.valueOf(pageSize)) | ||
.queryParam("page", String.valueOf(pageNumber)) | ||
.build(), JsonNode.class); | ||
return deserializeCursoredList(jsonNode, Favorite.class, "favorites"); | ||
} | ||
|
||
@Override | ||
public Favorite getFavorite(long id) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public CursoredList<Tag> getTags() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public CursoredList<Tag> getTags(int pageSize, int pageNumber) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/org/springframework/social/weibo/api/impl/json/FavoriteMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2011 France Telecom R&D Beijing Co., Ltd 北京法国电信研发中心有限公司 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.weibo.api.impl.json; | ||
|
||
import java.util.Date; | ||
|
||
import org.codehaus.jackson.annotate.JsonIgnoreProperties; | ||
import org.codehaus.jackson.annotate.JsonProperty; | ||
import org.codehaus.jackson.map.annotate.JsonDeserialize; | ||
import org.springframework.social.weibo.api.Status; | ||
|
||
/** | ||
* Annotated mixin to add Jackson annotations to Favorite. | ||
* | ||
* @author edva8332 | ||
*/ | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
abstract class FavoriteMixin { | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
abstract static class TagMixin { | ||
long id; | ||
@JsonProperty("tag") | ||
String value; | ||
int count; | ||
} | ||
|
||
@JsonProperty("status") | ||
Status status; | ||
@JsonProperty("favorited_time") | ||
@JsonDeserialize(using = TimelineDateDeserializer.class) | ||
Date favoritedTime; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/test/java/org/springframework/social/weibo/api/impl/FavoriteTemplateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2011 France Telecom R&D Beijing Co., Ltd 北京法国电信研发中心有限公司 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.weibo.api.impl; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.springframework.http.HttpMethod.GET; | ||
import static org.springframework.social.test.client.RequestMatchers.header; | ||
import static org.springframework.social.test.client.RequestMatchers.method; | ||
import static org.springframework.social.test.client.RequestMatchers.requestTo; | ||
import static org.springframework.social.test.client.ResponseCreators.withResponse; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
import org.springframework.social.weibo.api.CursoredList; | ||
import org.springframework.social.weibo.api.Favorite; | ||
import org.springframework.social.weibo.api.Favorite.Tag; | ||
import org.springframework.social.weibo.matcher.StatusMatcher; | ||
|
||
public class FavoriteTemplateTest extends AbstractWeiboOperationsTest { | ||
|
||
private FavoriteTemplate favoriteTemplate; | ||
|
||
@Test | ||
public void testGetFavorites() { | ||
mockServer | ||
.expect(requestTo("https://api.weibo.com/2/favorites.json")) | ||
.andExpect(method(GET)) | ||
.andExpect(header("Authorization", "OAuth2 accessToken")) | ||
.andRespond( | ||
withResponse(jsonResource("cursoredFavorites"), | ||
responseHeaders)); | ||
CursoredList<Favorite> cursoredList = favoriteTemplate.getFavorites(); | ||
assertEquals(16, cursoredList.getTotalNumber()); | ||
assertEquals(2, cursoredList.size()); | ||
Favorite firstFavorite = cursoredList.iterator().next(); | ||
List<Tag> tags = firstFavorite.getTags(); | ||
assertEquals(2, tags.size()); | ||
Tag firstTag = tags.iterator().next(); | ||
verifyTag(firstTag); | ||
StatusMatcher.verifyStatus(firstFavorite.getStatus()); | ||
} | ||
|
||
@Test | ||
public void testGetFavoritesIntInt() { | ||
mockServer | ||
.expect(requestTo("https://api.weibo.com/2/favorites.json?count=20&page=5")) | ||
.andExpect(method(GET)) | ||
.andExpect(header("Authorization", "OAuth2 accessToken")) | ||
.andRespond( | ||
withResponse(jsonResource("cursoredFavorites"), | ||
responseHeaders)); | ||
CursoredList<Favorite> cursoredList = favoriteTemplate.getFavorites(20, | ||
5); | ||
assertEquals(16, cursoredList.getTotalNumber()); | ||
assertEquals(2, cursoredList.size()); | ||
Favorite firstFavorite = cursoredList.iterator().next(); | ||
List<Tag> tags = firstFavorite.getTags(); | ||
assertEquals(2, tags.size()); | ||
Tag firstTag = tags.iterator().next(); | ||
verifyTag(firstTag); | ||
StatusMatcher.verifyStatus(firstFavorite.getStatus()); | ||
} | ||
|
||
private void verifyTag(Tag firstTag) { | ||
assertEquals(23, firstTag.getId()); | ||
assertEquals("80后", firstTag.getValue()); | ||
assertEquals(25369, firstTag.getCount()); | ||
} | ||
|
||
@Override | ||
public void setUp() { | ||
favoriteTemplate = new FavoriteTemplate(getObjectMapper(), | ||
getRestTemplate(), true); | ||
} | ||
|
||
} |
Oops, something went wrong.