Skip to content

Instantly share code, notes, and snippets.

View rhari991's full-sized avatar

Harikrishnan Rajan rhari991

View GitHub Profile
@rhari991
rhari991 / NewPasteExample.class
Created February 7, 2018 04:51
An example of calling a Retrofit interface
NewPasteParameters parameters = new NewPasteParameters.Builder("Random Text")
.title("Random title")
.visibility(Visibility.PUBLIC)
.build();
Call<ReturnType> call = apiService.createNewPaste(parameters);
@rhari991
rhari991 / NewPasteParametersConverter.java
Created February 7, 2018 04:36
An example of a custom request converter for Retrofit
class NewPasteParametersConverter implements Converter<NewPasteParameters, RequestBody> {
@Override
public RequestBody convert(NewPasteParameters value) throws IOException {
FormBody.Builder requestBodyBuilder = new FormBody.Builder()
.add("api_paste_code", value.getText());
if (value.getTitle() != null) {
requestBodyBuilder.add("api_paste_name", value.getTitle());
}
@rhari991
rhari991 / NewPasteParameters.java
Created February 7, 2018 04:27
An example of the builder pattern in Java
public class NewPasteParameters {
private final String text;
private final String title;
private final Format format;
private final Visibility visibility;
private final ExpiryDate expiryDate;
private NewPasteParameters(String text, String title, Format format, Visibility visibility, ExpiryDate expiryDate) {
this.text = text;
@rhari991
rhari991 / FieldMapUsageExample.java
Created February 6, 2018 16:06
Sample usage of @fieldmap option for the Retrofit library
public interface ApiService {
@FormUrlEncoded
@POST("/endpoint")
Call<ReturnType> method(@FieldMap Map<String, String> fields);
}
public void sampleUsage {
Map<String, String> map = new HashMap<>();
@rhari991
rhari991 / AllArgumentCombinations.java
Created February 6, 2018 15:41
A sample way to define a Retrofit interface for multiple required and optional request arguments
public interface MyApiService {
public Call<String> method(String requiredArgument1);
public Call<String> method(String requiredArgument1, String optionalArgument1);
public Call<String> method(String requiredArgument1, String optionalArgument1, String optionalArgument2);
//Add every possible combination of arguments
}
@rhari991
rhari991 / PasteListExample.xml
Created February 4, 2018 22:22
A sample response for the trending pastes endpoint of the Pastebin API
<paste>
<paste_key>4eWYATXe</paste_key>
<paste_date>1319458935</paste_date>
<paste_title>577 French MPs</paste_title>
<paste_size>29397</paste_size>
<paste_expire_date>0</paste_expire_date>
<paste_private>0</paste_private>
<paste_format_long>None</paste_format_long>
<paste_format_short>text</paste_format_short>
<paste_url>https://pastebin.com/4eWYATXe</paste_url>
@rhari991
rhari991 / PasteListConverter.java
Created February 1, 2018 05:24
An example of a custom response converter for Retrofit
class PasteListConverter implements Converter<ResponseBody, List<Paste>> {
private final Serializer serializer;
PasteListConverter() {
serializer = new Persister(new AnnotationStrategy());
}
@Override
public List<Paste> convert(ResponseBody value) throws IOException {
@rhari991
rhari991 / improve_imap_related_features_report.md
Created August 29, 2017 13:25
GSoC 2017 final report for K-9 Mail / Improve IMAP-related features