{"id":218355,"date":"2014-04-05T14:24:03","date_gmt":"2014-04-05T10:24:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=218355"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=218355","title":{"rendered":"<span class=\"post_title\">\u041f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0434\u043b\u044f Android \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 #Square \u0427\u0430\u0441\u0442\u044c 1<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       \u041d\u0430 \u044d\u0442\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0438 \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043f\u043e\u0441\u0432\u0435\u0449\u0435\u043d \u043e\u043d \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Square Inc, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0442 \u043d\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \ud83d\ude42<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2><a href=\"http:\/\/square.github.io\/retrofit\/\">Retrofit<\/a><\/h2>\n<p>  \u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 REST API \u0441\u0435\u0440\u0432\u0438\u0441 \u0432 Java Interface<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"java\">public interface GitHubService {   @GET(&quot;\/users\/{user}\/repos&quot;)   List&lt;Repo&gt; listRepos(@Path(&quot;user&quot;) String user); } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e RestAdapter \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0432\u0430\u0448\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c.  <\/p>\n<pre><code class=\"java\">RestAdapter restAdapter = new RestAdapter.Builder()     .setEndpoint(&quot;https:\/\/api.github.com&quot;)     .build();  GitHubService service = restAdapter.create(GitHubService.class); <\/code><\/pre>\n<p>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u0432 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e GitHubService \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c HTTP \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440  <\/p>\n<pre><code class=\"java\">List&lt;Repo&gt; repos = service.listRepos(&quot;octocat&quot;);<\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u0430\u0448\u0438\u0445 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432  <\/p>\n<ul>\n<li>\u041f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432 URL \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 <\/li>\n<li>\u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430(JSON, Protocol buffers)<\/li>\n<li>\u041c\u0443\u043b\u044c\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0444\u0430\u0439\u043b\u043e\u0432<\/li>\n<\/ul>\n<h3>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 API<\/h3>\n<p>  \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0432 \u0432\u0430\u0448\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/p>\n<h4>\u041c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h4>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d, \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u0442\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e 5 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439<br \/>  GET, POST, PUT, DELETE \u0438 HEAD. \u0421\u0441\u044b\u043b\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430 \u0432\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u0430\u0448\u0435\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438  <\/p>\n<pre><code class=\"java\">@GET(&quot;\/users\/list&quot;)<\/code><\/pre>\n<p>  \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u0438\u043c\u0438\u043a\u043e\u043c \u0438\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439  <\/p>\n<pre><code class=\"java\">@GET(&quot;\/users\/list?sort=desc&quot;)<\/code><\/pre>\n<p>  <\/p>\n<h4>\u041c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u044f \u0441 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438<\/h4>\n<p>  \u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u043d\u043e\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u0447\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445. \u041f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u0447\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044b \u0432 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438, \u043f\u0440\u0438\u043c\u0435\u0440: {id}, \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430 <a href=\"http:\/\/habrahabr.ru\/users\/path\/\" class=\"user_link\">Path<\/a>  <\/p>\n<pre><code class=\"java\">@GET(&quot;\/group\/{id}\/users&quot;) List&lt;User&gt; groupList(@Path(&quot;id&quot;) int groupId); <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b   <\/p>\n<pre><code class=\"java\">@GET(&quot;\/group\/{id}\/users&quot;) List&lt;User&gt; groupList(@Path(&quot;id&quot;) int groupId, @Query(&quot;sort&quot;) String sort); <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <a href=\"http:\/\/habrahabr.ru\/users\/map\/\" class=\"user_link\">Map<\/a>  <\/p>\n<pre><code class=\"java\">@GET(&quot;\/group\/{id}\/users&quot;) List&lt;User&gt; groupList(@Path(&quot;id&quot;) int groupId, @QueryMap Map&lt;String, String&gt; options); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438<\/h4>\n<p>  \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u0442\u0435\u043b\u043e HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <a href=\"http:\/\/habrahabr.ru\/users\/body\/\" class=\"user_link\">Body<\/a>  <\/p>\n<pre><code class=\"java\">@POST(&quot;\/users\/new&quot;) void createUser(@Body User user, Callback&lt;User&gt; cb); <\/code><\/pre>\n<p>  \u0412\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u0432\u0430\u043c\u0438 RestAdapter&#8217;\u0441\u043a\u0438\u043c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0442\u043e\u0440\u043e\u043c (\u043e \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0432\u0435\u043b \u044f)<\/p>\n<p>  <\/p>\n<h4>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0444\u043e\u0440\u043c<\/h4>\n<p>  \u0412\u0430\u0448\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432\u0432\u0438\u0434\u0435 \u0444\u043e\u0440\u043c\u044b<br \/>  \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u0444\u043e\u0440\u043c\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e @FormUrlEncoded \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439<br \/>  \u0438 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435 \u0444\u043e\u0440\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e @Field \u043e\u043c<\/p>\n<pre><code>@FormUrlEncoded @POST(&quot;\/user\/edit&quot;) User updateUser(@Field(&quot;first_name&quot;) String first, @Field(&quot;last_name&quot;) String last); <\/code><\/pre>\n<p>  Multipart(\u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0432\u0441\u0442\u0438) \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e @Multipart  <\/p>\n<pre><code>@Multipart @PUT(&quot;\/user\/photo&quot;) User updateUser(@Part(&quot;photo&quot;) TypedFile photo, @Part(&quot;description&quot;) TypedString description); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u044f \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438<\/h4>\n<p>  \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <a href=\"http:\/\/habrahabr.ru\/users\/header\/\" class=\"user_link\">Header<\/a>  <\/p>\n<pre><code>@Headers(&quot;Cache-Control: max-age=640000&quot;) @GET(&quot;\/widget\/list&quot;) List&lt;Widget&gt; widgetList(); <\/code><\/pre>\n<pre><code>@Headers({     &quot;Accept: application\/vnd.github.v3.full+json&quot;,     &quot;User-Agent: Retrofit-Sample-App&quot; }) @GET(&quot;\/users\/{username}&quot;) User getUser(@Path(&quot;username&quot;) String username); <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435* \u0437\u0430\u0433\u043e\u043b\u0432\u043a\u0438 \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u0412\u0441\u0435 \u0437\u0430\u0433\u043e\u043b\u0432\u043a\u0438 \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0438\u043c\u0435\u043d\u0435\u043d\u043c \u0431\u0443\u0434\u0443\u0442 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0441 \u0417\u0430\u0433\u043b\u043e\u0432\u043a\u043e\u043c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0441\u0435 \u0442\u043e\u0442 \u0436\u0435 <a href=\"http:\/\/habrahabr.ru\/users\/header\/\" class=\"user_link\">Header<\/a>, \u0441\u0442\u0440\u043e\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Null \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c<\/p>\n<pre><code>@GET(&quot;\/user&quot;) void getUser(@Header(&quot;Authorization&quot;) String authorization, Callback&lt;User&gt; callback) <\/code><\/pre>\n<p>  \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b \u0432 RequestInterceptor, \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 RequestInterceptor \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 User-Agent \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/p>\n<pre><code>RequestInterceptor requestInterceptor = new RequestInterceptor() {   @Override   public void intercept(RequestFacade request) {     request.addHeader(&quot;User-Agent&quot;, &quot;Retrofit-Sample-App&quot;);   } };  RestAdapter restAdapter = new RestAdapter.Builder()   .setEndpoint(&quot;https:\/\/api.github.com&quot;)   .setRequestInterceptor(requestInterceptor)   .build(); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 vs \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 vs Observable<\/h4>\n<p>  \u0412\u0430\u0448\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u0434\u0435\u043a\u043b\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0438 \u0430\u0441\u0438\u0445\u0440\u043d\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438.<\/p>\n<p>  \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439  <\/p>\n<pre><code>@GET(&quot;\/user\/{id}\/photo&quot;) Photo getUserPhoto(@Path(&quot;id&quot;) int id); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439  <\/p>\n<pre><code>@GET(&quot;\/user\/{id}\/photo&quot;) void getUserPhoto(@Path(&quot;id&quot;) int id, Callback&lt;Photo&gt; cb); <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u043d\u0435\u0442\u044c \u0432 \u043a\u043e\u043d\u0446\u0435 Callback \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c<br \/>  \u0412 \u0430\u043d\u0434\u0440\u043e\u0438\u0434\u0435 Callback&#8217;\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u044b \u0432 UI \u043f\u043e\u0442\u043e\u043a\u0435. <\/p>\n<p>  Retrofit \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0441 <a href=\"https:\/\/github.com\/Netflix\/RxJava\/wiki\">RxJava<\/a> \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 rx.Observable  <\/p>\n<pre><code>@GET(&quot;\/user\/{id}\/photo&quot;) Observable&lt;Photo&gt; getUserPhoto(@Path(&quot;id&quot;) int id); <\/code><\/pre>\n<p>  Observable \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0442\u043e\u043a\u0435, \u0447\u0442\u043e \u0438 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u044b\u0437\u043e\u0432\u0438\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 observerOn(Scheduler) \u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u043c Observable<\/p>\n<p>  <\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0442\u0432\u0435\u0442\u043e\u0432<\/h4>\n<p>  HTTP \u043e\u0442\u0432\u0435\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0443\u043a\u0430\u0437\u043e\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f RestAdapter&#8217;\u043e\u0432\u0441\u043a\u0438\u0439 GSON \u043a\u043e\u0432\u0435\u0440\u0442\u043e\u0440. \u0423\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0438, \u0421allback \u0438\u043b\u0438 Observable  <\/p>\n<pre><code>@GET(&quot;\/users\/list&quot;) List&lt;User&gt; userList();  @GET(&quot;\/users\/list&quot;) void userList(Callback&lt;List&lt;User&gt;&gt; cb);  @GET(&quot;\/users\/list&quot;) Observable&lt;List&lt;User&gt;&gt; userList(); <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043a\u0430 \u043a \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u043c\u0443 \u043e\u0442\u0432\u0435\u0442\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435<\/p>\n<pre><code>@GET(&quot;\/users\/list&quot;) Response userList();  @GET(&quot;\/users\/list&quot;) void userList(Callback&lt;Response&gt; cb);  @GET(&quot;\/users\/list&quot;) Observable&lt;Response&gt; userList(); <\/code><\/pre>\n<p>  <\/p>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f RestAdapter<\/h3>\n<p>  \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u0430\u0448 RestAdapter, \u0441\u0431\u0438\u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \ud83d\ude09<\/p>\n<p>  <\/p>\n<h4>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 JSON \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u043e\u0440\u0430<\/h4>\n<p>  Retrofit \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e GSON \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 JSON \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0442\u0435\u043b\u043e HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0412\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0434 \u0441\u0432\u043e\u0438 \u043d\u0443\u0436\u0434\u044b<\/p>\n<pre><code>Gson gson = new GsonBuilder()     .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)     .registerTypeAdapter(Date.class, new DateTypeAdapter())     .create();  RestAdapter restAdapter = new RestAdapter.Builder()     .setEndpoint(&quot;https:\/\/api.github.com&quot;)     .setConverter(new GsonConverter(gson))     .build();  GitHubService service = restAdapter.create(GitHubService.class); <\/code><\/pre>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u0432 RestAdapter \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u043e\u0440\u043e\u043c<\/p>\n<p>  <\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432<\/h4>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Retrofit \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e Json. \u041d\u043e \u0442\u0430\u043a\u0436\u0435 \u0438 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 XML, \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 \u0441\u043f\u0438\u043e\u043a <a href=\"https:\/\/github.com\/square\/retrofit\/tree\/master\/retrofit-converters\">Retorfit-\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u043e\u0440\u043e\u0432<\/a><br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f XML \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u043e\u0440\u0430<\/p>\n<pre><code>RestAdapter restAdapter = new RestAdapter.Builder()     .setEndpoint(&quot;https:\/\/api.soundcloud.com&quot;)     .setConverter(new SimpleXMLConverter())     .build();  SoundCloudService service = restAdapter.create(SoundCloudService.class); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0431\u043e\u043a<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0441\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0448\u0438\u0431\u043e\u043a, \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442 \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 ErrorHandler, \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b \u043a\u043e\u0434 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u0432 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 401 \u043e\u0448\u0438\u0431\u043a\u0430<\/p>\n<pre><code>class MyErrorHandler implements ErrorHandler {   @Override public Throwable handleError(RetrofitError cause) {     Response r = cause.getResponse();     if (r != null && r.getStatus() == 401) {       return new UnauthorizedException(cause);     }     return cause;   } }  RestAdapter restAdapter = new RestAdapter.Builder()     .setEndpoint(&quot;https:\/\/api.github.com&quot;)     .setErrorHandler(new MyErrorHandler())     .build(); <\/code><\/pre>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \ud83d\ude09<\/p>\n<p>  <b>\u041c\u0443\u0437\u044b\u043a\u0430 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435:<\/b><br \/>  Lights &#038; Motion \u2014 The March<br \/>  Craig Wazbinski &#038; R.wali Vincent \u2014 Sideways<br \/>  The Family Crest \u2014 Make Me a Boat<br \/>  Ruth Barrett \u2014 Earthflow<br \/>  Ludovico Einaudi \u2014 Divenire<br \/>  Aron Wright \u2014 In the woods<br \/>  Earth Wind and Fire \u2014 September<br \/>  Anywayican \u2014 Walk The Moon<\/p>\n<h4>\u0410 \u043a\u0430\u043a\u0443\u044e \u043c\u0443\u0437\u044b\u043a\u0443 \u0441\u043b\u0443\u0448\u0430\u0435\u0442\u0435 \u0432\u044b?<\/h4>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/218355\/\"> http:\/\/habrahabr.ru\/post\/218355\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       \u041d\u0430 \u044d\u0442\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0438 \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043f\u043e\u0441\u0432\u0435\u0449\u0435\u043d \u043e\u043d \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Square Inc, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0442 \u043d\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \ud83d\ude42  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-218355","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/218355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=218355"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/218355\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=218355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=218355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=218355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}