-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COINS-2255 | Refactor creating Retrofit services (#17)
* COINS-2255 | Refactor creating Retrofit services OkHttpClient instance is no longer created in this library. It has to be passed from the outside. Thanks to this change the OkHttpClient can be shared with the rest of the app. * COINS-2255 | Bump library version to 0.4.4
- Loading branch information
1 parent
7fe9719
commit 062141b
Showing
15 changed files
with
58 additions
and
123 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
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
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
28 changes: 3 additions & 25 deletions
28
src/main/java/com/coinpaprika/apiclient/api/CoinpaprikaApiFactory.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
21 changes: 8 additions & 13 deletions
21
src/main/java/com/coinpaprika/apiclient/repository/coin/CoinApi.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 |
---|---|---|
@@ -1,42 +1,37 @@ | ||
package com.coinpaprika.apiclient.repository.coin | ||
|
||
import com.coinpaprika.apiclient.api.CoinpaprikaApiFactory | ||
import com.coinpaprika.apiclient.entity.* | ||
import com.coinpaprika.apiclient.extensions.safeApiCallRaw | ||
import io.reactivex.Observable | ||
import retrofit2.Response | ||
|
||
class CoinApi constructor( | ||
private var retrofit: CoinApiContract = CoinpaprikaApiFactory() | ||
.client() | ||
.create(CoinApiContract::class.java) | ||
) : CoinApiContract { | ||
class CoinApi(private var contract: CoinApiContract) : CoinApiContract { | ||
|
||
override suspend fun getCoin(id: String): CoinDetailsEntity { | ||
return retrofit.getCoin(id) | ||
return contract.getCoin(id) | ||
} | ||
|
||
override suspend fun getCoins(additionalFields: String?): List<CoinEntity> { | ||
return retrofit.getCoins(additionalFields) | ||
return contract.getCoins(additionalFields) | ||
} | ||
|
||
override fun getEvents(id: String): Observable<Response<List<EventEntity>>> { | ||
return safeApiCallRaw { retrofit.getEvents(id) } | ||
return safeApiCallRaw { contract.getEvents(id) } | ||
} | ||
|
||
override fun getExchanges(id: String): Observable<Response<List<ExchangeEntity>>> { | ||
return safeApiCallRaw { retrofit.getExchanges(id) } | ||
return safeApiCallRaw { contract.getExchanges(id) } | ||
} | ||
|
||
override fun getMarkets(id: String, quotes: String): Observable<Response<List<MarketEntity>>> { | ||
return safeApiCallRaw { retrofit.getMarkets(id, quotes) } | ||
return safeApiCallRaw { contract.getMarkets(id, quotes) } | ||
} | ||
|
||
override fun getTweets(id: String): Observable<Response<List<TweetEntity>>> { | ||
return safeApiCallRaw { retrofit.getTweets(id) } | ||
return safeApiCallRaw { contract.getTweets(id) } | ||
} | ||
|
||
override fun addEvent(cryptoId: String, event: EventEntity): Observable<Response<Void>> { | ||
return safeApiCallRaw { retrofit.addEvent(cryptoId, event) } | ||
return safeApiCallRaw { contract.addEvent(cryptoId, event) } | ||
} | ||
} |
11 changes: 3 additions & 8 deletions
11
src/main/java/com/coinpaprika/apiclient/repository/exchange/ExchangeApi.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 |
---|---|---|
@@ -1,23 +1,18 @@ | ||
package com.coinpaprika.apiclient.repository.exchange | ||
|
||
import com.coinpaprika.apiclient.api.CoinpaprikaApiFactory | ||
import com.coinpaprika.apiclient.entity.ExchangeEntity | ||
import com.coinpaprika.apiclient.entity.MarketEntity | ||
import com.coinpaprika.apiclient.extensions.safeApiCallRaw | ||
import io.reactivex.Observable | ||
import retrofit2.Response | ||
|
||
class ExchangeApi constructor( | ||
private var retrofit: ExchangeApiContract = CoinpaprikaApiFactory() | ||
.client() | ||
.create(ExchangeApiContract::class.java) | ||
) : ExchangeApiContract { | ||
class ExchangeApi(private var contract: ExchangeApiContract) : ExchangeApiContract { | ||
|
||
override fun getExchanges(): Observable<Response<List<ExchangeEntity>>> { | ||
return safeApiCallRaw { retrofit.getExchanges() } | ||
return safeApiCallRaw { contract.getExchanges() } | ||
} | ||
|
||
override fun getMarkets(exchangeId: String): Observable<Response<List<MarketEntity>>> { | ||
return safeApiCallRaw { retrofit.getMarkets(exchangeId) } | ||
return safeApiCallRaw { contract.getMarkets(exchangeId) } | ||
} | ||
} |
9 changes: 2 additions & 7 deletions
9
src/main/java/com/coinpaprika/apiclient/repository/fiats/FiatApi.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 |
---|---|---|
@@ -1,15 +1,10 @@ | ||
package com.coinpaprika.apiclient.repository.fiats | ||
|
||
import com.coinpaprika.apiclient.api.CoinpaprikaApiFactory | ||
import com.coinpaprika.apiclient.entity.FiatEntity | ||
|
||
class FiatApi constructor( | ||
private var retrofit: FiatApiContract = CoinpaprikaApiFactory() | ||
.client() | ||
.create(FiatApiContract::class.java) | ||
) : FiatApiContract { | ||
class FiatApi(private var contract: FiatApiContract) : FiatApiContract { | ||
|
||
override suspend fun getFiats(): List<FiatEntity> { | ||
return retrofit.getFiats() | ||
return contract.getFiats() | ||
} | ||
} |
9 changes: 2 additions & 7 deletions
9
src/main/java/com/coinpaprika/apiclient/repository/global/GlobalApi.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 |
---|---|---|
@@ -1,18 +1,13 @@ | ||
package com.coinpaprika.apiclient.repository.global | ||
|
||
import com.coinpaprika.apiclient.api.CoinpaprikaApiFactory | ||
import com.coinpaprika.apiclient.entity.GlobalStatsEntity | ||
import com.coinpaprika.apiclient.extensions.safeApiCallRaw | ||
import io.reactivex.Observable | ||
import retrofit2.Response | ||
|
||
class GlobalApi constructor( | ||
private var retrofit: GlobalApiContract = CoinpaprikaApiFactory() | ||
.client() | ||
.create(GlobalApiContract::class.java) | ||
) : GlobalApiContract { | ||
class GlobalApi(private var contract: GlobalApiContract) : GlobalApiContract { | ||
|
||
override fun getGlobal(): Observable<Response<GlobalStatsEntity>> { | ||
return safeApiCallRaw { retrofit.getGlobal() } | ||
return safeApiCallRaw { contract.getGlobal() } | ||
} | ||
} |
9 changes: 2 additions & 7 deletions
9
src/main/java/com/coinpaprika/apiclient/repository/news/NewsApi.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 |
---|---|---|
@@ -1,18 +1,13 @@ | ||
package com.coinpaprika.apiclient.repository.news | ||
|
||
import com.coinpaprika.apiclient.api.CoinpaprikaApiFactory | ||
import com.coinpaprika.apiclient.entity.NewsEntity | ||
import com.coinpaprika.apiclient.extensions.safeApiCallRaw | ||
import io.reactivex.Observable | ||
import retrofit2.Response | ||
|
||
class NewsApi constructor( | ||
private var retrofit: NewsApiContract = CoinpaprikaApiFactory() | ||
.client() | ||
.create(NewsApiContract::class.java) | ||
) : NewsApiContract { | ||
class NewsApi(private var contract: NewsApiContract) : NewsApiContract { | ||
|
||
override fun getNews(limit: Int): Observable<Response<List<NewsEntity>>> { | ||
return safeApiCallRaw { retrofit.getNews(limit) } | ||
return safeApiCallRaw { contract.getNews(limit) } | ||
} | ||
} |
11 changes: 3 additions & 8 deletions
11
src/main/java/com/coinpaprika/apiclient/repository/people/PeopleApi.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 |
---|---|---|
@@ -1,23 +1,18 @@ | ||
package com.coinpaprika.apiclient.repository.people | ||
|
||
import com.coinpaprika.apiclient.api.CoinpaprikaApiFactory | ||
import com.coinpaprika.apiclient.entity.PersonEntity | ||
import com.coinpaprika.apiclient.entity.TweetEntity | ||
import com.coinpaprika.apiclient.extensions.safeApiCallRaw | ||
import io.reactivex.Observable | ||
import retrofit2.Response | ||
|
||
class PeopleApi constructor( | ||
private var retrofit: PeopleApiContract = CoinpaprikaApiFactory() | ||
.client() | ||
.create(PeopleApiContract::class.java) | ||
) : PeopleApiContract { | ||
class PeopleApi(private var contract: PeopleApiContract) : PeopleApiContract { | ||
|
||
override fun getPerson(id: String): Observable<Response<PersonEntity>> { | ||
return safeApiCallRaw { retrofit.getPerson(id) } | ||
return safeApiCallRaw { contract.getPerson(id) } | ||
} | ||
|
||
override fun getTweets(id: String): Observable<Response<List<TweetEntity>>> { | ||
return safeApiCallRaw { retrofit.getTweets(id) } | ||
return safeApiCallRaw { contract.getTweets(id) } | ||
} | ||
} |
11 changes: 3 additions & 8 deletions
11
src/main/java/com/coinpaprika/apiclient/repository/ranking/RankingApi.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 |
---|---|---|
@@ -1,19 +1,14 @@ | ||
package com.coinpaprika.apiclient.repository.ranking | ||
|
||
import com.coinpaprika.apiclient.api.CoinpaprikaApiFactory | ||
import com.coinpaprika.apiclient.entity.TopMoversEntity | ||
|
||
class RankingApi constructor( | ||
private var retrofit: RankingApiContract = CoinpaprikaApiFactory() | ||
.client() | ||
.create(RankingApiContract::class.java) | ||
) : RankingApiContract { | ||
class RankingApi(private var contract: RankingApiContract) : RankingApiContract { | ||
|
||
override suspend fun getTop10Movers(type: String): TopMoversEntity { | ||
return retrofit.getTop10Movers(type) | ||
return contract.getTop10Movers(type) | ||
} | ||
|
||
override suspend fun getMovers(results: Int, range: String): TopMoversEntity { | ||
return retrofit.getMovers(results, range) | ||
return contract.getMovers(results, range) | ||
} | ||
} |
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
11 changes: 3 additions & 8 deletions
11
src/main/java/com/coinpaprika/apiclient/repository/tag/TagApi.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 |
---|---|---|
@@ -1,19 +1,14 @@ | ||
package com.coinpaprika.apiclient.repository.tag | ||
|
||
import com.coinpaprika.apiclient.api.CoinpaprikaApiFactory | ||
import com.coinpaprika.apiclient.entity.TagEntity | ||
|
||
class TagApi constructor( | ||
private var retrofit: TagApiContract = CoinpaprikaApiFactory() | ||
.client() | ||
.create(TagApiContract::class.java) | ||
) : TagApiContract { | ||
class TagApi(private var contract: TagApiContract) : TagApiContract { | ||
|
||
override suspend fun getTag(id: String): TagEntity { | ||
return retrofit.getTag(id) | ||
return contract.getTag(id) | ||
} | ||
|
||
override suspend fun getTags(): List<TagEntity> { | ||
return retrofit.getTags() | ||
return contract.getTags() | ||
} | ||
} |
15 changes: 5 additions & 10 deletions
15
src/main/java/com/coinpaprika/apiclient/repository/ticker/TickerApi.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
3 changes: 1 addition & 2 deletions
3
src/main/java/com/coinpaprika/apiclient/repository/ticker/TickerApiContract.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