Skip to content

Commit f95fe31

Browse files
committed
Update the Kotlin wrapper
1 parent 4ab0159 commit f95fe31

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

native/kotlin/api/kotlin/src/integrationTest/kotlin/IntegrationTestHelpers.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import uniffi.wp_api.WpApiClientDelegate
77
import uniffi.wp_api.WpApiMiddlewarePipeline
88
import uniffi.wp_api.WpAuthenticationProvider
99
import uniffi.wp_api.WpErrorCode
10+
import uniffi.wp_api.ParsedUrl
1011
import uniffi.wp_mobile.MockPostService
12+
import uniffi.wp_mobile.SiteInfo
1113
import uniffi.wp_mobile.WpService
1214
import rs.wordpress.cache.kotlin.WordPressApiCache
1315

@@ -51,10 +53,15 @@ fun createTestServiceContext(): TestServiceContext {
5153
// Extract site URL by removing /wp-json suffix
5254
val siteUrl = apiRootUrl.removeSuffix("/wp-json")
5355

56+
val parsedSiteUrl = ParsedUrl.parse(siteUrl)
57+
val parsedApiRoot = ParsedUrl.parse(apiRootUrl)
58+
5459
// Create self-hosted service
55-
val service = WpService.selfHosted(
56-
siteUrl = siteUrl,
57-
apiRoot = apiRootUrl,
60+
val service = WpService(
61+
siteInfo = SiteInfo.SelfHosted(
62+
siteUrl = parsedSiteUrl,
63+
apiRoot = parsedApiRoot
64+
),
5865
delegate = WpApiClientDelegate(
5966
authProvider,
6067
requestExecutor = WpRequestExecutor(emptyList(), NetworkAvailabilityProvider { true }),
@@ -64,11 +71,12 @@ fun createTestServiceContext(): TestServiceContext {
6471
cache = wordPressApiCache.cache
6572
)
6673

67-
// Create mock post service with shared cache
74+
// Create mock post service with shared cache.
75+
// Use the parsed URL strings to ensure URL normalization matches the WpService's DbSite.
6876
val mockPostService = MockPostService(
6977
wordPressApiCache.cache,
70-
siteUrl,
71-
apiRootUrl
78+
parsedSiteUrl.url(),
79+
parsedApiRoot.url()
7280
)
7381

7482
return TestServiceContext(service, mockPostService)

native/kotlin/example/composeApp/src/androidMain/kotlin/rs/wordpress/example/ui/welcome/WelcomeActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import uniffi.wp_api.parseAuthorizationUrl
3232
import uniffi.wp_api.wordpressComOauth2Configuration
3333
import uniffi.wp_mobile.Account
3434
import uniffi.wp_mobile.AccountRepository
35-
import uniffi.wp_mobile.wordpressComSiteApiRoot
3635

3736
class WelcomeActivity : ComponentActivity() {
3837
private val accountRepository: AccountRepository by inject()
@@ -221,7 +220,7 @@ class WelcomeActivity : ComponentActivity() {
221220
domain = siteUrl,
222221
username = siteUrl,
223222
password = tokenResponse.accessToken,
224-
siteApiRoot = wordpressComSiteApiRoot(blogId)
223+
siteApiRoot = "https://public-api.wordpress.com/wp/v2/sites/$blogId"
225224
)
226225
)
227226
siteSpecificOAuthState = null

native/kotlin/example/composeApp/src/commonMain/kotlin/rs/wordpress/example/shared/di/AppModule.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import uniffi.wp_api.WpAuthenticationProvider
1616
import uniffi.wp_api.wpAuthenticationFromUsernameAndPassword
1717
import uniffi.wp_mobile.Account
1818
import uniffi.wp_mobile.AccountRepository
19+
import uniffi.wp_api.ParsedUrl
20+
import uniffi.wp_mobile.SiteInfo
1921
import uniffi.wp_mobile.WpService
2022
import java.io.File
2123
import java.net.URI
@@ -47,9 +49,11 @@ fun createWpService(
4749
} else {
4850
wpAuthenticationFromUsernameAndPassword(account.username, account.password)
4951
}
50-
return WpService.selfHosted(
51-
siteUrl = account.domain,
52-
apiRoot = account.siteApiRoot,
52+
return WpService(
53+
siteInfo = SiteInfo.SelfHosted(
54+
siteUrl = ParsedUrl.parse(account.domain),
55+
apiRoot = ParsedUrl.parse(account.siteApiRoot)
56+
),
5357
delegate = WpApiClientDelegate(
5458
WpAuthenticationProvider.staticWithAuth(auth),
5559
requestExecutor = WpRequestExecutor(emptyList(), networkAvailabilityProvider),

0 commit comments

Comments
 (0)