Skip to content

Commit cea2891

Browse files
committed
Attempted fix for CoinGecko API.
1 parent 7d1abf6 commit cea2891

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

bitcoin/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ android {
1313
applicationId "com.brentpanther.bitcoinwidget"
1414
minSdk 23
1515
targetSdk 34
16-
versionCode 333
17-
versionName "8.5.8"
18-
16+
versionCode 334
17+
versionName "8.5.9"
1918
}
2019

2120
buildFeatures {
@@ -62,7 +61,7 @@ ksp {
6261
}
6362

6463
dependencies {
65-
implementation platform('androidx.compose:compose-bom:2024.09.00')
64+
implementation platform('androidx.compose:compose-bom:2024.09.01')
6665

6766
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1'
6867
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3'

bitcoin/src/main/java/com/brentpanther/bitcoinwidget/exchange/ExchangeHelper.kt

+2-11
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import java.io.InputStream
1313
object ExchangeHelper {
1414

1515
private val client: OkHttpClient by lazy {
16-
OkHttpClient.Builder()
17-
.addNetworkInterceptor { chain -> intercept(chain) }
18-
.build()
16+
OkHttpClient.Builder().build()
1917
}
2018

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

52-
@Throws(IOException::class)
53-
private fun intercept(chain: Interceptor.Chain): Response {
54-
val request = chain.request().newBuilder()
55-
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0")
56-
.build()
57-
val response = chain.proceed(request)
58-
return response.newBuilder().build()
59-
}
6051
}

bitcoin/src/main/res/raw/cryptowidgetcoins_v2.json

+1-1
Large diffs are not rendered by default.

bitcoin/src/main/res/values/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<item>ISO</item>
9797
<item>NONE</item>
9898
</string-array>
99-
<string name="json_last_modified" translatable="false">Mon, 09 Sep 2024 13:12:38 GMT</string>
99+
<string name="json_last_modified" translatable="false">Wed, 11 Sep 2024 01:13:42 GMT</string>
100100
<string name="json_url" translatable="false">https://www.brentpanther.com/cryptowidgetcoins_v2.json</string>
101101

102102
<string name="error_restricted_battery_saver">Unable to refresh, Battery Saver is on</string>

bitcoin/src/test/java/com/brentpanther/bitcoinwidget/GenerateSupportedCoinsJson.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,14 @@ class GenerateSupportedCoinsJson {
242242

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

247254
private fun OkHttpClient.Builder.ignoreAllSSLErrors(): OkHttpClient.Builder {
248255
val naiveTrustManager = object : X509TrustManager {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Attempted fix for CoinGecko API.

0 commit comments

Comments
 (0)