Last active
June 9, 2020 22:34
-
-
Save raulh82vlc/f0e5e908c9cae7b421928acfc573c29a to your computer and use it in GitHub Desktop.
search functionality from Network data source implementation
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
suspend fun search(query: String, token: String) | |
:Either<Throwable, List<TweetApiModel>> { | |
// a response coming from the Retrofit API | |
val response = twitterApi.search(requestsIOHandler.getTokenFormatted(token), query) | |
return if (requestsIOHandler.searchIsSuccessful(response)) { | |
val tweets = requestsIOHandler.getTweets(response) | |
// return a list of tweets wrapped into a Either.Right | |
Either.right(tweets) | |
} else { | |
// return a bad response exception wrapped into an Either.Left | |
Either.left(BadResponseException(response.message())) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment