Skip to content

Instantly share code, notes, and snippets.

@nutchy
Last active October 15, 2017 16:04
Show Gist options
  • Save nutchy/261e963f6980c8ecff6f9a2413ab6462 to your computer and use it in GitHub Desktop.
Save nutchy/261e963f6980c8ecff6f9a2413ab6462 to your computer and use it in GitHub Desktop.
[MyLazyInstagram] - MainActivity.java
public class MainActivity extends AppCompatActivity {
public OkHttpClient client;
public Retrofit retrofit;
public LazyInstagramApi lazyInstagramApi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lazyinstagram_main);
getConnection();
getContentByName("cartoon");
}
public void getConnection(){
client = new OkHttpClient.Builder().build();
retrofit = new Retrofit
.Builder()
.baseUrl(LazyInstagramApi.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
lazyInstagramApi = retrofit.create(LazyInstagramApi.class);
}
private void getContentByName(String userName){
Call<UserProfile> call = lazyInstagramApi.getProfile(userName);
call.enqueue(new Callback<UserProfile>() {
@Override
public void onResponse(Call<UserProfile> call, Response<UserProfile> response) {
if (response.isSuccessful()){
// Mapping to Model
UserProfile userProfile = response.body();
}
}
@Override
public void onFailure(Call<UserProfile> call, Throwable t) {
System.out.println("Connect API FAILED");
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment