Search in sources :

Example 1 with ApiDataRow

use of com.google.api.services.webmasters.model.ApiDataRow in project incubator-gobblin by apache.

the class GoogleWebmasterClientImpl method getPages.

@Override
public List<String> getPages(String siteProperty, String startDate, String endDate, String country, int rowLimit, List<GoogleWebmasterFilter.Dimension> requestedDimensions, List<ApiDimensionFilter> filters, int startRow) throws IOException {
    checkRowLimit(rowLimit);
    Preconditions.checkArgument(requestedDimensions.contains(GoogleWebmasterFilter.Dimension.PAGE));
    SearchAnalyticsQueryResponse rspByCountry = createSearchAnalyticsQuery(siteProperty, startDate, endDate, requestedDimensions, GoogleWebmasterFilter.andGroupFilters(filters), rowLimit, startRow).execute();
    List<ApiDataRow> pageRows = rspByCountry.getRows();
    List<String> pages = new ArrayList<>(rowLimit);
    if (pageRows != null) {
        int pageIndex = requestedDimensions.indexOf(GoogleWebmasterFilter.Dimension.PAGE);
        for (ApiDataRow row : pageRows) {
            pages.add(row.getKeys().get(pageIndex));
        }
    }
    return pages;
}
Also used : SearchAnalyticsQueryResponse(com.google.api.services.webmasters.model.SearchAnalyticsQueryResponse) ArrayList(java.util.ArrayList) ApiDataRow(com.google.api.services.webmasters.model.ApiDataRow)

Example 2 with ApiDataRow

use of com.google.api.services.webmasters.model.ApiDataRow in project incubator-gobblin by apache.

the class GoogleWebmasterDataFetcher method convertResponse.

public static List<String[]> convertResponse(List<Metric> requestedMetrics, SearchAnalyticsQueryResponse response) {
    List<ApiDataRow> rows = response.getRows();
    if (rows == null || rows.isEmpty()) {
        return new ArrayList<>();
    }
    int arraySize = rows.get(0).getKeys().size() + requestedMetrics.size();
    List<String[]> ret = new ArrayList<>(rows.size());
    for (ApiDataRow row : rows) {
        List<String> keys = row.getKeys();
        String[] data = new String[arraySize];
        int i = 0;
        for (; i < keys.size(); ++i) {
            data[i] = keys.get(i);
        }
        for (Metric requestedMetric : requestedMetrics) {
            if (requestedMetric == Metric.CLICKS) {
                data[i] = row.getClicks().toString();
            } else if (requestedMetric == Metric.IMPRESSIONS) {
                data[i] = row.getImpressions().toString();
            } else if (requestedMetric == Metric.CTR) {
                data[i] = String.format("%.5f", row.getCtr());
            } else if (requestedMetric == Metric.POSITION) {
                data[i] = String.format("%.2f", row.getPosition());
            } else {
                throw new RuntimeException("Unknown Google Webmaster Metric Type");
            }
            ++i;
        }
        ret.add(data);
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) ApiDataRow(com.google.api.services.webmasters.model.ApiDataRow)

Aggregations

ApiDataRow (com.google.api.services.webmasters.model.ApiDataRow)2 ArrayList (java.util.ArrayList)2 SearchAnalyticsQueryResponse (com.google.api.services.webmasters.model.SearchAnalyticsQueryResponse)1