All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.urbanairship.api.channel.ChannelAttributesRequest Maven / Gradle / Ivy

There is a newer version: 9.4.2
Show newest version
package com.urbanairship.api.channel;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.net.HttpHeaders;
import com.urbanairship.api.channel.model.ChannelAttributesResponse;
import com.urbanairship.api.channel.model.attributes.ChannelAttributesPayload;
import com.urbanairship.api.channel.parse.ChannelObjectMapper;
import com.urbanairship.api.client.Request;
import com.urbanairship.api.client.RequestUtils;
import com.urbanairship.api.client.ResponseParser;
import org.apache.http.entity.ContentType;

import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

public class ChannelAttributesRequest implements Request {

    private final ObjectMapper MAPPER = ChannelObjectMapper.getInstance();
    private final static String API_CHANNELS_ATTRIBUTES = "/api/channels/attributes";
    private final String path;
    private final ChannelAttributesPayload payload;

    private ChannelAttributesRequest(String path, ChannelAttributesPayload payload) {
        this.path = path;
        this.payload = payload;
    }

    /**
     * Create a new channel attribute request.
     *
     * @param payload ChannelAttributesPayload payload
     * @return ChannelAttributesRequest
     */
    public static ChannelAttributesRequest newRequest(ChannelAttributesPayload payload) {
        return new ChannelAttributesRequest(API_CHANNELS_ATTRIBUTES, payload);
    }

    @Override
    public HttpMethod getHttpMethod() {
        return HttpMethod.POST;
    }

    @Override
    public String getRequestBody() {
        return payload.toJSON();
    }

    @Override
    public ContentType getContentType() {
        return ContentType.APPLICATION_JSON;
    }

    @Override
    public Map getRequestHeaders() {
        Map headers = new HashMap();
        headers.put(HttpHeaders.CONTENT_TYPE, CONTENT_TYPE_JSON);
        headers.put(HttpHeaders.ACCEPT, UA_VERSION_JSON);
        return headers;
    }

    @Override
    public URI getUri(URI baseUri) {
        return RequestUtils.resolveURI(baseUri, path);
    }

    @Override
    public ResponseParser getResponseParser() {
        return response -> MAPPER.readValue(response, ChannelAttributesResponse.class);
    }

    @Override
    public boolean bearerTokenAuthRequired() {
        return false;
    }

    @Override
    public boolean canUseBearerTokenAuth() {
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy