org.datatransferproject.transfer.microsoft.common.RequestHelper Maven / Gradle / Ivy
/*
* Copyright 2018 The Data Transfer Project Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.datatransferproject.transfer.microsoft.common;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.datatransferproject.spi.transfer.provider.ImportResult;
import org.datatransferproject.types.transfer.auth.TokenAuthData;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** Provides request operations. */
public class RequestHelper {
private static final String BATCH_URL = "/beta/$batch";
private RequestHelper() {}
/**
* Creates a Graph API request object with required headers.
*
* @param id the request id
* @param url the request URL
* @param data the data
*/
public static Map createRequest(int id, String url, LinkedHashMap data) {
Map request = new LinkedHashMap<>();
Map headers = new HashMap<>();
headers.put("Content-Type", "application/json");
request.put("headers", headers);
request.put("id", id + "");
request.put("method", "POST");
request.put("url", url);
request.put("body", data);
return request;
}
/**
* Creates a Graph API batch request with required the authorization header.
*
* @param authData the auth token
* @param requests the batch request data
* @param client the client to construct the request with
* @param objectMapper the mapper to serialize data
*/
@SuppressWarnings("unchecked")
public static BatchResponse batchRequest(
TokenAuthData authData,
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy