Skip to content

Commit

Permalink
feat: add verified account field to UserV2 (#159)
Browse files Browse the repository at this point in the history
* feat_add_verified

* cleaning with terminary

* cleaning doc

* add unit test
  • Loading branch information
redouane59 authored Mar 11, 2021
1 parent 51127f5 commit 20537eb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,17 @@ public interface User {
boolean isProtectedAccount();

/**
* Know if the user is following the owner account. Warning: this is not not support by all endpoints.
* Get if the user is following the owner account. Warning: this is not not support by all endpoints.
*
* @return true if the user is following the owner account, else false
*/
boolean isFollowing();

/**
* Get if the user has a verified account. Warning: this is not not support by all endpoints.
*
* @return true if the user account is certified
*/
boolean isVerified();

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public Tweet getPinnedTweet() {
return null;
}

@Override
public boolean isVerified() {
LOGGER.debug("UnsupportedOperation");
return false;
}

public LocalDateTime getLastUpdate() {
return ConverterHelper.getDateFromTwitterString(this.lastUpdate);
}
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/com/github/redouane59/twitter/dto/user/UserV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,17 @@ public Tweet getPinnedTweet() {

@Override
public String getId() {
if (this.data == null) {
return null;
}
return this.data.getId();
return this.data == null ? null : this.data.getId();
}

@Override
public String getName() {
if (this.data == null) {
return null;
}
return this.data.getName();
return this.data == null ? null : this.data.getName();
}

@Override
public String getDisplayedName() {
if (this.data == null) {
return null;
}
return this.data.getDisplayedName();
return this.data == null ? null : this.data.getDisplayedName();
}

@Override
Expand Down Expand Up @@ -157,6 +148,11 @@ public boolean isFollowing() {
return this.data.isFollowing();
}

@Override
public boolean isVerified() {
return this.data == null ? false : this.data.verified;
}

@Override
public Tweet getPinnedTweet() {
if (this.includes.getTweets().length < 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public void testGetUserDateOfCreation() {
assertEquals(ConverterHelper.getDateFromTwitterDateV2("2009-11-23T17:53:15.000Z"), userV2.getDateOfCreation());
}

@Test
public void testIsVerified() {
assertTrue(userV2.isVerified());
}

@Test
public void testGetUserPinnedTweet() {
Tweet pinnedTweet = userV2.getPinnedTweet();
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/tests/user_example_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"url": "",
"username": "RedTheOne",
"verified": false
"verified": true
},
"includes": {
"tweets": [
Expand Down

0 comments on commit 20537eb

Please sign in to comment.