Skip to content

Instantly share code, notes, and snippets.

View naturalwarren's full-sized avatar
🎯
Focusing

Warren Smith naturalwarren

🎯
Focusing
  • Waterloo Canada
View GitHub Profile
@naturalwarren
naturalwarren / Rider.java
Last active May 26, 2017 20:42
Rider Model with Nullness Annotations
public class Rider {
@NonNull private String firstName;
@NonNull private String lastName;
public Rider(@NonNull String firstname, @NonNull String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@naturalwarren
naturalwarren / UsingRave.java
Last active April 2, 2017 21:54
Demonstrates how to use RAVE
public class UsingRave {
public static void main(String[] args) {
MyModel myModel = new MyModel(“Validate me please!”);
try {
Rave.getInstance().validate(myModel);
} catch (RaveException e) {
// This response didn't pass RAVE validation, throw an exception.
throw new RuntimeException(e);
}
}
/**
* A converter factory that uses Rave to validate responses from the network. In the event that a response doesn't
* validate an exception is thrown to consumers.
*
* NOTE: This is a forwarding converter that delegates to another converter that should convert Java Objects
* into JSON and back. This converter must registered to your Retrofit instance before any other converter it might
* delegate to.
*/
final class RaveConverterFactory extends Converter.Factory {
@naturalwarren
naturalwarren / NetworkException.java
Last active July 28, 2022 10:47
Retrofit 2 CallAdapterFactory that Wraps Network Errors
package com.uber.retrofit2.adapters.network.exception;
import android.support.annotation.NonNull;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Request;