-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2867 from wordpress-mobile/task/add-fetch-all-dom…
…ains-call Adds fetch all-domains api call
- Loading branch information
Showing
11 changed files
with
265 additions
and
19 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
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
32 changes: 32 additions & 0 deletions
32
example/src/test/resources/wp/all-domains/all-domains.json
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,32 @@ | ||
{ | ||
"domains": [ | ||
{ | ||
"domain": "some.test.domain", | ||
"blog_id": 11111, | ||
"blog_name": "some test blog", | ||
"type": "mapping", | ||
"is_domain_only_site": false, | ||
"is_wpcom_staging_domain": false, | ||
"has_registration": false, | ||
"registration_date": "2009-03-26T21:20:53+00:00", | ||
"expiry": "2024-03-24T00:00:00+00:00", | ||
"wpcom_domain": false, | ||
"current_user_is_owner": true, | ||
"site_slug": "test slug" | ||
}, | ||
{ | ||
"domain": "some.test.domain 2", | ||
"blog_id": 22222, | ||
"blog_name": "some test blog 2", | ||
"type": "mapping", | ||
"is_domain_only_site": false, | ||
"is_wpcom_staging_domain": false, | ||
"has_registration": false, | ||
"registration_date": "2009-03-26T21:20:53+00:00", | ||
"expiry": "2024-03-24T00:00:00+00:00", | ||
"wpcom_domain": true, | ||
"current_user_is_owner": false, | ||
"site_slug": "test slug 2" | ||
} | ||
] | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...c/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/site/AllDomainsResponse.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,38 @@ | ||
package org.wordpress.android.fluxc.network.rest.wpcom.site | ||
|
||
import com.google.gson.annotations.JsonAdapter | ||
import com.google.gson.annotations.SerializedName | ||
|
||
data class AllDomainsResponse(val domains: List<AllDomainsDomain>) | ||
|
||
data class AllDomainsDomain( | ||
@SerializedName("domain") | ||
val domain: String? = null, | ||
@SerializedName("blog_id") | ||
val blogId: Long = 0, | ||
@SerializedName("blog_name") | ||
val blogName: String? = null, | ||
@SerializedName("type") | ||
val type: String? = null, | ||
@SerializedName("is_domain_only_site") | ||
@JsonAdapter(BooleanTypeAdapter::class) | ||
val isDomainOnlySite: Boolean = false, | ||
@SerializedName("is_wpcom_staging_domain") | ||
@JsonAdapter(BooleanTypeAdapter::class) | ||
val isWpcomStagingDomain: Boolean = false, | ||
@SerializedName("has_registration") | ||
@JsonAdapter(BooleanTypeAdapter::class) | ||
val hasRegistration: Boolean = false, | ||
@SerializedName("registration_date") | ||
val registrationDate: String? = null, | ||
@SerializedName("expiry") | ||
val expiry: String? = null, | ||
@SerializedName("wpcom_domain") | ||
@JsonAdapter(BooleanTypeAdapter::class) | ||
val wpcomDomain: Boolean = false, | ||
@SerializedName("current_user_is_owner") | ||
@JsonAdapter(BooleanTypeAdapter::class) | ||
val currentUserIsOwner: Boolean = false, | ||
@SerializedName("site_slug") | ||
val siteSlug: String? = null, | ||
) |
25 changes: 25 additions & 0 deletions
25
...c/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/site/BooleanTypeAdapter.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,25 @@ | ||
package org.wordpress.android.fluxc.network.rest.wpcom.site | ||
|
||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonDeserializer | ||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonParseException | ||
import java.lang.reflect.Type | ||
import java.util.Locale | ||
|
||
internal class BooleanTypeAdapter : JsonDeserializer<Boolean?> { | ||
@Suppress("VariableNaming") private val TRUE_STRINGS: Set<String> = HashSet(listOf("true", "1", "yes")) | ||
|
||
@Throws(JsonParseException::class) | ||
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Boolean { | ||
val jsonPrimitive = json.asJsonPrimitive | ||
return when { | ||
jsonPrimitive.isBoolean -> jsonPrimitive.asBoolean | ||
jsonPrimitive.isNumber -> jsonPrimitive.asNumber.toInt() == 1 | ||
jsonPrimitive.isString -> TRUE_STRINGS.contains(jsonPrimitive.asString.toLowerCase( | ||
Locale.getDefault() | ||
)) | ||
else -> false | ||
} | ||
} | ||
} |
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
Oops, something went wrong.