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

com.azure.communication.messages.implementation.NotificationMessagesClientImpl Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package com.azure.communication.messages.implementation;

import com.azure.communication.messages.MessagesServiceVersion;
import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Post;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.util.BinaryData;
import com.azure.core.util.Context;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.DateTimeRfc1123;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerAdapter;
import java.time.OffsetDateTime;
import reactor.core.publisher.Mono;

/**
 * Initializes a new instance of the NotificationMessagesClient type.
 */
public final class NotificationMessagesClientImpl {
    /**
     * The proxy service used to perform REST calls.
     */
    private final NotificationMessagesClientService service;

    /**
     * The communication resource, for example https://my-resource.communication.azure.com.
     */
    private final String endpoint;

    /**
     * Gets The communication resource, for example https://my-resource.communication.azure.com.
     * 
     * @return the endpoint value.
     */
    public String getEndpoint() {
        return this.endpoint;
    }

    /**
     * Service version.
     */
    private final MessagesServiceVersion serviceVersion;

    /**
     * Gets Service version.
     * 
     * @return the serviceVersion value.
     */
    public MessagesServiceVersion getServiceVersion() {
        return this.serviceVersion;
    }

    /**
     * The HTTP pipeline to send requests through.
     */
    private final HttpPipeline httpPipeline;

    /**
     * Gets The HTTP pipeline to send requests through.
     * 
     * @return the httpPipeline value.
     */
    public HttpPipeline getHttpPipeline() {
        return this.httpPipeline;
    }

    /**
     * The serializer to serialize an object into a string.
     */
    private final SerializerAdapter serializerAdapter;

    /**
     * Gets The serializer to serialize an object into a string.
     * 
     * @return the serializerAdapter value.
     */
    public SerializerAdapter getSerializerAdapter() {
        return this.serializerAdapter;
    }

    /**
     * Initializes an instance of NotificationMessagesClient client.
     * 
     * @param endpoint The communication resource, for example https://my-resource.communication.azure.com.
     * @param serviceVersion Service version.
     */
    public NotificationMessagesClientImpl(String endpoint, MessagesServiceVersion serviceVersion) {
        this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(),
            JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion);
    }

    /**
     * Initializes an instance of NotificationMessagesClient client.
     * 
     * @param httpPipeline The HTTP pipeline to send requests through.
     * @param endpoint The communication resource, for example https://my-resource.communication.azure.com.
     * @param serviceVersion Service version.
     */
    public NotificationMessagesClientImpl(HttpPipeline httpPipeline, String endpoint,
        MessagesServiceVersion serviceVersion) {
        this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion);
    }

    /**
     * Initializes an instance of NotificationMessagesClient client.
     * 
     * @param httpPipeline The HTTP pipeline to send requests through.
     * @param serializerAdapter The serializer to serialize an object into a string.
     * @param endpoint The communication resource, for example https://my-resource.communication.azure.com.
     * @param serviceVersion Service version.
     */
    public NotificationMessagesClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter,
        String endpoint, MessagesServiceVersion serviceVersion) {
        this.httpPipeline = httpPipeline;
        this.serializerAdapter = serializerAdapter;
        this.endpoint = endpoint;
        this.serviceVersion = serviceVersion;
        this.service
            = RestProxy.create(NotificationMessagesClientService.class, this.httpPipeline, this.getSerializerAdapter());
    }

    /**
     * The interface defining all the services for NotificationMessagesClient to be used by the proxy service to perform
     * REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "NotificationMessages")
    public interface NotificationMessagesClientService {
        @Post("/messages/notifications:send")
        @ExpectedResponses({ 202 })
        @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
        @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
        @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
        @UnexpectedResponseExceptionType(HttpResponseException.class)
        Mono> send(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType,
            @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData notificationContent,
            RequestOptions requestOptions, Context context);

        @Post("/messages/notifications:send")
        @ExpectedResponses({ 202 })
        @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
        @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
        @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
        @UnexpectedResponseExceptionType(HttpResponseException.class)
        Response sendSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @HeaderParam("Content-Type") String contentType,
            @HeaderParam("Accept") String accept, @BodyParam("application/json") BinaryData notificationContent,
            RequestOptions requestOptions, Context context);

        @Get("/messages/streams/{id}")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
        @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
        @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
        @UnexpectedResponseExceptionType(HttpResponseException.class)
        Mono> downloadMedia(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("id") String mediaId,
            @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context);

        @Get("/messages/streams/{id}")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
        @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
        @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
        @UnexpectedResponseExceptionType(HttpResponseException.class)
        Response downloadMediaSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("id") String mediaId,
            @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context);
    }

    /**
     * Sends a notification message from Business to User.
     * 

Header Parameters

* * * * * *
Header Parameters
NameTypeRequiredDescription
repeatability-request-idStringNoRepeatability request ID header
repeatability-first-sentStringNoRepeatability first sent header as * HTTP-date
* You can add these to a request with {@link RequestOptions#addHeader} *

Request Body Schema

* *
     * {@code
     * {
     *     kind: String(text/image/image_v0/document/video/audio/template) (Required)
     *     channelRegistrationId: String (Required)
     *     to (Required): [
     *         String (Required)
     *     ]
     * }
     * }
     * 
* *

Response Body Schema

* *
     * {@code
     * {
     *     receipts (Required): [
     *          (Required){
     *             messageId: String (Required)
     *             to: String (Required)
     *         }
     *     ]
     * }
     * }
     * 
* * @param notificationContent Details of the message to send. * @param requestOptions The options to configure the HTTP request before HTTP client sends it. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. * @return result of the send message operation along with {@link Response} on successful completion of * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> sendWithResponseAsync(BinaryData notificationContent, RequestOptions requestOptions) { final String contentType = "application/json"; final String accept = "application/json"; RequestOptions requestOptionsLocal = requestOptions == null ? new RequestOptions() : requestOptions; requestOptionsLocal.addRequestCallback(requestLocal -> { if (requestLocal.getHeaders().get(HttpHeaderName.fromString("repeatability-request-id")) == null) { requestLocal.getHeaders() .set(HttpHeaderName.fromString("repeatability-request-id"), CoreUtils.randomUuid().toString()); } }); requestOptionsLocal.addRequestCallback(requestLocal -> { if (requestLocal.getHeaders().get(HttpHeaderName.fromString("repeatability-first-sent")) == null) { requestLocal.getHeaders() .set(HttpHeaderName.fromString("repeatability-first-sent"), DateTimeRfc1123.toRfc1123String(OffsetDateTime.now())); } }); return FluxUtil.withContext(context -> service.send(this.getEndpoint(), this.getServiceVersion().getVersion(), contentType, accept, notificationContent, requestOptionsLocal, context)); } /** * Sends a notification message from Business to User. *

Header Parameters

* * * * * *
Header Parameters
NameTypeRequiredDescription
repeatability-request-idStringNoRepeatability request ID header
repeatability-first-sentStringNoRepeatability first sent header as * HTTP-date
* You can add these to a request with {@link RequestOptions#addHeader} *

Request Body Schema

* *
     * {@code
     * {
     *     kind: String(text/image/image_v0/document/video/audio/template) (Required)
     *     channelRegistrationId: String (Required)
     *     to (Required): [
     *         String (Required)
     *     ]
     * }
     * }
     * 
* *

Response Body Schema

* *
     * {@code
     * {
     *     receipts (Required): [
     *          (Required){
     *             messageId: String (Required)
     *             to: String (Required)
     *         }
     *     ]
     * }
     * }
     * 
* * @param notificationContent Details of the message to send. * @param requestOptions The options to configure the HTTP request before HTTP client sends it. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. * @return result of the send message operation along with {@link Response}. */ @ServiceMethod(returns = ReturnType.SINGLE) public Response sendWithResponse(BinaryData notificationContent, RequestOptions requestOptions) { final String contentType = "application/json"; final String accept = "application/json"; RequestOptions requestOptionsLocal = requestOptions == null ? new RequestOptions() : requestOptions; requestOptionsLocal.addRequestCallback(requestLocal -> { if (requestLocal.getHeaders().get(HttpHeaderName.fromString("repeatability-request-id")) == null) { requestLocal.getHeaders() .set(HttpHeaderName.fromString("repeatability-request-id"), CoreUtils.randomUuid().toString()); } }); requestOptionsLocal.addRequestCallback(requestLocal -> { if (requestLocal.getHeaders().get(HttpHeaderName.fromString("repeatability-first-sent")) == null) { requestLocal.getHeaders() .set(HttpHeaderName.fromString("repeatability-first-sent"), DateTimeRfc1123.toRfc1123String(OffsetDateTime.now())); } }); return service.sendSync(this.getEndpoint(), this.getServiceVersion().getVersion(), contentType, accept, notificationContent, requestOptionsLocal, Context.NONE); } /** * Download the Media payload from a User to Business message. *

Response Body Schema

* *
     * {@code
     * BinaryData
     * }
     * 
* * @param mediaId The stream ID. * @param requestOptions The options to configure the HTTP request before HTTP client sends it. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. * @return the response body along with {@link Response} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> downloadMediaWithResponseAsync(String mediaId, RequestOptions requestOptions) { final String accept = "application/octet-stream"; return FluxUtil.withContext(context -> service.downloadMedia(this.getEndpoint(), this.getServiceVersion().getVersion(), mediaId, accept, requestOptions, context)); } /** * Download the Media payload from a User to Business message. *

Response Body Schema

* *
     * {@code
     * BinaryData
     * }
     * 
* * @param mediaId The stream ID. * @param requestOptions The options to configure the HTTP request before HTTP client sends it. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. * @return the response body along with {@link Response}. */ @ServiceMethod(returns = ReturnType.SINGLE) public Response downloadMediaWithResponse(String mediaId, RequestOptions requestOptions) { final String accept = "application/octet-stream"; return service.downloadMediaSync(this.getEndpoint(), this.getServiceVersion().getVersion(), mediaId, accept, requestOptions, Context.NONE); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy