Skip to content

Commit 18081fb

Browse files
authored
Add initial httpsloader (ethereum-lists#2104)
Did this in several projects now - so moving it to a module
1 parent 4ecc635 commit 18081fb

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

httpsloader/build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
plugins {
2+
id("maven-publish")
3+
}
4+
5+
publishing {
6+
publications {
7+
create<MavenPublication>("maven") {
8+
version = "1.2"
9+
10+
from(components["java"])
11+
}
12+
}
13+
}
14+
15+
dependencies {
16+
implementation(project(":model"))
17+
implementation("com.squareup.okhttp3:okhttp:4.9.3")
18+
implementation("com.squareup.moshi:moshi:1.14.0")
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.ethereum.lists.chains.https
2+
3+
import com.squareup.moshi.JsonAdapter
4+
import com.squareup.moshi.Moshi
5+
import com.squareup.moshi.Types
6+
import okhttp3.OkHttpClient
7+
import okhttp3.Request
8+
import org.ethereum.lists.chains.model.Chain
9+
10+
fun getChains(okhttpClient: OkHttpClient = OkHttpClient()): List<Chain>? {
11+
val request = Request.Builder()
12+
.url("https://chainid.network/chains.json")
13+
.build()
14+
15+
val listMyData = Types.newParameterizedType(MutableList::class.java, Chain::class.java)
16+
val adapter: JsonAdapter<List<Chain>> = Moshi.Builder().build().adapter(listMyData)
17+
18+
val response = okhttpClient.newCall(request).execute()
19+
return response.body?.let { adapter.fromJson(it.source()) }
20+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
include(":model")
2+
include(":httpsloader")
23
include(":processor")

0 commit comments

Comments
 (0)