From 90321be1da5d4cc3d7c6074afbd56c49070052f2 Mon Sep 17 00:00:00 2001 From: AMIT SHEKHAR Date: Fri, 16 Sep 2016 01:07:33 +0530 Subject: [PATCH] examples added --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 23c23700..811cd44f 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Fast Android Networking Library supports Android 2.3 (Gingerbread) and later. Add this in your build.gradle ```groovy -compile 'com.amitshekhar.android:android-networking:0.1.0' +compile 'com.amitshekhar.android:android-networking:0.2.0' ``` Do not forget to add internet permission in manifest if already not present ```xml @@ -57,6 +57,15 @@ OkHttpClient okHttpClient = new OkHttpClient() .newBuilder() .build(); AndroidNetworking.initialize(getApplicationContext(),okHttpClient); ``` +Using the Fast Android Networking with Jackson Parser +```groovy +compile 'com.amitshekhar.android:jackson-android-networking:0.2.0' +``` +```java +// Then set the JacksonParserFactory like below +AndroidNetworking.setParserFactory(new JacksonParserFactory()); +``` + If you are using proguard, then add this rule in proguard-project.txt ``` -dontwarn okio.** @@ -477,6 +486,39 @@ AndroidNetworking.download(url,dirPath,fileName) }); Note : If bytesSent or bytesReceived is -1 , it means it is unknown ``` +### Getting OkHttpResponse in Response +```java +AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAnUserDetail/{userId}") + .addPathParameter("userId", "1") + .setTag(this) + .setPriority(Priority.LOW) + .setUserAgent("getAnUser") + .build() + .getAsOkHttpResponseAndParsed(new TypeToken() { + }, new OkHttpResponseAndParsedRequestListener() { + @Override + public void onResponse(Response okHttpResponse, User user) { + // do anything with okHttpResponse and user + } + @Override + public void onError(ANError anError) { + // handle error + } + }); +``` +### Making Synchronous Request +```java +ANRequest request = AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllUsers/{pageNumber}") + .addPathParameter("pageNumber", "0") + .addQueryParameter("limit", "3") + .build(); +ANResponse> response = request.executeForParsed(new TypeToken>() {}); +if (response.isSuccess()) { + List users = responseTwo.getResult(); +} else { + //handle error +} +``` ### How caching works ? * First of all the server must send cache-control in header so that is starts working. * Response will be cached on the basis of cache-control max-age,max-stale.