This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Migration guide
Ryan Feline edited this page May 31, 2017
·
7 revisions
Below is a sample usage of Merlin pre v1 release.
merlin = new Merlin.Builder()
.setEndPoint("http://google.com")
.setResponseCodeValidator(new ResponseCodeValidator() {
@Override
public boolean isResponseCodeValid(int responseCode) {
return true;
}
}).withAllCallbacks()
.withLogging(true)
.build(this);
merlin.registerConnectable(new Connectable() {
@Override
public void onConnect() {
Log.e(getClass().getSimpleName(), "onConnect");
}
});
merlin.registerBindable(new Bindable() {
@Override
public void onBind(NetworkStatus networkStatus) {
Log.e(getClass().getSimpleName(), "onBind");
}
});
merlin.registerDisconnectable(new Disconnectable() {
@Override
public void onDisconnect() {
Log.e(getClass().getSimpleName(), "onDisconnect");
}
});
Below is the migration of the above code to post v1 Merlin.
merlin = new Merlin.Builder()
.withEndpoint(Endpoint.from("http://google.com"))
.withResponseCodeValidator(new ResponseCodeValidator() {
@Override
public boolean isResponseCodeValid(int responseCode) {
return true;
}
}).withAllCallbacks()
.build(this);
Logger.attach(new DemoLogHandle());
merlin.registerConnectable(new Connectable() {
@Override
public void onConnect() {
Log.e(getClass().getSimpleName(), "onConnect");
}
});
merlin.registerBindable(new Bindable() {
@Override
public void onBind(NetworkStatus networkStatus) {
Log.e(getClass().getSimpleName(), "onBind");
}
});
merlin.registerDisconnectable(new Disconnectable() {
@Override
public void onDisconnect() {
Log.e(getClass().getSimpleName(), "onDisconnect");
}
});
}
private static class DemoLogHandle implements Logger.LogHandle {
private static final String TAG = "DemoLogHandle";
@Override
public void v(Object... message) {
Log.v(TAG, message[0].toString());
}
// ... Methods omitted for brevity.
@Override
public void i(Object... message) {
Log.i(TAG, message[0].toString());
}
}
- All builder methods have been rewritten to follow the format
with[ComponentToBuildWith]
.-
setEndPoint
->withEndpoint
-
setResponseCodeValidator
->withResponseCodeValidator
-
-
Endpoint
to enforce type safety on theHostPinger
. Clients now need to pass anEndpoint
to thewithEndpoint
builder call. -
Introduction of a
Logger
to which clients can specify aLogHandle
dictating where all instances ofMerlin
will Log to.
Modules for RxJava1
and RxJava2
, clients are no longer forced to include these
dependencies as part of their build process. Clients can now add these optional
dependencies to the build.gradle
file in addition to the standard Merlin
dependency.
compile 'com.novoda:merlin-rxjava:[version_number]'
compile 'com.novoda:merlin-rxjava2:[version_number]'