forked from ethereum-lists/chains
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial httpsloader (ethereum-lists#2104)
Did this in several projects now - so moving it to a module
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
id("maven-publish") | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("maven") { | ||
version = "1.2" | ||
|
||
from(components["java"]) | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":model")) | ||
implementation("com.squareup.okhttp3:okhttp:4.9.3") | ||
implementation("com.squareup.moshi:moshi:1.14.0") | ||
} |
20 changes: 20 additions & 0 deletions
20
httpsloader/src/main/kotlin/org/ethereum/lists/chains/https/Chain.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,20 @@ | ||
package org.ethereum.lists.chains.https | ||
|
||
import com.squareup.moshi.JsonAdapter | ||
import com.squareup.moshi.Moshi | ||
import com.squareup.moshi.Types | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import org.ethereum.lists.chains.model.Chain | ||
|
||
fun getChains(okhttpClient: OkHttpClient = OkHttpClient()): List<Chain>? { | ||
val request = Request.Builder() | ||
.url("https://chainid.network/chains.json") | ||
.build() | ||
|
||
val listMyData = Types.newParameterizedType(MutableList::class.java, Chain::class.java) | ||
val adapter: JsonAdapter<List<Chain>> = Moshi.Builder().build().adapter(listMyData) | ||
|
||
val response = okhttpClient.newCall(request).execute() | ||
return response.body?.let { adapter.fromJson(it.source()) } | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include(":model") | ||
include(":httpsloader") | ||
include(":processor") |