Search in sources :

Example 1 with HttpRequest

use of com.google.firebase.crashlytics.internal.network.HttpRequest in project GreenHouse by utsanjan.

the class DefaultCreateReportSpiCall method applyMultipartDataTo.

private HttpRequest applyMultipartDataTo(HttpRequest request, Report report) {
    File[] files;
    HttpRequest request2 = request.part(IDENTIFIER_PARAM, report.getIdentifier());
    if (report.getFiles().length == 1) {
        Logger.getLogger().d("Adding single file " + report.getFileName() + " to report " + report.getIdentifier());
        return request2.part(FILE_PARAM, report.getFileName(), FILE_CONTENT_TYPE, report.getFile());
    }
    int i = 0;
    for (File file : report.getFiles()) {
        Logger.getLogger().d("Adding file " + file.getName() + " to report " + report.getIdentifier());
        StringBuilder sb = new StringBuilder();
        sb.append(MULTI_FILE_PARAM);
        sb.append(i);
        sb.append("]");
        request2 = request2.part(sb.toString(), file.getName(), FILE_CONTENT_TYPE, file);
        i++;
    }
    return request2;
}
Also used : HttpRequest(com.google.firebase.crashlytics.internal.network.HttpRequest) File(java.io.File)

Example 2 with HttpRequest

use of com.google.firebase.crashlytics.internal.network.HttpRequest in project GreenHouse by utsanjan.

the class DefaultCreateReportSpiCall method applyHeadersTo.

private HttpRequest applyHeadersTo(HttpRequest request, CreateReportRequest requestData) {
    HttpRequest request2 = request.header(AbstractSpiCall.HEADER_GOOGLE_APP_ID, requestData.googleAppId).header(AbstractSpiCall.HEADER_CLIENT_TYPE, AbstractSpiCall.ANDROID_CLIENT_TYPE).header(AbstractSpiCall.HEADER_CLIENT_VERSION, this.version);
    Map<String, String> customHeaders = requestData.report.getCustomHeaders();
    for (Map.Entry<String, String> entry : customHeaders.entrySet()) {
        request2 = request2.header(entry);
    }
    return request2;
}
Also used : HttpRequest(com.google.firebase.crashlytics.internal.network.HttpRequest) Map(java.util.Map)

Example 3 with HttpRequest

use of com.google.firebase.crashlytics.internal.network.HttpRequest in project GreenHouse by utsanjan.

the class DefaultCreateReportSpiCall method invoke.

// com.google.firebase.crashlytics.internal.report.network.CreateReportSpiCall
@Override
public boolean invoke(CreateReportRequest requestData, boolean dataCollectionToken) {
    if (dataCollectionToken) {
        HttpRequest httpRequest = getHttpRequest();
        HttpRequest httpRequest2 = applyMultipartDataTo(applyHeadersTo(httpRequest, requestData), requestData.report);
        Logger logger = Logger.getLogger();
        logger.d("Sending report to: " + getUrl());
        try {
            HttpResponse httpResponse = httpRequest2.execute();
            int statusCode = httpResponse.code();
            Logger logger2 = Logger.getLogger();
            logger2.d("Create report request ID: " + httpResponse.header(AbstractSpiCall.HEADER_REQUEST_ID));
            Logger logger3 = Logger.getLogger();
            logger3.d("Result was: " + statusCode);
            return ResponseParser.parse(statusCode) == 0;
        } catch (IOException ioe) {
            Logger.getLogger().e("Create report HTTP request failed.", ioe);
            throw new RuntimeException(ioe);
        }
    } else {
        throw new RuntimeException("An invalid data collection token was used.");
    }
}
Also used : HttpRequest(com.google.firebase.crashlytics.internal.network.HttpRequest) HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse) IOException(java.io.IOException) Logger(com.google.firebase.crashlytics.internal.Logger)

Example 4 with HttpRequest

use of com.google.firebase.crashlytics.internal.network.HttpRequest in project GreenHouse by utsanjan.

the class DefaultSettingsSpiCall method invoke.

// com.google.firebase.crashlytics.internal.settings.network.SettingsSpiCall
@Override
public JSONObject invoke(SettingsRequest requestData, boolean dataCollectionToken) {
    if (dataCollectionToken) {
        try {
            Map<String, String> queryParams = getQueryParamsFor(requestData);
            HttpRequest httpRequest = getHttpRequest(queryParams);
            HttpRequest httpRequest2 = applyHeadersTo(httpRequest, requestData);
            Logger logger = this.logger;
            logger.d("Requesting settings from " + getUrl());
            Logger logger2 = this.logger;
            logger2.d("Settings query params were: " + queryParams);
            HttpResponse httpResponse = httpRequest2.execute();
            Logger logger3 = this.logger;
            logger3.d("Settings request ID: " + httpResponse.header(AbstractSpiCall.HEADER_REQUEST_ID));
            JSONObject toReturn = handleResponse(httpResponse);
            return toReturn;
        } catch (IOException e) {
            this.logger.e("Settings request failed.", e);
            return null;
        }
    } else {
        throw new RuntimeException("An invalid data collection token was used.");
    }
}
Also used : HttpRequest(com.google.firebase.crashlytics.internal.network.HttpRequest) JSONObject(org.json.JSONObject) HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse) IOException(java.io.IOException) Logger(com.google.firebase.crashlytics.internal.Logger)

Example 5 with HttpRequest

use of com.google.firebase.crashlytics.internal.network.HttpRequest in project GreenHouse by utsanjan.

the class NativeCreateReportSpiCall method invoke.

// com.google.firebase.crashlytics.internal.report.network.CreateReportSpiCall
@Override
public boolean invoke(CreateReportRequest requestData, boolean dataCollectionToken) {
    if (dataCollectionToken) {
        HttpRequest httpRequest = getHttpRequest();
        HttpRequest httpRequest2 = applyMultipartDataTo(applyHeadersTo(httpRequest, requestData.googleAppId), requestData.organizationId, requestData.report);
        Logger logger = Logger.getLogger();
        logger.d("Sending report to: " + getUrl());
        try {
            HttpResponse httpResponse = httpRequest2.execute();
            int statusCode = httpResponse.code();
            Logger logger2 = Logger.getLogger();
            logger2.d("Result was: " + statusCode);
            return ResponseParser.parse(statusCode) == 0;
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    } else {
        throw new RuntimeException("An invalid data collection token was used.");
    }
}
Also used : HttpRequest(com.google.firebase.crashlytics.internal.network.HttpRequest) HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse) IOException(java.io.IOException) Logger(com.google.firebase.crashlytics.internal.Logger)

Aggregations

HttpRequest (com.google.firebase.crashlytics.internal.network.HttpRequest)6 Logger (com.google.firebase.crashlytics.internal.Logger)4 HttpResponse (com.google.firebase.crashlytics.internal.network.HttpResponse)4 IOException (java.io.IOException)4 File (java.io.File)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1