public String executeInternal()

in templates/java/src/main/java/com/facebook/ads/sdk/BatchRequest.java [114:152]


  public String executeInternal() throws APIException, IOException {

    Map<String, Object> params = new LinkedHashMap<String, Object>();
    Map<String, File> files = new HashMap<String, File>();
    JsonArray batch = new JsonArray();
    params.put("access_token", context.getAccessToken());
    if (context.hasAppSecret()) {
      params.put("appsecret_proof", context.getAppSecretProof());
    }
    params.put("include_headers", "false");
    for (Pair requestEntry : requests) {
      JsonObject batchElement = new JsonObject();
      BatchModeRequestInfo info = requestEntry.request.getBatchModeRequestInfo();

      batchElement.addProperty("method", info.method);
      batchElement.addProperty("relative_url", info.relativeUrl);
      batchElement.addProperty("name", requestEntry.name);
      batchElement.addProperty("omit_response_on_success", requestEntry.omitResponseOnSuccess);

      if (info.body != null) {
        batchElement.addProperty("body", info.body);
      }

      if (info.files != null) {
        JsonObject attachedFiles = new JsonObject();
        for (Map.Entry entry : info.files.entrySet()) {
          File file = (File)entry.getValue();
          attachedFiles.addProperty("File" + files.size(), (String)entry.getKey());
          files.put("File" + files.size(), file);
        }
        batchElement.add("attached_files", attachedFiles);
      }

      batch.add(batchElement);
    }
    params.put("batch", batch.toString());
    params.putAll(files);
    return APIRequest.getExecutor().sendPost(context.getEndpointBase() + "/", params, context).getBody();
  }