Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
access request token
Request Params
add Delete and GET and PUT
add Response Handler in three different type
  • Loading branch information
alishatergholi committed Feb 2, 2019
1 parent ee78403 commit e2c4dd3
Show file tree
Hide file tree
Showing 62 changed files with 1,575 additions and 992 deletions.
Binary file added .idea/caches/gradle_models.ser
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

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

12 changes: 9 additions & 3 deletions .idea/misc.xml

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

93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
RestClient
======

Type-safe HTTP client for Android and Java by Square, Inc.


implement Basic Authorization



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' }
}
dependencies {
implementation 'com.github.alishatergholi:restclient:latest_version'
}
```


How do i use RestClient
=======================
```java
RestClient client = new RestClient
.Builder(context)

/* you can add Accept encoding for encode your response */
/* for now we just support gzip */
.setAcceptEnconding(EncodingType.GZIP)

/* for add custom header you need
ArrayMap<String,String> header = new ArrayMap<>();
header.put("appid","0e8f8fd2-1acb-11e7-8ab0-ac162d7938f0");
header.put("accept-language", "fa");
.setHeader(header)
*/
/* for add Authorization Header */
.setAuthorization("Authorization url","clientId","client",AuthType.BASIC_AUTH)
.setUserInfo("username for Authorization","password for Authorization")
.build();

//for add body use.
RequestParams params = new RequestParams(RequestBodyType.FormData);
params.put("key","value");

client.POST("url",
"tag " /*you can set tag when you need to cancel your service*/,
params /* except get method we can add body for other method as body */,
new ResponseTextHandler() {
@Override
protected void onSuccess(String result) {
Log.d(TAG,result);
}

@Override
public void onProgress(double percent, long bytesWritten, long totalSize) {
super.onProgress(percent, bytesWritten, totalSize);
Log.d(TAG,"percent " + percent);
}

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

License
=======

Copyright 2013 Square, Inc.

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.

20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
apply plugin: 'com.android.application'


android {
compileSdkVersion 28
compileSdkVersion project.compileSdkVersion
defaultConfig {
applicationId "ir.vasl.restclient"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion project.minSdkVersion
targetSdkVersion project.targetSdkVersion
versionCode project.versionCode
versionName project.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -24,10 +25,9 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation project(':library')
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ir.vasl.restclient;
package com.github.restclient;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ir.vasl.restclient">
package="com.github.restclient">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<activity android:name="com.github.restclient.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
79 changes: 79 additions & 0 deletions app/src/main/java/com/github/restclient/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.github.restclient;


import android.os.Bundle;
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;


public class MainActivity extends AppCompatActivity {

private String TAG = MainActivity.class.getSimpleName();

private RestClient restClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

initRestClient();

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

restClient.POST("https://google.com", "", new RequestParams(), new ResponseJsonHandler() {
@Override
protected void onSuccess(JSONObject result) {
Log.d(TAG, "response " + result);
}

@Override
protected void onSuccess(JSONArray result) {

}

@Override
protected void onSuccess(String result) {

}

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

private void initRestClient() {
ArrayMap<String, String> header = new ArrayMap<>();
header.put("appid", "c3bdf6c5-508f-48ae-9af4-243a24072e31");
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)
.setUserInfo("android-XoaM8ODAYVcKnB16ob8N", "DOI0qOIa0KT6ViYmS1k6")

.setHeader(header)
.build();


}
}
60 changes: 0 additions & 60 deletions app/src/main/java/ir/vasl/restclient/MainActivity.java

This file was deleted.

14 changes: 6 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
<Button
android:id="@+id/text"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:text="Hello World!" />

</android.support.constraint.ConstraintLayout>
</RelativeLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ir.vasl.restclient;
package com.github.restclient;

import org.junit.Test;

Expand Down
Loading

0 comments on commit e2c4dd3

Please sign in to comment.