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 Contributor { | |
| String login; | |
| String html_url; | |
| int contributions; | |
| @Override | |
| public String toString() { | |
| return login + " (" + contributions + ")"; |
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 GitHubService { | |
| @GET(“repos/{owner}/{repo}/contributors”) | |
| Call<List<Contributor>> repoContributors( | |
| @Path(“owner”) String owner, | |
| @Path(“repo”) String repo); | |
| } |
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
| interface GitHubService { | |
| @GET("repos/{owner}/{repo}/contributors") | |
| Call<List<Contributor>> repoContributors( | |
| @Path("owner") String owner, | |
| @Path("repo") String repo); | |
| public static final Retrofit retrofit = new Retrofit.Builder() | |
| .baseUrl("https://api.github.com/") | |
| .addConverterFactory(GsonConverterFactory.create()) |
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
| GitHubService gitHubService = GitHubService.retrofit.create(GitHubService.class); | |
| Call<List<Contributor>> call = gitHubService.repoContributors(“square”, “retrofit”); | |
| List<Contributor> result = call.execute().body(); |
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
| call.enqueue(new Callback<List<Contributor>>() { | |
| @Override | |
| public void onResponse(Response<List<Contributor>> response, Retrofit retrofit) { | |
| // handle success | |
| } | |
| @Override | |
| public void onFailure(Throwable t) { | |
| // handle failure | |
| } |
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
| <Button | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="Fetch" | |
| android:id="@+id/button" | |
| android:layout_alignParentBottom="true" | |
| android:layout_centerHorizontal="true" | |
| android:layout_marginBottom="151dp" /> | |
| <TextView |
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
| Button button = (Button) findViewById(R.id.button); | |
| button.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| GitHubService gitHubService = GitHubService.retrofit.create(GitHubService.class); | |
| Call<List<Contributor>> call = gitHubService.repoContributors(“square”, “retrofit”); | |
| String result = call.execute().body().toString(); | |
| TextView textView = (TextView) findViewById(R.id.textView); | |
| textView.setText(result); | |
| } |
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
| private class NetworkCall extends AsyncTask<Call, Void, String> { | |
| @Override | |
| protected String doInBackground(Call… params) { | |
| try { | |
| Call<List<Contributor>> call = params[0]; | |
| Response<List<Contributor>> response = call.execute(); | |
| return response.body().toString(); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } |
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
| Button button = (Button) findViewById(R.id.button); | |
| button.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| GitHubService gitHubService = GitHubService.retrofit.create(GitHubService.class); | |
| final Call<List<Contributor>> call = gitHubService.repoContributors("square", "retrofit"); | |
| new NetworkCall().execute(call); | |
| } | |
| }); |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width" /> | |
| <title>Hello World</title> | |
| </head> | |
| <body> | |
| <div id="container"></div> |