Skip to content

Instantly share code, notes, and snippets.

@raulh82vlc
Last active June 9, 2020 22:34
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 raulh82vlc/f0e5e908c9cae7b421928acfc573c29a to your computer and use it in GitHub Desktop.
Save raulh82vlc/f0e5e908c9cae7b421928acfc573c29a to your computer and use it in GitHub Desktop.
search functionality from Network data source implementation
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