Skip to content

Commit 9722816

Browse files
committed
Added relationship container
1 parent 135adea commit 9722816

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.springframework.social.instagram.api.impl;
2+
3+
import org.codehaus.jackson.map.annotate.JsonDeserialize;
4+
import org.springframework.social.instagram.api.Relationship;
5+
6+
@JsonDeserialize(using=RelationshipContainerDeserializer.class)
7+
public class RelationshipContainer {
8+
9+
private Relationship relationship;
10+
11+
public RelationshipContainer(Relationship relationship) {
12+
this.relationship = relationship;
13+
}
14+
15+
public Relationship getRelationship() {
16+
return relationship;
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.springframework.social.instagram.api.impl;
2+
3+
import java.io.IOException;
4+
5+
import org.codehaus.jackson.JsonParser;
6+
import org.codehaus.jackson.JsonProcessingException;
7+
import org.codehaus.jackson.map.DeserializationContext;
8+
import org.springframework.social.instagram.api.Relationship;
9+
10+
public class RelationshipContainerDeserializer extends AbstractInstagramDeserializer<RelationshipContainer> {
11+
12+
@Override public RelationshipContainer deserialize(JsonParser jp, DeserializationContext ctxt)
13+
throws IOException, JsonProcessingException {
14+
return deserializeResponseObject(jp, RelationshipContainer.class, Relationship.class);
15+
}
16+
}

spring-social-instagram/src/main/java/org/springframework/social/instagram/api/impl/UserTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public List<InstagramProfile> getRequestedBy() {
7474

7575
public Relationship getRelationship(long userId) {
7676
requireUserAuthorization();
77-
return get(buildUri(USERS_ENDPOINT + Long.toString(userId) + "/relationship/"), Relationship.class);
77+
return get(buildUri(USERS_ENDPOINT + Long.toString(userId) + "/relationship/"), RelationshipContainer.class).getRelationship();
7878
}
7979

8080
public void followUser(long userId) {

spring-social-instagram/src/test/java/org/springframework/social/instagram/api/impl/UserTemplateTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.springframework.social.instagram.api.impl;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
46
import static org.springframework.http.HttpMethod.GET;
57
import static org.springframework.http.HttpMethod.POST;
68
import static org.springframework.social.test.client.RequestMatchers.body;
@@ -16,7 +18,6 @@
1618
import org.springframework.social.instagram.api.PagedMediaList;
1719
import org.springframework.social.instagram.api.Relationship;
1820

19-
@SuppressWarnings("unused")
2021
public class UserTemplateTest extends AbstractInstagramApiTest {
2122

2223
@Test
@@ -70,6 +71,7 @@ public void getFollowedBy() {
7071
.andRespond(withResponse(new ClassPathResource("testdata/user-list.json", getClass()), responseHeaders));
7172

7273
List<InstagramProfile> follows = instagram.userOperations().getFollowedBy(12345);
74+
assertTrue(follows.size() > 0);
7375
mockServer.verify();
7476
}
7577

@@ -80,6 +82,7 @@ public void getFollows() {
8082
.andRespond(withResponse(new ClassPathResource("testdata/user-list.json", getClass()), responseHeaders));
8183

8284
List<InstagramProfile> follows = instagram.userOperations().getFollows(12345);
85+
assertTrue(follows.size() > 0);
8386
mockServer.verify();
8487
}
8588

@@ -90,6 +93,7 @@ public void getRequestedBy() {
9093
.andRespond(withResponse(new ClassPathResource("testdata/user-list.json", getClass()), responseHeaders));
9194

9295
List<InstagramProfile> follows = instagram.userOperations().getRequestedBy();
96+
assertTrue(follows.size() > 0);
9397
mockServer.verify();
9498
}
9599

@@ -100,6 +104,8 @@ public void getRelationship() {
100104
.andRespond(withResponse(new ClassPathResource("testdata/relationship.json", getClass()), responseHeaders));
101105

102106
Relationship relationship = instagram.userOperations().getRelationship(12345);
107+
assertNotNull(relationship.getIncomingStatus());
108+
assertNotNull(relationship.getOutgoingStatus());
103109
mockServer.verify();
104110
}
105111

0 commit comments

Comments
 (0)