Skip to content

Commit 4d8c318

Browse files
authored
Merge pull request #114 from EbenezerGH/cleanup-stat-extra-fields
update remove stat extra fields
2 parents 24fa606 + c5edbe8 commit 4d8c318

File tree

4 files changed

+12
-53
lines changed

4 files changed

+12
-53
lines changed

etherscan-sample/src/main/java/jfyg/etherscan/helloetherescan/SampleActivity.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class SampleActivity : AppCompatActivity() {
3232
fab.setOnClickListener {
3333

3434
//stat test
35-
stat.getLastPriceInBtc()
35+
stat.getEtherStatistics()
3636
.observeOn(AndroidSchedulers.mainThread())
3737
.subscribeBy(
38-
onSuccess = { Log.d(TAG, "The current price of Ether in Btc: $it") },
38+
onSuccess = { Log.d(TAG, "The current price of Ether in Btc: ${it.ethUsd}") },
3939
onError = { Log.d(TAG, "error receiving stat") })
4040

4141

etherscanapi/src/main/java/jfyg/data/stat/Stats.kt

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jfyg.data.stat
22

33
import io.reactivex.Single
4+
import jfyg.data.StatPrice
45
import jfyg.network.queries.ApiQuery
56
import jfyg.utils.ETH_PRICE
67
import jfyg.utils.ETH_SUPPLY
@@ -28,24 +29,9 @@ class Stats : StatsContract {
2829
override fun getTotalSupplyInWei(): Single<Double> = supplyQuery.map { it.result?.toDouble()?.div(wei) }
2930

3031
/**
31-
* Get ETHER LastPrice Price in btc
32+
* Get Ether Statistics
3233
*/
33-
override fun getLastPriceInUsd(): Single<Float> = priceQuery.map { it.result?.ethUsd?.toFloat() }
34-
35-
/**
36-
* Return timestamp
37-
*/
38-
override fun getEthTimestamp(): Single<Long> = priceQuery.map { it.result?.ethUsdTimestamp?.toLong() }
39-
40-
/**
41-
* Get ETHER LastPrice Price in usd
42-
*/
43-
override fun getLastPriceInBtc(): Single<Float> = priceQuery.map { it.result?.ethBtcTimestamp?.toFloat() }
44-
45-
/**
46-
* Return timestamp
47-
*/
48-
override fun getBtcTimestamp(): Single<Long> = priceQuery.map { it.result?.ethBtcTimestamp?.toLong() }
34+
override fun getEtherStatistics(): Single<StatPrice> = priceQuery.map { it.result }
4935

5036
/**
5137
* Return network status

etherscanapi/src/main/java/jfyg/data/stat/StatsContract.kt

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jfyg.data.stat
22

33
import io.reactivex.Single
4+
import jfyg.data.StatPrice
45

56
/**
67
* https://etherscan.io/apis#stats
@@ -18,24 +19,9 @@ internal interface StatsContract {
1819
fun getTotalSupplyInWei(): Single<Double>
1920

2021
/**
21-
* Get ETHER LastPrice Price in btc
22+
* Get ETHER statistics
2223
*/
23-
fun getLastPriceInBtc(): Single<Float>
24-
25-
/**
26-
* Return timestamp
27-
*/
28-
fun getBtcTimestamp(): Single<Long>
29-
30-
/**
31-
* Get ETHER LastPrice Price in usd
32-
*/
33-
fun getLastPriceInUsd(): Single<Float>
34-
35-
/**
36-
* Return timestamp
37-
*/
38-
fun getEthTimestamp(): Single<Long>
24+
fun getEtherStatistics(): Single<StatPrice>
3925

4026
/**
4127
* Return network status

etherscanapi/src/test/java/jfyg/data/stat/StatsTest.kt

+4-17
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,20 @@ internal class StatsTest {
6161
}
6262

6363
@Test
64-
fun getLastPriceInUsd() {
64+
fun getEtherStatistics() {
6565
val response = gson.fromJson(inputPrice, StatPriceResponse::class.java)
6666
assertEquals("377.67", response.result?.ethUsd)
67-
}
68-
69-
@Test
70-
fun getEthTimestamp() {
71-
val response = gson.fromJson(inputPrice, StatPriceResponse::class.java)
72-
assertEquals("1523064526", response.result?.ethUsdTimestamp)
73-
}
74-
75-
@Test
76-
fun getLastPriceInBtc() {
77-
val response = gson.fromJson(inputPrice, StatPriceResponse::class.java)
7867
assertEquals("0.0557", response.result?.ethBtc)
79-
}
80-
81-
@Test
82-
fun getBtcTimestamp() {
83-
val response = gson.fromJson(inputPrice, StatPriceResponse::class.java)
68+
assertEquals("1523064526", response.result?.ethUsdTimestamp)
8469
assertEquals("1523064523", response.result?.ethBtcTimestamp)
70+
8571
}
8672

8773
@Test
8874
fun networkStatusIsDown() {
8975
val response = gson.fromJson(inputBadResponse, BaseResponse::class.java)
9076
assertEquals("0", response.status)
77+
9178
}
9279

9380
@Test

0 commit comments

Comments
 (0)