Skip to content

Commit

Permalink
Changed GET Request approach
Browse files Browse the repository at this point in the history
  • Loading branch information
F4pl0 committed Sep 7, 2019
1 parent 615c3f9 commit e4d7617
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 50 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.github.F4pl0:FARLA:0.1.0'
implementation 'com.github.F4pl0:FARLA:0.1.1'
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/f4pl0/farlaexample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FARLA farla = new FARLA();
farla.GET("http://google.com", "asd", new FARLA.onResult() {
farla.GET("http://webhook.site/7a7ca4d3-e601-4950-83bf-47e7bb769dd0", "asd", new FARLA.onResult() {
@Override
public void resultSuccess(String response) {
Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT).show();
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ buildscript {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
Expand Down
1 change: 1 addition & 0 deletions farla/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.android.volley:volley:1.1.1'
}
48 changes: 0 additions & 48 deletions farla/src/main/java/com/f4pl0/farla/FARLA.java

This file was deleted.

58 changes: 58 additions & 0 deletions farla/src/main/java/com/f4pl0/farla/FarlaGetRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.f4pl0.farla;

import android.content.Context;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONObject;

public class FarlaGetRequest {

Context context;
RequestQueue requestQueue;
String URL = "";
onGetRequestListener listener;

public FarlaGetRequest(Context context) {
this.context = context;
requestQueue = Volley.newRequestQueue(context);
}

public interface onGetRequestListener{
void onSuccess(String response);
void onFailure(int error);
}

FarlaGetRequest setURL(String URL){
this.URL = URL;
return this;
}

FarlaGetRequest setListener(onGetRequestListener listener){
this.listener = listener;
return this;
}

void execute(){
StringRequest stringRequest = new StringRequest(Request.Method.GET, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
listener.onSuccess(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(stringRequest);
}

}

0 comments on commit e4d7617

Please sign in to comment.