com.urbanairship.api.reports.StatisticsCsvRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
The Urban Airship Java client library
package com.urbanairship.api.reports;
import com.google.common.base.Preconditions;
import com.urbanairship.api.client.Request;
import com.urbanairship.api.client.RequestUtils;
import com.urbanairship.api.client.ResponseParser;
import com.urbanairship.api.common.parse.DateFormats;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.joda.time.DateTime;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
public class StatisticsCsvRequest implements Request {
private final static String API_STATISTICS = "/api/push/stats/";
private final DateTime start;
private final DateTime end;
private StatisticsCsvRequest() {
this(null,null);
}
private StatisticsCsvRequest(DateTime start, DateTime end) {
this.start = start;
this.end = end;
}
/**
* Create a statistics request with a csv response
*
* @param start DateTime
* @param end DateTime
* @return StatisticsCsvRequest
*/
public static StatisticsCsvRequest newRequest(DateTime start, DateTime end) {
return new StatisticsCsvRequest(start, end);
}
@Override
public ContentType getContentType() {
return null;
}
@Override
public Map getRequestHeaders() {
return null;
}
@Override
public Request.HttpMethod getHttpMethod() {
return Request.HttpMethod.GET;
}
@Override
public String getRequestBody() {
return null;
}
@Override
public URI getUri(URI baseUri) throws URISyntaxException {
Preconditions.checkNotNull(start, "start cannot be null");
Preconditions.checkNotNull(end, "end cannot be null");
Preconditions.checkArgument(end.isAfter(start), "end must occur after start");
URIBuilder builder = new URIBuilder(RequestUtils.resolveURI(baseUri, API_STATISTICS));
builder.addParameter("start", this.start.toString(DateFormats.DATE_FORMATTER));
builder.addParameter("end", this.end.toString(DateFormats.DATE_FORMATTER));
builder.addParameter("format", "csv");
return builder.build();
}
@Override
public ResponseParser getResponseParser() {
return new ResponseParser() {
@Override
public String parse(String response) throws IOException {
return response;
}
};
}
@Override
public boolean bearerTokenAuthRequired() {
return false;
}
@Override
public boolean canUseBearerTokenAuth() {
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy