MCPcopy Create free account
hub / github.com/Asana/java-asana / request

Method request

src/main/java/com/asana/Client.java:143–221  ·  view source on GitHub ↗

@param request Asana client request object @return Raw HttpResponse object @throws IOException if the request fails

(Request request)

Source from the content-addressed store, hash-verified

141 * @throws IOException if the request fails
142 */
143 public HttpResponse request(Request request) throws IOException {
144 GenericUrl url = new GenericUrl(request.options.get("base_url") + request.path);
145
146 HttpContent content = null;
147 Map<String, Object> body = new HashMap<String, Object>();
148
149 // API options
150 if (request.method.equals("GET")) {
151 for (String key : API_OPTIONS) {
152 if (request.options.containsKey(key) && !request.query.containsKey("opt_" + key)) {
153 request.query.put("opt_" + key, request.options.get(key));
154 }
155 }
156 for (String key : QUERY_OPTIONS) {
157 if (request.options.containsKey(key) && !request.query.containsKey(key)) {
158 request.query.put(key, request.options.get(key));
159 }
160 }
161 } else if (request.method.equals("POST") || request.method.equals("PUT")) {
162 Map<String, Object> opts = new HashMap<String, Object>();
163 for (String key : API_OPTIONS) {
164 if (request.options.containsKey(key)) {
165 opts.put(key, request.options.get(key));
166 }
167 }
168 if (opts.size() > 0) {
169 body.put("options", opts);
170 }
171 }
172
173 // Query string
174 for (Map.Entry<String, Object> entry : request.query.entrySet()) {
175 Object value = entry.getValue();
176 if (value == null || value == "") {
177 continue;
178 }
179 if (value instanceof List) {
180 value = Joiner.on(",").join((List) value);
181 }
182 url.put(entry.getKey(), value);
183 }
184
185 // Headers
186 Map <String, String> headers = new HashMap<String, String>(this.headers);
187 headers.putAll(request.headers);
188
189 if (request.content != null) {
190 // Multipart, etc body
191 content = request.content;
192 } else if (request.method.equals("POST") || request.method.equals("PUT")) {
193 // JSON body
194 body.put("data", request.data);
195 String json = Json.getInstance().toJson(body);
196 content = new ByteArrayContent("application/json", json.getBytes("UTF-8"));
197 }
198
199 int retryCount = 0;
200 int maxRetries = (Integer) request.options.get("max_retries");

Callers 2

executeRawMethod · 0.80
executeRawMethod · 0.80

Calls 7

getInstanceMethod · 0.95
versionHeaderMethod · 0.95
mapExceptionMethod · 0.95
handleRetryableErrorMethod · 0.95
getMethod · 0.80
buildRequestMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected