{"action":"created","issue":{"url":"https://api.github.com/repos/square/retrofit/issues/831","labels_url":"https://api.github.com/repos/square/retrofit/issues/831/labels{/name}","comments_url":"https://api.github.com/repos/square/retrofit/issues/831/comments","events_url":"https://api.github.com/repos/square/retrofit/issues/831/events","html_url":"https://github.com/square/retrofit/pull/831","id":72842329,"number":831,"title":"Add rxpromises support","user":{"login":"SandroMachado","id":631739,"avatar_url":"https://avatars.githubusercontent.com/u/631739?v=3","gravatar_id":"","url":"https://api.github.com/users/SandroMachado","html_url":"https://github.com/SandroMachado","followers_url":"https://api.github.com/users/SandroMachado/followers","following_url":"https://api.github.com/users/SandroMachado/following{/other_user}","gists_url":"https://api.github.com/users/SandroMachado/gists{/gist_id}","starred_url":"https://api.github.com/users/SandroMachado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SandroMachado/subscriptions","organizations_url":"https://api.github.com/users/SandroMachado/orgs","repos_url":"https://api.github.com/users/SandroMachado/repos","events_url":"https://api.github.com/users/SandroMachado/events{/privacy}","received_events_url":"https://api.github.com/users/SandroMachado/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-03T18:09:48Z","updated_at":"2015-05-04T02:22:59Z","closed_at":"2015-05-04T02:22:59Z","pull_request":{"url":"https://api.github.com/repos/square/retrofit/pulls/831","html_url":"https://github.com/square/retrofit/pull/831","diff_url":"https://github.com/square/retrofit/pull/831.diff","patch_url":"https://github.com/square/retrofit/pull/831.patch"},"body":"This pull request adds promises support to the retrofit.\r\n\r\nWhy promises support?  Mainly, because the power of chaining multiple of them together. With multiple promises in chaining we can have one single point to handle the errors and to execute the final operation. \r\n```java\r\npromise.then(....).then(...).then(...).fail(....).fin(...)\r\n```\r\nThe library of promises used was: https://github.com/darylteo/rxjava-promises\r\n\r\nFor the example project, the code adapted to the promises is:\r\n\r\n```java\r\npublic class GitHubClient {\r\n\r\n    private static final String API_URL = \"https://api.github.com\";\r\n\r\n    static class Contributor {\r\n        String login;\r\n        int contributions;\r\n    }\r\n\r\n    interface GitHub {\r\n        @GET(\"/repos/{owner}/{repo}/contributors\")\r\n        RetrofitPromise<List<Contributor>> contributors(\r\n                @Path(\"owner\") String owner,\r\n                @Path(\"repo\") String repo\r\n        );\r\n    }\r\n\r\n    public static void main(String... args) {\r\n        // Create a very simple REST adapter which points the GitHub API endpoint.\r\n        RestAdapter restAdapter = new RestAdapter.Builder()\r\n                .endpoint(API_URL)\r\n                .build();\r\n\r\n        // Create an instance of our GitHub API interface.\r\n        GitHub github = restAdapter.create(GitHub.class);\r\n\r\n        // Fetch and print a list of the contributors to this library.\r\n        RetrofitPromise<List<Contributor>> promise = github.contributors(\"square\", \"retrofit\");\r\n        promise.then(new PromiseAction<List<Contributor>>() {\r\n            @Override\r\n            public void call(List<Contributor> contributors) {\r\n                for (Contributor contributor : contributors) {\r\n                    System.out.println(contributor.login + \" (\" + contributor.contributions + \")\");\r\n                }\r\n            }\r\n        }).fail(new PromiseAction<Exception>() {\r\n            @Override\r\n            public void call(Exception e) {\r\n\r\n            }\r\n        });\r\n    }\r\n\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/square/retrofit/issues/comments/98568437","html_url":"https://github.com/square/retrofit/pull/831#issuecomment-98568437","issue_url":"https://api.github.com/repos/square/retrofit/issues/831","id":98568437,"user":{"login":"JakeWharton","id":66577,"avatar_url":"https://avatars.githubusercontent.com/u/66577?v=3","gravatar_id":"","url":"https://api.github.com/users/JakeWharton","html_url":"https://github.com/JakeWharton","followers_url":"https://api.github.com/users/JakeWharton/followers","following_url":"https://api.github.com/users/JakeWharton/following{/other_user}","gists_url":"https://api.github.com/users/JakeWharton/gists{/gist_id}","starred_url":"https://api.github.com/users/JakeWharton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JakeWharton/subscriptions","organizations_url":"https://api.github.com/users/JakeWharton/orgs","repos_url":"https://api.github.com/users/JakeWharton/repos","events_url":"https://api.github.com/users/JakeWharton/events{/privacy}","received_events_url":"https://api.github.com/users/JakeWharton/received_events","type":"User","site_admin":false},"created_at":"2015-05-04T02:22:59Z","updated_at":"2015-05-04T02:22:59Z","body":"> Why promises support? Mainly, because the power of chaining multiple of them together. With multiple promises in chaining we can have one single point to handle the errors and to execute the final operation.\r\n\r\nWe already support RxJava `Observable` for this style of chaining which not only allows you to achieve the same effect, but has composition operations which are much more powerful than those offered by that promises library. It also is much more widely used library to build on than this specific promises library–the latter of which actually is built on RxJava. I'm not sure why the library doesn't just accept an `Observable` if it's based on RxJava.\r\n\r\nAs a potential consolation, we're looking at a pluggable mechanism for people to provide their own wrapper around execution which would allow you add support for this promises library without modifying Retrofit itself. See #817. "}}