NetworkProxy

Additional

Language
Java
Version
N/A
Created
Dec 8, 2018
Updated
Jan 16, 2019
Owner
Quan Vu (nongdenchet)
Contributors
Quan Vu (nongdenchet)
quanvu7
2
Activity
Badge
Generate
Download
Source code
APK file

Promotion

NetworkProxy

A network proxy library to intercept and mock response from OkHttp

Getting started

In your root build.gradle:

allprojects {
    repositories {
        // Other configurations
        maven { url 'https://dl.bintray.com/nongdenchet/maven' }
    }
}

In your app/build.gradle:

dependencies {
  debugImplementation 'com.github.nongdenchet:networkproxy:0.2.2'
  releaseImplementation 'com.github.nongdenchet:networkproxy-no-op:0.2.2'
}

In your Application class:

public class ExampleApplication extends Application {

  @Override public void onCreate() {
    super.onCreate();
    NetworkProxy.init(this);
    // Normal app init code...
  }
}

Add the Interceptor to your OkHttp builder:

new OkHttpClient.Builder()
  // other configuration...
  .addInterceptor(NetworkProxy.interceptor())
  // other configuration...
  .build();

To mock data from a pending response

adb shell "am broadcast -a com.rain.networkproxy.INSTRUCTION -n [YOUR_APP_PACKAGE]/com.rain.networkproxy.NPReceiver \
    --es data '{"id": "0", "status": 200}' \
    --es body '"'{"id": 1, "title": "hello"}'"'"

"id": "0" is the pending response id. You can get it through the UI or from Logcat (Put NetworkProxy as filter to see the logs)

Demo

License

Copyright 2018 Quan Vu.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.