-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds fetch all-domains api call #2867
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b91597d
Adds all-domains endpoint
3f5b318
Extracts the boolean type adapter so that it can be reused with the a…
74e83c7
Adds the rest client implementation for the all-domains api call
0d77b28
Adds the all-domains api call to the site store
b90b05d
Adds UI to the example client to test the new call
0739f39
Update to use property syntax
5bed1ee
Adds error test cases
397b911
Merge branch 'trunk' into task/add-fetch-all-domains-call
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional nitpick: the property is never used. If we don't want to test the error cases for the "fetch all domains" flow, we can remove it and pass
null
directly, or we can have a test for a bad case too. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for catching this @justtwago 🙇
I've added some tests for the error cases with 5bed1ee