- Android version 4.0 (
android:minSdkVersion="14"
)
-
Download and add the source code to your project. Notethat this library does not require additional dependencies.
-
Include this line in your app’s AndroidManifest.xml to allow Internet access
<uses-permission android:name="android.permission.INTERNET" />
- In order to use optional network state checks, this library uses the NetworkInfo api. This requires the following permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
You can find proguard rules for Taboola LightNetwork in proguard-rules.pro file.
At this moment just add the following line:
-keep class com.taboola.lightnetwork.** { *; }
This program is licensed under the Apache 2.0 License Agreement (the “License Agreement”). By copying, using or redistributing this program, you agree with the terms of the License Agreement. The full text of the license agreement can be found at https://github.com/taboola/LightNetwork/blob/master/LICENSE. Copyright 2019 Taboola, Inc. All rights reserved.
- Define a network interface
public interface SampleNetworkApi {
@GET("http://www.example.com/")
public DynamicRequest sampleNetworkRequest1();
@POST("https://www.example.com/")
public DynamicRequest sampleNetworkRequest2();
}
- Create a DynamicRequest object out of that interface
// Define NetworkExecutable instance
NetworkExecutable networkExecutable = new NetworkExecutable(<networkManager>);
// Create network object
SampleNetworkApi sampleNetworkApi = networkExecutable.create(SampleNetworkApi.class);
// Access network API synchronously
sampleNetworkApi.sampleNetworkRequest1.execute();
// Access network API using a NetworkResponse callback
sampleNetworkApi.sampleNetworkRequest2.execute(new NetworkResponse(){..});
public interface SampleNetworkApi {
DynamicRequest sampleNetworkRequest1();
DynamicRequest sampleNetworkRequest2();
}
- Request definition tags
3.1. Using Available Protocols:
Currently all requests can either be Http Get or Http Post. To define the protocol, put the relevant annotation on top of defined method in your interface.
@GET - Perform HTTP GET request.
@GET("http://www.example.com/{mee}/{yaoo}")
@POST - Perform POST request.
@POST("https://postman-echo.com/post")
3.2. Using Available Annotations:
@Path - Replace path parameter in url.
@GET("http://www.example.com/{mee}/{yaoo}")
DynamicRequest getA(@Path("mee") String mee, @Path("yaoo") String yaoo);
@Query - Add key=value query pair in url.
@GET("https://www.example.com/")
DynamicRequest getB(@Query("hai") String ya);
@Body - Add JSONObject body to a POST request.
@POST("https://postman-echo.com/post")
DynamicRequest postA(@Body JSONObject jsonBody);