-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
62 changed files
with
1,575 additions
and
992 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...l/restclient/ExampleInstrumentedTest.java → ...b/restclient/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...a/ir/vasl/restclient/ExampleUnitTest.java → ...om/github/restclient/ExampleUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
Oops, something went wrong.