Skip to content

Commit

Permalink
Attempted fix for CoinGecko API.
Browse files Browse the repository at this point in the history
  • Loading branch information
hwki committed Sep 11, 2024
1 parent 7d1abf6 commit cea2891
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
7 changes: 3 additions & 4 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ android {
applicationId "com.brentpanther.bitcoinwidget"
minSdk 23
targetSdk 34
versionCode 333
versionName "8.5.8"

versionCode 334
versionName "8.5.9"
}

buildFeatures {
Expand Down Expand Up @@ -62,7 +61,7 @@ ksp {
}

dependencies {
implementation platform('androidx.compose:compose-bom:2024.09.00')
implementation platform('androidx.compose:compose-bom:2024.09.01')

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import java.io.InputStream
object ExchangeHelper {

private val client: OkHttpClient by lazy {
OkHttpClient.Builder()
.addNetworkInterceptor { chain -> intercept(chain) }
.build()
OkHttpClient.Builder().build()
}

val JsonElement?.asString: String?
Expand All @@ -38,6 +36,7 @@ object ExchangeHelper {
headers?.let {
builder = builder.headers(it)
}
builder = builder.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0")
val request = builder.build()
val response = client.newCall(request).execute()
if (response.code == 429) {
Expand All @@ -49,12 +48,4 @@ object ExchangeHelper {
}
}

@Throws(IOException::class)
private fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request().newBuilder()
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0")
.build()
val response = chain.proceed(request)
return response.newBuilder().build()
}
}
2 changes: 1 addition & 1 deletion bitcoin/src/main/res/raw/cryptowidgetcoins_v2.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bitcoin/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<item>ISO</item>
<item>NONE</item>
</string-array>
<string name="json_last_modified" translatable="false">Mon, 09 Sep 2024 13:12:38 GMT</string>
<string name="json_last_modified" translatable="false">Wed, 11 Sep 2024 01:13:42 GMT</string>
<string name="json_url" translatable="false">https://www.brentpanther.com/cryptowidgetcoins_v2.json</string>

<string name="error_restricted_battery_saver">Unable to refresh, Battery Saver is on</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,14 @@ class GenerateSupportedCoinsJson {

private fun parseKeys(url: String, path: String) = (JsonPath.read(get(url), path) as Map<String, *>).keys.map { it }
private fun parse(url: String, path: String) = JsonPath.read(get(url), path) as List<String>
private fun get(value: String): String = OkHttpClient.Builder().ignoreAllSSLErrors().build().newCall(Request.Builder().url(value).build()).execute().body!!.string()
private fun get(value: String): String = OkHttpClient.Builder()
.ignoreAllSSLErrors()
.build()
.newCall(Request.Builder()
.url(value)
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0")
.build()
).execute().body!!.string()

private fun OkHttpClient.Builder.ignoreAllSSLErrors(): OkHttpClient.Builder {
val naiveTrustManager = object : X509TrustManager {
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/334.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Attempted fix for CoinGecko API.

0 comments on commit cea2891

Please sign in to comment.