Skip to content

Instantly share code, notes, and snippets.

@rhari991
Created February 7, 2018 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhari991/3e961f3f9797d69706ee4176ddda44e9 to your computer and use it in GitHub Desktop.
Save rhari991/3e961f3f9797d69706ee4176ddda44e9 to your computer and use it in GitHub Desktop.
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());
}
if (value.getFormat() != null) {
requestBodyBuilder.add("api_paste_format", value.getFormat().toString());
}
if (value.getVisibility() != null) {
requestBodyBuilder.add("api_paste_private", value.getVisibility().toString());
}
if (value.getExpiryDate() != null) {
requestBodyBuilder.add("api_paste_expire_date", value.getExpiryDate().toString());
}
return requestBodyBuilder.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment