Created
August 19, 2014 00:27
-
-
Save hectorups/4e5aabb203f44a21135d to your computer and use it in GitHub Desktop.
Retrofit use
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 interface Api { | |
| @POST("/users/sign_in") Observable<Response> login(@Body Login login); | |
| } |
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
| client.login(login) | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .subscribeOn(Schedulers.io()) | |
| .subscribe(new Observer<Response>() { | |
| @Override public void onCompleted() { | |
| } | |
| @Override public void onError(Throwable e) { | |
| } | |
| @Override public void onNext(Response response) { | |
| User user; | |
| try { | |
| user = (User) gsonConverter.fromBody(response.getBody(), User.class); | |
| } catch (Exception e) { | |
| onError(e); | |
| return; | |
| } | |
| //... | |
| } | |
| }); |
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 class Login { | |
| private String email; | |
| private String password; | |
| private String fbToken; | |
| private String gplusToken; | |
| private String audienceToken; | |
| public Login(String email, String password) { | |
| this.email = email; | |
| this.password = password; | |
| } | |
| public Login() { | |
| } | |
| //... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment