Skip to content

Commit

Permalink
Merge branch 'master' into add-integration-tests-for-edit-status-and-…
Browse files Browse the repository at this point in the history
…edit-poll
  • Loading branch information
andregasser authored Apr 6, 2023
2 parents 9c3e781 + 83a2548 commit efade7d
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RxAppMethods(client: MastodonClient) {
@JvmOverloads
fun createApp(
clientName: String,
redirectUris: String = "urn:ietf:wg:oauth:2.0:oob",
redirectUris: String,
scope: Scope = Scope(Scope.Name.ALL),
website: String? = null
): Single<Application> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RxOAuthMethods(client: MastodonClient) {
fun getUserAccessTokenWithAuthorizationCodeGrant(
clientId: String,
clientSecret: String,
redirectUri: String = "urn:ietf:wg:oauth:2.0:oob",
redirectUri: String,
code: String
): Single<Token> {
return Single.create {
Expand All @@ -35,7 +35,7 @@ class RxOAuthMethods(client: MastodonClient) {
clientId: String,
clientSecret: String,
scope: Scope = Scope(Scope.Name.READ),
redirectUri: String = "urn:ietf:wg:oauth:2.0:oob",
redirectUri: String,
username: String,
password: String
): Single<Token> {
Expand Down
4 changes: 0 additions & 4 deletions bigbone/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ dependencies {
api libs.okhttp
api libs.gson
implementation libs.kotlin.jdk8

testImplementation libs.junit.jupiter.api
testImplementation libs.kluent
testImplementation libs.mockk
testImplementation libs.mockk.dsl
integrationTestImplementation libs.junit.jupiter.api
integrationTestImplementation libs.junit.jupiter.engine
integrationTestImplementation libs.junit.platform.suite.engine
integrationTestImplementation 'ch.qos.logback:logback-core:1.4.6'
integrationTestImplementation 'ch.qos.logback:logback-classic:1.4.6'
integrationTestImplementation 'org.slf4j:slf4j-api:2.0.7'
}

tasks.register('integrationTest', Test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object TestHelpers {
return client.oauth.getAccessTokenWithClientCredentialsGrant(
clientId = application.clientId!!,
clientSecret = application.clientSecret!!,
redirectUri = TestConstants.REDIRECT_URI,
scope = Scope(Scope.Name.ALL)
).execute()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class V300StatusMethodsIntegrationTest {
return client.oauth.getAccessTokenWithClientCredentialsGrant(
clientId = application.clientId!!,
clientSecret = application.clientSecret!!,
redirectUri = TestConstants.REDIRECT_URI,
scope = Scope(Scope.Name.ALL)
).execute()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class V402StatusMethodsIntegrationTest {
return client.oauth.getAccessTokenWithClientCredentialsGrant(
clientId = application.clientId!!,
clientSecret = application.clientSecret!!,
redirectUri = TestConstants.REDIRECT_URI,
scope = Scope(Scope.Name.ALL)
).execute()
}
Expand Down
6 changes: 3 additions & 3 deletions bigbone/src/main/kotlin/social/bigbone/api/entity/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ data class Account(
* How many statuses are attached to this account.
*/
@SerializedName("statuses_count")
val statusesCount: Int = 0,
val statusesCount: Long = 0,

/**
* The reported followers of this profile.
*/
@SerializedName("followers_count")
val followersCount: Int = 0,
val followersCount: Long = 0,

/**
* The reported follows of this profile.
*/
@SerializedName("following_count")
val followingCount: Int = 0
val followingCount: Long = 0
) {
/**
* Specifies a name-value pair as used in [fields] of the [Account] entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ data class CustomEmoji(
* Whether this Emoji should be visible in the picker or unlisted.
*/
@SerializedName("visible_in_picker")
val visibleInPicker: Boolean = true
val visibleInPicker: Boolean = true,

/**
* Used for sorting custom emoji in the picker.
*/
@SerializedName("category")
val category: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ data class InstanceStats(
* Total users on this instance.
*/
@SerializedName("user_count")
val userCount: Int = 0,
val userCount: Long = 0,

/**
* Total statuses on this instance.
*/
@SerializedName("status_count")
val statusCount: Int = 0,
val statusCount: Long = 0,

/**
* Total domains discovered by this instance.
*/
@SerializedName("domain_count")
val domainCount: Int = 0
val domainCount: Long = 0
)
6 changes: 3 additions & 3 deletions bigbone/src/main/kotlin/social/bigbone/api/entity/Poll.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ data class Poll(
* How many votes have been received.
*/
@SerializedName("votes_count")
val votesCount: Int = 0,
val votesCount: Long = 0,

/**
* How many unique accounts have voted on a multiple-choice poll; integer, or null if [multiple] is false.
*/
@SerializedName("voters_count")
val votersCount: Int? = null,
val votersCount: Long? = null,

/**
* Possible answers for the poll.
Expand Down Expand Up @@ -83,6 +83,6 @@ data class Poll(
* The total number of received votes for this option; integer, or null if results are not published yet.
*/
@SerializedName("votes_count")
val votesCount: Int? = null
val votesCount: Long? = null
)
}
6 changes: 3 additions & 3 deletions bigbone/src/main/kotlin/social/bigbone/api/entity/Status.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ data class Status(
* How many boosts this status has received.
*/
@SerializedName("reblogs_count")
val reblogsCount: Int = 0,
val reblogsCount: Long = 0,

/**
* How many favourites this status has received.
*/
@SerializedName("favourites_count")
val favouritesCount: Int = 0,
val favouritesCount: Long = 0,

/**
* How many replies this status has received.
*/
@SerializedName("replies_count")
val repliesCount: Int = 0,
val repliesCount: Long = 0,

/**
* A link to the status’s HTML representation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ class AppMethods(private val client: MastodonClient) {
/**
* Create a new application to obtain OAuth2 credentials.
* @param clientName A name for your application
* @param redirectUris Where the user should be redirected after authorization. Defaults to "urn:ietf:wg:oauth:2.0:oob",
* which will display the authorization code to the user instead of redirecting to a web page.
* @param redirectUris Where the user should be redirected after authorization.
* @param scope Space separated list of scopes. Defaults to all scopes.
* @param website A URL to the homepage of your app, defaults to null.
* @see <a href="https://docs.joinmastodon.org/methods/apps/#create">Mastodon apps API methods #create</a>
*/
@JvmOverloads
fun createApp(
clientName: String,
redirectUris: String = "urn:ietf:wg:oauth:2.0:oob",
redirectUris: String,
scope: Scope = Scope(Scope.Name.ALL),
website: String? = null
): MastodonRequest<Application> {
Expand Down
27 changes: 9 additions & 18 deletions bigbone/src/main/kotlin/social/bigbone/api/method/OAuthMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ class OAuthMethods(private val client: MastodonClient) {
/**
* Returns a URL that can be used to display an authorization form to the user. If approved,
* it will create and return an authorization code, then redirect to the desired redirectUri,
* or show the authorization code if urn:ietf:wg:oauth:2.0:oob was requested.
* or show the authorization code if redirectUri is "urn:ietf:wg:oauth:2.0:oob".
* The authorization code can be used while requesting a token to obtain access to user-level methods.
* @param clientId The client ID, obtained during app registration.
* @param scope List of requested OAuth scopes, separated by spaces. Must be a subset of scopes declared during app registration.
* @param redirectUri Set a URI to redirect the user to. Defaults to "urn:ietf:wg:oauth:2.0:oob",
* which will display the authorization code to the user instead of redirecting to a web page.
* Must match one of the redirect_uris declared during app registration.
* @param redirectUri Set a URI to redirect the user to. Must match one of the redirect_uris declared during app registration.
* @see <a href="https://docs.joinmastodon.org/methods/oauth/#authorize">Mastodon oauth API methods #authorize</a>
*/
@JvmOverloads
fun getOAuthUrl(clientId: String, scope: Scope, redirectUri: String = "urn:ietf:wg:oauth:2.0:oob"): String {
fun getOAuthUrl(clientId: String, scope: Scope, redirectUri: String): String {
val endpoint = "oauth/authorize"
val params = Parameters()
.append("client_id", clientId)
Expand All @@ -39,17 +36,14 @@ class OAuthMethods(private val client: MastodonClient) {
* Obtain a user access token using OAuth 2 authorization code grant type. To be used during API calls that are not public.
* @param clientId The client ID, obtained during app registration.
* @param clientSecret The client secret, obtained during app registration.
* @param redirectUri Set a URI to redirect the user to. Defaults to "urn:ietf:wg:oauth:2.0:oob",
* which will display the authorization code to the user instead of redirecting to a web page.
* Must match one of the redirect_uris declared during app registration.
* @param redirectUri Set a URI to redirect the user to. Must match one of the redirect_uris declared during app registration.
* @param code A user authorization code, obtained via the URL received from getOAuthUrl()
* @see <a href="https://docs.joinmastodon.org/methods/oauth/#token">Mastodon oauth API methods #token</a>
*/
@JvmOverloads
fun getUserAccessTokenWithAuthorizationCodeGrant(
clientId: String,
clientSecret: String,
redirectUri: String = "urn:ietf:wg:oauth:2.0:oob",
redirectUri: String,
code: String
): MastodonRequest<Token> {
return client.getMastodonRequest(
Expand All @@ -69,9 +63,7 @@ class OAuthMethods(private val client: MastodonClient) {
* Obtain an access token using OAuth 2 client credentials grant type. To be used during API calls that are not public.
* @param clientId The client ID, obtained during app registration.
* @param clientSecret The client secret, obtained during app registration.
* @param redirectUri Set a URI to redirect the user to. Defaults to "urn:ietf:wg:oauth:2.0:oob",
* which will display the authorization code to the user instead of redirecting to a web page.
* Must match one of the redirect_uris declared during app registration.
* @param redirectUri Set a URI to redirect the user to. Must match one of the redirect_uris declared during app registration.
* @param scope Requested OAuth scopes. Must be a subset of scopes declared during app registration.
* If not provided, defaults to read.
* @see <a href="https://docs.joinmastodon.org/methods/oauth/#token">Mastodon oauth API methods #token</a>
Expand All @@ -81,7 +73,7 @@ class OAuthMethods(private val client: MastodonClient) {
fun getAccessTokenWithClientCredentialsGrant(
clientId: String,
clientSecret: String,
redirectUri: String = "urn:ietf:wg:oauth:2.0:oob",
redirectUri: String,
scope: Scope? = null
): MastodonRequest<Token> {
return client.getMastodonRequest(
Expand All @@ -105,8 +97,7 @@ class OAuthMethods(private val client: MastodonClient) {
* @param clientId The client ID, obtained during app registration.
* @param clientSecret The client secret, obtained during app registration.
* @param scope Requested OAuth scopes
* @param redirectUri Set a URI to redirect the user to. Defaults to "urn:ietf:wg:oauth:2.0:oob",
* which will display the authorization code to the user instead of redirecting to a web page.
* @param redirectUri Set a URI to redirect the user to.
* @param username The Mastodon account username.
* @param password The Mastodon account password.
* @see <a href="https://docs.joinmastodon.org/methods/oauth/#token">Mastodon oauth API methods #token</a>
Expand All @@ -116,7 +107,7 @@ class OAuthMethods(private val client: MastodonClient) {
clientId: String,
clientSecret: String,
scope: Scope = Scope(Scope.Name.READ),
redirectUri: String = "urn:ietf:wg:oauth:2.0:oob",
redirectUri: String,
username: String,
password: String
): MastodonRequest<Token> {
Expand Down
5 changes: 5 additions & 0 deletions bigbone/src/test/kotlin/social/bigbone/TestConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package social.bigbone

object TestConstants {
const val REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.amshove.kluent.shouldBeEqualTo
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import social.bigbone.MastodonClient
import social.bigbone.TestConstants
import social.bigbone.api.Scope
import social.bigbone.api.exception.BigBoneRequestException
import social.bigbone.testtool.MockClient
Expand All @@ -17,7 +18,9 @@ class AppMethodsTest {

val appMethods = AppMethods(client)
val application = appMethods.createApp(
clientName = "bigbone-sample-app", scope = Scope(Scope.Name.ALL)
clientName = "bigbone-sample-app",
redirectUris = TestConstants.REDIRECT_URI,
scope = Scope(Scope.Name.ALL)
).execute()

application.clientId shouldBeEqualTo "client id"
Expand All @@ -30,7 +33,9 @@ class AppMethodsTest {
val client = MockClient.ioException()
val appMethods = AppMethods(client)
appMethods.createApp(
clientName = "bigbone-sample-app", scope = Scope(Scope.Name.ALL)
clientName = "bigbone-sample-app",
redirectUris = TestConstants.REDIRECT_URI,
scope = Scope(Scope.Name.ALL)
).execute()
}
}
Expand Down
Loading

0 comments on commit efade7d

Please sign in to comment.