@@ -88,6 +88,7 @@ import org.wordpress.android.fluxc.store.SiteStore.SuggestDomainErrorType.EMPTY_
8888import org.wordpress.android.fluxc.store.SiteStore.SuggestDomainsResponsePayload
8989import org.wordpress.android.fluxc.store.SiteStore.UserRolesError
9090import org.wordpress.android.fluxc.store.SiteStore.UserRolesErrorType
91+ import org.wordpress.android.fluxc.tools.CoroutineEngine
9192import org.wordpress.android.fluxc.utils.SiteUtils
9293import org.wordpress.android.util.AppLog
9394import org.wordpress.android.util.AppLog.T.API
@@ -110,6 +111,7 @@ class SiteRestClient @Inject constructor(
110111 @Named(" regular" ) requestQueue : RequestQueue ? ,
111112 private val appSecrets : AppSecrets ,
112113 private val wpComGsonRequestBuilder : WPComGsonRequestBuilder ,
114+ private val coroutineEngine : CoroutineEngine ,
113115 accessToken : AccessToken ? ,
114116 userAgent : UserAgent ?
115117) : BaseWPComRestClient(appContext, dispatcher, requestQueue, accessToken, userAgent) {
@@ -673,34 +675,58 @@ class SiteRestClient @Inject constructor(
673675 }
674676
675677 // Unauthenticated network calls
676- @Suppress(" SwallowedException" )
677678 fun fetchConnectSiteInfo (siteUrl : String ) {
679+ coroutineEngine.launch(AppLog .T .API , this , " fetchConnectSiteInfo" ) {
680+ fetchConnectSiteInfoSync(siteUrl).let { payload ->
681+ mDispatcher.dispatch(SiteActionBuilder .newFetchedConnectSiteInfoAction(payload))
682+ }
683+ }
684+ }
685+
686+ @Suppress(" SwallowedException" )
687+ suspend fun fetchConnectSiteInfoSync (siteUrl : String ): ConnectSiteInfoPayload {
688+ fun ConnectSiteInfoResponse.toConnectSiteInfoPayload (url : String ): ConnectSiteInfoPayload {
689+ return ConnectSiteInfoPayload (
690+ url,
691+ exists,
692+ isWordPress,
693+ hasJetpack,
694+ isJetpackActive,
695+ isJetpackConnected,
696+ isWordPressDotCom, // CHECKSTYLE IGNORE
697+ urlAfterRedirects
698+ )
699+ }
700+
678701 // Get a proper URI to reliably retrieve the scheme.
679702 val uri: URI = try {
680703 URI .create(UrlUtils .addUrlSchemeIfNeeded(siteUrl, false ))
681704 } catch (e: IllegalArgumentException ) {
682705 val siteError = SiteError (INVALID_SITE )
683- val payload = ConnectSiteInfoPayload (siteUrl, siteError)
684- mDispatcher.dispatch(SiteActionBuilder .newFetchedConnectSiteInfoAction(payload))
685- return
706+ return ConnectSiteInfoPayload (siteUrl, siteError)
686707 }
708+
687709 val params = mutableMapOf<String , String >()
688710 params[" url" ] = uri.toString()
689711
690712 // Make the call.
691713 val url = WPCOMREST .connect.site_info.urlV1_1
692- val request = WPComGsonRequest .buildGetRequest(url, params,
693- ConnectSiteInfoResponse ::class .java,
694- { response ->
695- val info = connectSiteInfoFromResponse(siteUrl, response)
696- mDispatcher.dispatch(SiteActionBuilder .newFetchedConnectSiteInfoAction(info))
697- }
698- ) {
699- val siteError = SiteError (INVALID_SITE )
700- val info = ConnectSiteInfoPayload (siteUrl, siteError)
701- mDispatcher.dispatch(SiteActionBuilder .newFetchedConnectSiteInfoAction(info))
714+ val response = wpComGsonRequestBuilder.syncGetRequest(
715+ restClient = this ,
716+ url = url,
717+ params = params,
718+ clazz = ConnectSiteInfoResponse ::class .java
719+ )
720+
721+ return when (response) {
722+ is Error -> {
723+ val siteError = SiteError (INVALID_SITE )
724+ ConnectSiteInfoPayload (siteUrl, siteError)
725+ }
726+ is Success -> {
727+ response.data.toConnectSiteInfoPayload(siteUrl)
728+ }
702729 }
703- addUnauthedRequest(request)
704730 }
705731
706732 @Suppress(" SwallowedException" )
@@ -1229,19 +1255,6 @@ class SiteRestClient @Inject constructor(
12291255 return payload
12301256 }
12311257
1232- private fun connectSiteInfoFromResponse (url : String , response : ConnectSiteInfoResponse ): ConnectSiteInfoPayload {
1233- return ConnectSiteInfoPayload (
1234- url,
1235- response.exists,
1236- response.isWordPress,
1237- response.hasJetpack,
1238- response.isJetpackActive,
1239- response.isJetpackConnected,
1240- response.isWordPressDotCom, // CHECKSTYLE IGNORE
1241- response.urlAfterRedirects
1242- )
1243- }
1244-
12451258 private fun responseToDomainAvailabilityPayload (
12461259 response : DomainAvailabilityResponse
12471260 ): DomainAvailabilityResponsePayload {
0 commit comments