Skip to content

Commit

Permalink
Add support for PUT Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
F4pl0 committed Sep 7, 2019
1 parent 54f6035 commit a732188
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions farla/src/main/java/com/f4pl0/farla/FarlaPutRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;

public class FarlaPutRequest {
Context context;
RequestQueue requestQueue;
String URL = "";
onPutRequestListener listener;
Map<String, String> params = new HashMap<String, String>();

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

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

public FarlaPutRequest addParam(String key, String value){
params.put(key, value);
return this;
}

public FarlaPutRequest removeParam(String key){
params.remove(key);
return this;
}

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

public FarlaPutRequest setListener(onPutRequestListener listener){
this.listener = listener;
return this;
}

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

@Override
protected Map<String, String> getParams()
{
return params;
}

};
requestQueue.add(putRequest);
}
}

0 comments on commit a732188

Please sign in to comment.