Skip to content

Commit

Permalink
update gradle extra value
Browse files Browse the repository at this point in the history
update post file
add network Interceptor
user can check log with details
update readme file
  • Loading branch information
alishatergholi committed Feb 20, 2019
1 parent 936447c commit 99f4224
Show file tree
Hide file tree
Showing 20 changed files with 400 additions and 591 deletions.
6 changes: 6 additions & 0 deletions .idea/kotlinScripting.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ download
Gradle
latest version on jitpack [![](https://jitpack.io/v/alishatergholi/RestClient.svg)](https://jitpack.io/#alishatergholi/RestClient)
```groovy
repositories{
maven { url 'https://jitpack.io' }
}
//java version required
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
implementation 'com.github.alishatergholi:rest-client:latest_version'
implementation 'com.github.alishatergholi:rest-client:[latest_version](https://github.com/vaslco/vaslAppSdk/releases/latest)'
}
```




How do i use RestClient
=======================
```java
Expand Down
16 changes: 8 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ plugins {
}

android {
compileSdkVersion(28)
compileSdkVersion(rootProject.extra.get("compileSdk") as Int)
defaultConfig {
minSdkVersion(15)
targetSdkVersion(28)
buildToolsVersion = "28.0.3"
versionCode = 8
versionName = "1.0.8"
minSdkVersion(rootProject.extra.get("minSdk") as Int)
targetSdkVersion(rootProject.extra.get("targetSdk") as Int)
buildToolsVersion = rootProject.extra.get("buildTools") as String
versionCode = rootProject.extra.get("version_code") as Int
versionName = rootProject.extra.get("version_name") as String
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -27,9 +27,9 @@ android {
dependencies {
implementation(fileTree(mapOf("include" to listOf("*.jar"), "dir" to "libs")))
implementation("androidx.appcompat:appcompat:1.0.2")
implementation("com.github.alishatergholi:rest-client:v1.0.9")
//implementation("com.github.alishatergholi:rest-client:v1.0.9")
testImplementation("junit:junit:4.12")
// implementation(project(":library"))
implementation(project(":library"))
androidTestImplementation("androidx.test:runner:1.1.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.1.1")
}
Expand Down
28 changes: 10 additions & 18 deletions app/src/main/java/com/github/restclient/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@


import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONObject;

import androidx.appcompat.app.AppCompatActivity;
import androidx.collection.ArrayMap;

import com.github.library.RestClient;

import com.github.library.enums.AuthType;

import com.github.library.enums.RequestBodyType;
import com.github.library.response.ResponseJsonHandler;
import com.github.library.utils.RequestParams;

import androidx.appcompat.app.AppCompatActivity;
import androidx.collection.ArrayMap;


public class MainActivity extends AppCompatActivity {

Expand All @@ -34,25 +30,19 @@ protected void onCreate(Bundle savedInstanceState) {

findViewById(R.id.text).setOnClickListener(view -> {
RequestParams params = new RequestParams(RequestBodyType.FormData);
params.put("page", "1");


restClient.POST("https://google.com",
restClient.POST("https://sandbox.vaslapp.com",
"",
new RequestParams(),
new ResponseJsonHandler() {

@Override
protected void onSuccess(String result) {
Log.d(TAG, "response " + result);
}

@Override
public void onFailure(int errorCode, String errorMsg) {
Log.d(TAG, "onFailure " + errorMsg);
}
}
);
});
});
}

Expand All @@ -62,8 +52,10 @@ private void initRestClient() {
header.put("accept-language", "en");

restClient = new RestClient.Builder(this)
.setAuthorization("http://sandbox.vaslapp.com/oauth/token",
"c3bdf6c5-508f-48ae-9af4-243a24072e31", "LnDbEo3yDDcswKMC3h4H", AuthType.BASIC_AUTH)
.setAuthorization("https://sandbox.vaslapp.com/oauth/token",
"c3bdf6c5-508f-48ae-9af4-243a24072e31",
"LnDbEo3yDDcswKMC3h4H",
AuthType.BASIC_AUTH)
.setUserInfo("android-XoaM8ODAYVcKnB16ob8N", "DOI0qOIa0KT6ViYmS1k6")
.setHeader(header)
.build();
Expand Down
18 changes: 18 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

extra.set("kotlinVersion" , "1.3.20")
extra.set("minSdk" , 15)
extra.set("compileSdk" , 28)
extra.set("targetSdk" , 28)
extra.set("buildTools" , "28.0.3")
extra.set("version_code" , 10)
extra.set("version_name" , "1.1.0")

repositories {
google()
jcenter()
Expand All @@ -11,15 +20,24 @@ buildscript {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
// Define versions in a single place
extra.apply{
set("minSdkVersion", 26)
set("targetSdkVersion", 27)
}

}



allprojects {
repositories {
google()
jcenter()
maven("https://jitpack.io")
}


}

task<Delete>("clean") {
Expand Down
19 changes: 10 additions & 9 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ plugins {
}

group = "com.github.rest-client"
version = "1.0.9"
version = rootProject.extra.get("version_name")!!

android {
compileSdkVersion(28)
compileSdkVersion(rootProject.extra.get("compileSdk") as Int)
defaultConfig {
minSdkVersion(15)
targetSdkVersion(28)
buildToolsVersion = "28.0.3"
versionCode = 9
versionName = "1.0.9"
minSdkVersion(rootProject.extra.get("minSdk") as Int)
targetSdkVersion(rootProject.extra.get("targetSdk") as Int)
buildToolsVersion = rootProject.extra.get("buildTools") as String
versionCode = rootProject.extra.get("version_code") as Int
versionName = rootProject.extra.get("version_name") as String
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -34,11 +34,12 @@ android {

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.20")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${rootProject.extra.get("kotlinVersion")}")
implementation("androidx.appcompat:appcompat:1.0.2")
implementation("com.squareup.okhttp3:okhttp:3.12.0")
//implementation("androidx.annotation:annotation:1.0.1")

testImplementation("junit:junit:4.12")
androidTestImplementation("androidx.test:runner:1.1.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.1.1")

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.github.library;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import static org.junit.Assert.assertEquals;

/**
* Instrumented test, which will execute on an Android device.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@



import com.github.library.enums.ErrorCode;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;


import com.github.library.enums.ErrorCode;
import com.github.library.helper.LogHelper;

import okhttp3.Response;
import okhttp3.ResponseBody;

Expand All @@ -22,11 +20,9 @@
*/
public abstract class ResultHandler {

protected LogHelper logHelper = new LogHelper(ResultHandler.class);

public void onResultHandler(long startTime,Response response){
public void onResultHandler(Response response){
String url = response.request().url().url().toString();
if (response.body() != null && response.body().source() != null && response.isSuccessful()) {
if (response.body() != null && response.isSuccessful()) {
InputStream inputStream = null;
String contentEncodingHeader = response.header("Content-Encoding");
ResponseBody body = response.body();
Expand All @@ -35,7 +31,7 @@ public void onResultHandler(long startTime,Response response){
try {
inputStream = new GZIPInputStream(body.byteStream());
} catch (IOException e) {
this.onFailure(url,startTime,ErrorCode.IOException);
this.onFailure(url,ErrorCode.IOException);
}
} else {
inputStream = body.byteStream();
Expand All @@ -51,28 +47,28 @@ public void onResultHandler(long startTime,Response response){
outputStream.flush();
byte[] result = outputStream.toByteArray();
outputStream.close();
this.onSuccess(url,startTime,result);
this.onSuccess(url,result);
} catch (IOException e) {
this.onFailure(url,startTime,ErrorCode.IOException);
this.onFailure(url,ErrorCode.IOException);
}
}else {
this.onFailure(url,startTime,ErrorCode.ParseException);
this.onFailure(url,ErrorCode.ParseException);
}
} else {
this.onFailure(url,startTime,ErrorCode.NullPointerException);
this.onFailure(url,ErrorCode.NullPointerException);
}
} else {
this.onFailure(url,startTime,ErrorCode.Parse(response.code()));
this.onFailure(url,ErrorCode.Parse(response.code()));
}
}

protected abstract void onSuccess(String url,long startTime,byte[] result);
protected abstract void onSuccess(String url,byte[] result);

public void onProgress(double percent,long bytesWritten,long totalSize){

}

public abstract void onFailure(String url,long startTime,ErrorCode errorCode);
public abstract void onFailure(String url,ErrorCode errorCode);

protected static String calcTime(Long startTime) {
Long duration = getTimeMillisecond() - startTime;
Expand Down
Loading

0 comments on commit 99f4224

Please sign in to comment.