Created
January 15, 2016 20:00
-
-
Save paulofaria/b53f57b076cafc3240ce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public Observable<Rates> getRates() { | |
String accessToken = getAuthenticationTokens().getAccessToken(); | |
return networking.getRates(accessToken) | |
.flatMap(new Func1<Response<Rates>, Observable<Rates>>() { | |
@Override | |
public Observable<Rates> call(Response<Rates> response) { | |
if (response.isSuccess()) { | |
Rates rates = response.body(); | |
return Observable.just(rates); | |
} | |
switch (response.code()) { | |
case 401: | |
return exchangeRefreshToken() | |
.doOnNext(new Action1<AuthenticationTokens>() { | |
@Override | |
public void call(AuthenticationTokens authenticationTokens) { | |
saveAuthenticationTokens(authenticationTokens); | |
} | |
}).flatMap(new Func1<AuthenticationTokens, Observable<Rates>>() { | |
@Override | |
public Observable<Rates> call(AuthenticationTokens authenticationTokens) { | |
return getRates(); | |
} | |
}); | |
} | |
return Observable.error(ErrorParser.parseBody(response.errorBody())); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment