Skip to content

Commit

Permalink
Fetch demo user from Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzkocer committed Jul 9, 2024
1 parent 80956df commit ee0e885
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ repositories {
includeGroup "org.wordpress.fluxc"
includeGroup "org.wordpress.wellsql"
includeGroup "org.wordpress.gutenberg-mobile"
includeGroup "rs.wordpress.api"
includeGroupByRegex "org.wordpress.react-native-libraries.*"
includeGroup "com.automattic"
includeGroup "com.automattic.tracks"
Expand Down Expand Up @@ -350,6 +351,10 @@ static def addBuildConfigFieldsFromPrefixedProperties(variant, properties, prefi
}

dependencies {
implementation('rs.wordpress.api:android:0.1-rc-9') {
exclude group: "net.java.dev.jna"
}
implementation 'net.java.dev.jna:jna:5.13.0@aar'
implementation 'androidx.webkit:webkit:1.11.0'
implementation "androidx.navigation:navigation-compose:$androidxComposeNavigationVersion"
compileOnly project(path: ':libs:annotations')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.wordpress.android.ui.posts.PostListType.TRASHED
import org.wordpress.android.ui.prefs.AppPrefsWrapper
import org.wordpress.android.ui.uploads.UploadActionUseCase
import org.wordpress.android.ui.uploads.UploadStarter
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.NetworkUtilsWrapper
Expand All @@ -54,6 +55,9 @@ import org.wordpress.android.viewmodel.helpers.ToastMessageHolder
import org.wordpress.android.viewmodel.posts.PostFetcher
import org.wordpress.android.viewmodel.posts.PostListItemIdentifier.LocalPostId
import org.wordpress.android.viewmodel.posts.PostListViewModelConnector
import rs.wordpress.api.kotlin.WpApiClient
import rs.wordpress.api.kotlin.WpRequestSuccess
import uniffi.wp_api.wpAuthenticationFromUsernameAndPassword
import javax.inject.Inject
import javax.inject.Named
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -305,6 +309,33 @@ class PostListMainViewModel @Inject constructor(
}

isStarted = true

fetchDemoUserFromRust()
}

private fun fetchDemoUserFromRust() {
// This is an empty test site that'll be destroyed in a few days.
val siteUrl = "https://loudly-special.jurassic.ninja/"
val authentication = wpAuthenticationFromUsernameAndPassword(
username = "demo", password = "50uB 6ivM b7OC vc1K GXjh zZsI"
)
val client = WpApiClient(siteUrl, authentication)
launch {
val demoUser = client.request { requestBuilder ->
requestBuilder.users().retrieveMeWithEditContext()
}
when (demoUser) {
is WpRequestSuccess -> {
withContext(mainDispatcher) {
_snackBarMessage.value =
SnackbarMessageHolder(
message = UiString.UiStringText("Demo user's name: ${demoUser.data.name}")
)
}
}
else -> {}
}
}
}

override fun onCleared() {
Expand Down

0 comments on commit ee0e885

Please sign in to comment.