-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better support for querying suspended accounts
- Loading branch information
Showing
6 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
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,27 @@ | ||
package net.dean.jraw.models; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* The main function of an AccountQuery is to store the status of an account. If an account exists and is not suspended, | ||
* then the {@link Account} object can be used normally. | ||
*/ | ||
@AutoValue | ||
public abstract class AccountQuery { | ||
/** The reddit username being queried */ | ||
public abstract String getName(); | ||
|
||
public abstract AccountStatus getStatus(); | ||
|
||
/** The account data. Only non-null when the status is {@link AccountStatus#EXISTS}. */ | ||
@Nullable public abstract Account getAccount(); | ||
|
||
public static AccountQuery create(String name, AccountStatus status) { | ||
return create(name, status, null); | ||
} | ||
|
||
public static AccountQuery create(String name, AccountStatus status, @Nullable Account data) { | ||
return new AutoValue_AccountQuery(name, status, data); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
lib/src/main/kotlin/net/dean/jraw/SuspendedAccountException.kt
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,7 @@ | ||
package net.dean.jraw | ||
|
||
/** | ||
* Thrown when directly querying a user who is suspended | ||
*/ | ||
class SuspendedAccountException(val name: String, cause: Throwable? = null) : | ||
Exception("Account '$name' is suspended", cause) |
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,12 @@ | ||
package net.dean.jraw.models | ||
|
||
enum class AccountStatus { | ||
/** The account exists and is not suspended */ | ||
EXISTS, | ||
|
||
/** An account by the requested name has never been created */ | ||
NON_EXISTENT, | ||
|
||
/** The account exists and has been suspended reddit-wide */ | ||
SUSPENDED | ||
} |
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
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
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