Skip to content

Instantly share code, notes, and snippets.

@rezaiyan
Created October 21, 2022 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezaiyan/96c8ae8ccc17a3cd4e32f6055ac5f5f9 to your computer and use it in GitHub Desktop.
Save rezaiyan/96c8ae8ccc17a3cd4e32f6055ac5f5f9 to your computer and use it in GitHub Desktop.
Mock response
val client = OkHttpClient.Builder()
.addInterceptor(MockInterceptor())
.build()
//-------------------------
import okhttp3.Interceptor
import okhttp3.Protocol
import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody
class MockInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
return Response.Builder()
.body(mockResponse.toResponseBody())
.code(200)
.protocol(Protocol.HTTP_1_0)
.request(chain.request())
.message("")
.build()
}
}
//-------------------------
const val mockResponse = "{\n" +
" \"coins\": [\n" +
" {\n" +
" \"id\": \"bitcoin\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/1650455588819.png\",\n" +
" \"name\": \"Bitcoin\",\n" +
" \"symbol\": \"BTC\",\n" +
" \"rank\": 1,\n" +
" \"price\": 19494.239287258468,\n" +
" \"priceBtc\": 1,\n" +
" \"volume\": 31066775117.589973,\n" +
" \"marketCap\": 373999904861.9468,\n" +
" \"availableSupply\": 19185150,\n" +
" \"totalSupply\": 21000000,\n" +
" \"priceChange1h\": -0.09,\n" +
" \"priceChange1d\": -0.4,\n" +
" \"priceChange1w\": -3.89,\n" +
" \"websiteUrl\": \"http://www.bitcoin.org\",\n" +
" \"twitterUrl\": \"https://twitter.com/bitcoin\",\n" +
" \"exp\": [\n" +
" \"https://blockchair.com/bitcoin/\",\n" +
" \"https://btc.com/\",\n" +
" \"https://btc.tokenview.io/\"\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"id\": \"ethereum\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/1650455629727.png\",\n" +
" \"name\": \"Ethereum\",\n" +
" \"symbol\": \"ETH\",\n" +
" \"rank\": 2,\n" +
" \"price\": 1318.0861027788776,\n" +
" \"priceBtc\": 0.0675948244809498,\n" +
" \"volume\": 28071413661.120247,\n" +
" \"marketCap\": 158860784688.81567,\n" +
" \"availableSupply\": 120523829.478131,\n" +
" \"totalSupply\": 120523829.478131,\n" +
" \"priceChange1h\": -0.15,\n" +
" \"priceChange1d\": -0.31,\n" +
" \"priceChange1w\": -2.98,\n" +
" \"websiteUrl\": \"https://www.ethereum.org/\",\n" +
" \"twitterUrl\": \"https://twitter.com/ethereum\",\n" +
" \"contractAddress\": \"0x2170ed0880ac9a755fd29b2688956bd959f933f8\",\n" +
" \"decimals\": 18,\n" +
" \"exp\": [\n" +
" \"https://etherscan.io/\",\n" +
" \"https://ethplorer.io/\",\n" +
" \"https://blockchair.com/ethereum\",\n" +
" \"https://eth.tokenview.io/\"\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"id\": \"tether\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/1650455771843.png\",\n" +
" \"name\": \"Tether\",\n" +
" \"symbol\": \"USDT\",\n" +
" \"rank\": 3,\n" +
" \"price\": 1.0274944701231479,\n" +
" \"priceBtc\": 0.000052692542783581884,\n" +
" \"volume\": 54086681843.77335,\n" +
" \"marketCap\": 70334729285.74742,\n" +
" \"availableSupply\": 68452659679.3437,\n" +
" \"totalSupply\": 68452659679.3437,\n" +
" \"priceChange1h\": -0.02,\n" +
" \"priceChange1d\": -0.06,\n" +
" \"priceChange1w\": 0.3,\n" +
" \"websiteUrl\": \"https://tether.to/\",\n" +
" \"twitterUrl\": \"https://twitter.com/Tether_to\",\n" +
" \"contractAddress\": \"0xdac17f958d2ee523a2206206994597c13d831ec7\",\n" +
" \"decimals\": 18,\n" +
" \"exp\": [\n" +
" \"https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7\",\n" +
" \"https://ethplorer.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7\",\n" +
" \"https://snowtrace.io/token/0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7\",\n" +
" \"https://optimistic.etherscan.io/token/0x94b008aa00579c1307b0ef2c499ad98a8ce58e58\",\n" +
" \"https://polygonscan.com/token/0xc2132d05d31c914a87c6611c10748aeb04b58e8f\",\n" +
" \"https://bscscan.com/token/0x55d398326f99059ff775485246999027b3197955\",\n" +
" \"https://www.nearscan.org/tokens/dac17f958d2ee523a2206206994597c13d831ec7.factory.bridge.near\",\n" +
" \"https://cronos-explorer.crypto.org/token/0x66e428c3f67a68878562e79a0234c1f83c208770\",\n" +
" \"https://avascan.info/blockchain/c/address/0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7/token\",\n" +
" \"https://evmexplorer.velas.com/address/0xb44a9b6905af7c801311e8f4e76932ee959c663c\"\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"id\": \"usd-coin\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/1650455825065.png\",\n" +
" \"name\": \"USD Coin\",\n" +
" \"symbol\": \"USDC\",\n" +
" \"rank\": 4,\n" +
" \"price\": 1.02506861098595,\n" +
" \"priceBtc\": 0.00005255176369717688,\n" +
" \"volume\": 2356088549.1336584,\n" +
" \"marketCap\": 44987708844.67292,\n" +
" \"availableSupply\": 43895016055.4998,\n" +
" \"totalSupply\": 43897094311.4878,\n" +
" \"priceChange1h\": 0.18,\n" +
" \"priceChange1d\": 0.02,\n" +
" \"priceChange1w\": 0.02,\n" +
" \"websiteUrl\": \"https://www.circle.com/en/usdc\",\n" +
" \"twitterUrl\": \"https://twitter.com/circlepay\",\n" +
" \"contractAddress\": \"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\n" +
" \"decimals\": 18,\n" +
" \"exp\": [\n" +
" \"https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\n" +
" \"https://ethplorer.io/address/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\n" +
" \"https://blockchair.com/ethereum/erc-20/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\n" +
" \"https://blockscout.com/xdai/mainnet/token/0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83/token-transfers\",\n" +
" \"https://polygonscan.com/token/0x2791bca1f2de4661ed88a30c99a7a9449aa84174\",\n" +
" \"https://bscscan.com/token/0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d\",\n" +
" \"https://ftmscan.com/address/0x04068da6c83afcfa0e13ba15a6696662335d5b75\",\n" +
" \"https://arbiscan.io/token/0xff970a61a04b1ca14834a43f5de4533ebddb5cc8\",\n" +
" \"https://evmexplorer.velas.com/address/0x80a16016cc4a2e6a2caca8a4a498b1699ff0f844\",\n" +
" \"https://stepscan.io/token/0xe3f5a90f9cb311505cd691a46596599aa1a0ad7d\"\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"id\": \"binance-coin\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/1650455799549.png\",\n" +
" \"name\": \"BNB\",\n" +
" \"symbol\": \"BNB\",\n" +
" \"rank\": 5,\n" +
" \"price\": 273.9424893640112,\n" +
" \"priceBtc\": 0.014048471072865281,\n" +
" \"volume\": 602035641.6141703,\n" +
" \"marketCap\": 44728500885.9667,\n" +
" \"availableSupply\": 163276974.63,\n" +
" \"totalSupply\": 163276974.63,\n" +
" \"priceChange1h\": -0.33,\n" +
" \"priceChange1d\": -1.47,\n" +
" \"priceChange1w\": -2.68,\n" +
" \"websiteUrl\": \"https://www.binance.com/\",\n" +
" \"twitterUrl\": \"https://twitter.com/binance\",\n" +
" \"contractAddress\": \"BNB\",\n" +
" \"decimals\": 18,\n" +
" \"exp\": [\n" +
" \"https://binance.mintscan.io/\",\n" +
" \"https://explorer.binance.org/\",\n" +
" \"https://bscscan.com\",\n" +
" \"https://blockchair.com/ethereum/erc-20/token/0xb8c77482e45f1f44de1745f52c74426c631bdd52\",\n" +
" \"https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52\"\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"id\": \"ripple\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/XRPdnqGJ.png\",\n" +
" \"name\": \"XRP\",\n" +
" \"symbol\": \"XRP\",\n" +
" \"rank\": 6,\n" +
" \"price\": 0.45603313019336683,\n" +
" \"priceBtc\": 0.000023386544572414824,\n" +
" \"volume\": 3263406870.476892,\n" +
" \"marketCap\": 22750131930.236965,\n" +
" \"availableSupply\": 49887015710,\n" +
" \"totalSupply\": 99989258607,\n" +
" \"priceChange1h\": -0.4,\n" +
" \"priceChange1d\": -2.83,\n" +
" \"priceChange1w\": -10.7,\n" +
" \"websiteUrl\": \"https://ripple.com/currency/\",\n" +
" \"twitterUrl\": \"https://twitter.com/Ripple\",\n" +
" \"contractAddress\": \"0x1d2f0da169ceb9fc7b3144628db156f3f6c60dbe\",\n" +
" \"decimals\": 18,\n" +
" \"exp\": [\n" +
" \"https://blockchair.com/ripple\",\n" +
" \"https://xrpcharts.ripple.com\",\n" +
" \"https://xrpscan.com/\",\n" +
" \"https://bithomp.com/explorer/\"\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"id\": \"binance-usd\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/binance-usdcP4.png\",\n" +
" \"name\": \"Binance USD\",\n" +
" \"symbol\": \"BUSD\",\n" +
" \"rank\": 7,\n" +
" \"price\": 1.0240445664195306,\n" +
" \"priceBtc\": 0.00005249926443274414,\n" +
" \"volume\": 5851736265.514276,\n" +
" \"marketCap\": 22465353862.696106,\n" +
" \"availableSupply\": 21932426831.48,\n" +
" \"totalSupply\": 21932426831.48,\n" +
" \"priceChange1h\": 0.11,\n" +
" \"priceChange1d\": 0.01,\n" +
" \"priceChange1w\": 0.08,\n" +
" \"websiteUrl\": \"https://www.paxos.com/busd/\",\n" +
" \"twitterUrl\": \"https://twitter.com/PaxosGlobal\",\n" +
" \"contractAddress\": \"0x4Fabb145d64652a948d72533023f6E7A623C7C53\",\n" +
" \"decimals\": 18,\n" +
" \"exp\": [\n" +
" \"https://etherscan.io/token/0x4Fabb145d64652a948d72533023f6E7A623C7C53\",\n" +
" \"https://ethplorer.io/address/0x4Fabb145d64652a948d72533023f6E7A623C7C53\",\n" +
" \"https://explorer.binance.org/asset/BUSD-BD1\",\n" +
" \"https://bscscan.com/token/0xe9e7cea3dedca5984780bafc599bd69add087d56\",\n" +
" \"https://polygonscan.com/token/0xdab529f40e671a1d4bf91361c21bf9f0c9712ab7\",\n" +
" \"https://snowtrace.io/token/0x9C9e5fD8bbc25984B178FdCE6117Defa39d2db39\",\n" +
" \"https://moonriver.moonscan.io/token/0x5d9ab5522c64e1f6ef5e3627eccc093f56167818\",\n" +
" \"https://cronos.org/explorer/token/0xC74D59A548ecf7fc1754bb7810D716E9Ac3e3AE5/token-transfers\",\n" +
" \"https://explorer.fuse.io/token/0x6a5f6a8121592becd6747a38d67451b310f7f156\",\n" +
" \"https://scan.meter.io/address/0x24aa189dfaa76c671c279262f94434770f557c35\"\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"id\": \"cardano\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/CardanojXddT.png\",\n" +
" \"name\": \"Cardano\",\n" +
" \"symbol\": \"ADA\",\n" +
" \"rank\": 8,\n" +
" \"price\": 0.3473455940207546,\n" +
" \"priceBtc\": 0.000017812769903699504,\n" +
" \"volume\": 828450891.4692516,\n" +
" \"marketCap\": 11747319183.266191,\n" +
" \"availableSupply\": 33820262543.95,\n" +
" \"totalSupply\": 45000000000,\n" +
" \"priceChange1h\": -0.03,\n" +
" \"priceChange1d\": -3.97,\n" +
" \"priceChange1w\": -11.93,\n" +
" \"websiteUrl\": \"https://www.cardano.org/en/home/\",\n" +
" \"twitterUrl\": \"https://twitter.com/Cardano_CF\",\n" +
" \"contractAddress\": \"0x3ee2200efb3400fabb9aacf31297cbdd1d435d47\",\n" +
" \"decimals\": 18,\n" +
" \"exp\": [\n" +
" \"https://cardanoscan.io/\",\n" +
" \"https://cardanoexplorer.com/\",\n" +
" \"https://blockchair.com/cardano\",\n" +
" \"https://adaex.org/\",\n" +
" \"https://adastat.net/\",\n" +
" \"https://ada.tokenview.io/\"\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"id\": \"solana\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/solanambZ.png\",\n" +
" \"name\": \"Solana\",\n" +
" \"symbol\": \"SOL\",\n" +
" \"rank\": 9,\n" +
" \"price\": 28.705135327395805,\n" +
" \"priceBtc\": 0.0014720727121441623,\n" +
" \"volume\": 1243715118.8184988,\n" +
" \"marketCap\": 10283451952.181318,\n" +
" \"availableSupply\": 358244329.277449,\n" +
" \"totalSupply\": 531595116.299532,\n" +
" \"priceChange1h\": -0.27,\n" +
" \"priceChange1d\": -4.01,\n" +
" \"priceChange1w\": -11.56,\n" +
" \"websiteUrl\": \"https://solana.com/\",\n" +
" \"twitterUrl\": \"https://twitter.com/solana\",\n" +
" \"contractAddress\": \"0x7dff46370e9ea5f0bad3c4e29711ad50062ea7a4\",\n" +
" \"decimals\": 18,\n" +
" \"exp\": [\n" +
" \"https://solscan.io/\",\n" +
" \"https://explorer.solana.com/\",\n" +
" \"https://solanabeach.io/\",\n" +
" \"https://solana.fm/\"\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"id\": \"dogecoin\",\n" +
" \"icon\": \"https://static.coinstats.app/coins/DogecoinIZai5.png\",\n" +
" \"name\": \"Dogecoin\",\n" +
" \"symbol\": \"DOGE\",\n" +
" \"rank\": 10,\n" +
" \"price\": 0.060190903803928344,\n" +
" \"priceBtc\": 0.000003086743399690346,\n" +
" \"volume\": 353792574.5035986,\n" +
" \"marketCap\": 8220214935.384854,\n" +
" \"availableSupply\": 136569056383.705,\n" +
" \"totalSupply\": 0,\n" +
" \"priceChange1h\": -0.12,\n" +
" \"priceChange1d\": -1.45,\n" +
" \"priceChange1w\": -2.83,\n" +
" \"websiteUrl\": \"http://dogecoin.com/\",\n" +
" \"redditUrl\": \"https://www.reddit.com/r/dogecoin\",\n" +
" \"twitterUrl\": \"https://twitter.com/dogecoin\",\n" +
" \"contractAddress\": \"0xba2ae424d960c26247dd6c32edc70b295c744c43\",\n" +
" \"decimals\": 18,\n" +
" \"exp\": [\n" +
" \"https://blockchair.com/dogecoin\",\n" +
" \"https://doge.tokenview.io/\",\n" +
" \"http://dogechain.info/chain/Dogecoin\"\n" +
" ]\n" +
" }\n" +
" ]\n" +
"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment