4
4
import android .content .Context ;
5
5
6
6
import com .android .volley .Request ;
7
+ import com .android .volley .toolbox .JsonObjectRequest ;
7
8
import com .android .volley .toolbox .StringRequest ;
8
9
10
+ import org .json .JSONObject ;
11
+
9
12
import java .util .HashMap ;
10
13
import java .util .Map ;
11
14
@@ -54,9 +57,9 @@ private Map<String, String> getHeaders() {
54
57
/**
55
58
* Create GET request
56
59
*
57
- * @param url Desired URL
58
- * @param listener Success callback
59
- * @param errorListener Error callback
60
+ * @param url String
61
+ * @param listener Response<String>
62
+ * @param errorListener Error
60
63
*/
61
64
public void get (String url , Response <String > listener , Error errorListener ) {
62
65
Logger .i (Constants .TAG , "url--> " + url );
@@ -73,10 +76,10 @@ public Map<String, String> getHeaders() {
73
76
/**
74
77
* Create POST request
75
78
*
76
- * @param url Desired URL
77
- * @param body params
78
- * @param listener response listener
79
- * @param errorListener error listener
79
+ * @param url String
80
+ * @param body Map<String, String>
81
+ * @param listener Response<String>
82
+ * @param errorListener Error
80
83
*/
81
84
public void post (String url , final Map <String , String > body , Response <String > listener , Error errorListener ) {
82
85
Logger .i (Constants .TAG , "url--> " + url );
@@ -99,13 +102,37 @@ public String getBodyContentType() {
99
102
Singleton .getInstance (context ).addRequestQueue (request );
100
103
}
101
104
105
+ /**
106
+ * Create POST request
107
+ *
108
+ * @param url String
109
+ * @param body JSONObject
110
+ * @param listener Response<JSONObject>
111
+ * @param errorListener Error
112
+ */
113
+ public void post (String url , final JSONObject body , Response <JSONObject > listener , Error errorListener ) {
114
+ Logger .i (Constants .TAG , "url--> " + url );
115
+ JsonObjectRequest request = new JsonObjectRequest (Request .Method .POST , url , body , listener ::response , error -> errorListener .error (Utils .with (context ).getError (error ))) {
116
+ @ Override
117
+ public Map <String , String > getHeaders () {
118
+ return Api .this .getHeaders ();
119
+ }
120
+
121
+ @ Override
122
+ public String getBodyContentType () {
123
+ return "application/json" ;
124
+ }
125
+ };
126
+ Singleton .getInstance (context ).addRequestQueue (request );
127
+ }
128
+
102
129
/**
103
130
* Create PUT request
104
131
*
105
- * @param url Desired URL
132
+ * @param url String
106
133
* @param body Map<String, String> body
107
- * @param listener Success callback
108
- * @param errorListener Error callback
134
+ * @param listener Response<String>
135
+ * @param errorListener Error
109
136
*/
110
137
public void put (String url , final Map <String , String > body , Response <String > listener , Error errorListener ) {
111
138
Logger .i (Constants .TAG , "url--> " + url );
@@ -131,9 +158,9 @@ public String getBodyContentType() {
131
158
/**
132
159
* Create DELETE request
133
160
*
134
- * @param url Desired URL
135
- * @param listener Success callback
136
- * @param errorListener Error callback
161
+ * @param url String
162
+ * @param listener Response<String>
163
+ * @param errorListener Error
137
164
*/
138
165
public void delete (String url , Response <String > listener , Error errorListener ) {
139
166
Logger .i (Constants .TAG , "url--> " + url );
0 commit comments