Skip to content
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

PIA-839: Add region's iso within the shadowsocks server response #15

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,11 @@ public class Regions internal constructor(

val localizedRegions = mutableListOf<ShadowsocksRegionsResponse>()
for (region in shadowsocksRegionsResponse) {
val regionTranslation = shadowsocksRegionTranslation(region.region, vpnRegionsResponse)
?: continue
localizedRegions.add(region.copy(region = regionTranslation))
shadowsocksRegionTranslation(region.region, vpnRegionsResponse)?.let { translation ->
shadowsocksRegionIso(region.region, vpnRegionsResponse)?.let { iso ->
localizedRegions.add(region.copy(iso = iso, region = translation))
}
}
}
return Result.success(localizedRegions)
}
Expand Down Expand Up @@ -369,14 +371,25 @@ public class Regions internal constructor(
vpnRegionsResponse: VpnRegionsResponse
): String? {
for (region in vpnRegionsResponse.regions) {

if (region.id.startsWith(shadowsocksRegion, ignoreCase = true)) {
if (region.id.equals(shadowsocksRegion, ignoreCase = true)) {
return region.name
}
}
return null
}

private fun shadowsocksRegionIso(
shadowsocksRegion: String,
vpnRegionsResponse: VpnRegionsResponse
): String? {
for (region in vpnRegionsResponse.regions) {
if (region.id.equals(shadowsocksRegion, ignoreCase = true)) {
return region.country
}
}
return null
}

private fun coordinatesForRegionId(
targetRegionId: String,
translationsGeoResponse: TranslationsGeoResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ package com.privateinternetaccess.regions.model
* Internet Access Mobile Client. If not, see <https://www.gnu.org/licenses/>.
*/

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable


@Serializable
public data class ShadowsocksRegionsResponse(
@SerialName("region")
val iso: String = "world",
val region: String,
@SerialName("host")
val host: String,
@SerialName("port")
val port: Int,
@SerialName("key")
val key: String,
@SerialName("cipher")
val cipher: String
)