Skip to content

Instantly share code, notes, and snippets.

@ani03sha
Created August 9, 2018 19:33
Show Gist options
  • Save ani03sha/7c32b10b16d1a4a1d66c5f7e94e87559 to your computer and use it in GitHub Desktop.
Save ani03sha/7c32b10b16d1a4a1d66c5f7e94e87559 to your computer and use it in GitHub Desktop.
package org.redquark.retrofit.xmlparser.api;
import static org.redquark.retrofit.xmlparser.constants.AppConstants.URL;
import org.redquark.retrofit.xmlparser.model.Feed;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
/**
* @author Anirudh Sharma
*
*/
@SuppressWarnings("deprecation")
public class FeedController implements Callback<Feed> {
public void run() {
Retrofit retrofit = new Retrofit.Builder().baseUrl(URL).addConverterFactory(SimpleXmlConverterFactory.create())
.build();
RSSAPI rssapi = retrofit.create(RSSAPI.class);
Call<Feed> call = rssapi.getFeed();
call.enqueue(this);
}
public void onResponse(Call<Feed> call, Response<Feed> response) {
if (response.isSuccessful()) {
Feed feed = response.body();
System.out.println("Channel Title: " + feed.getChannelTitle());
System.out.println("----------------------------------------------\n");
feed.getArticleList().forEach(article -> System.out.println("Title: " + article.getTitle() + "\nLink: "
+ article.getLink() + "\n"));
} else {
System.out.println(response.errorBody());
}
}
public void onFailure(Call<Feed> call, Throwable t) {
t.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment