Esempio n. 1
0
        public async Task <GhasedakSendResponse> SendAsync(GhasedakOutgoingMessageRequest message, GhasedakOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (string.IsNullOrWhiteSpace(options.PrivateKey))
            {
                throw new ArgumentNullException(nameof(options.PrivateKey));
            }

            var serializer = new JsonSerializer <GhasedakSendResponse>();

            var inlineMessage = message.MapToInlineGhasedakOutgoingMessageRequest();

            inlineMessage.SignWith(options.PrivateKey);
            var content = inlineMessage.CreateContent();

            var httpResponse = await _httpClient.PostAsync("/api/v5.0/message/post", content);

            await CheckSuccessStatusCodeAndThrowIfUnsuccessful(httpResponse);

            var ghasedakResponseString = await httpResponse.Content.ReadAsStringAsync();

            var ghasedakResponse = serializer.DeserializeFromString(ghasedakResponseString);

            return(ghasedakResponse);
        }