Imgur.API.Endpoints.Impl.ConversationEndpoint.CreateConversationAsync C# (CSharp) Method

CreateConversationAsync() public method

Create a new message. OAuth authentication required.
/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// Thrown when an error is found in a response from an Imgur endpoint. Thrown when an error is found in a response from a Mashape endpoint.
public CreateConversationAsync ( string recipient, string body ) : Task
recipient string The recipient username, this person will receive the message.
body string The message itself, similar to the body of an email.
return Task
        public async Task<bool> CreateConversationAsync(string recipient, string body)
        {
            if (string.IsNullOrWhiteSpace(recipient))
                throw new ArgumentNullException(nameof(recipient));

            if (string.IsNullOrWhiteSpace(body))
                throw new ArgumentNullException(nameof(body));

            if (ApiClient.OAuth2Token == null)
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);

            var url = $"conversations/{recipient}";

            using (var request = RequestBuilder.CreateMessageRequest(url, body))
            {
                var added = await SendRequestAsync<bool>(request).ConfigureAwait(false);
                return added;
            }
        }

Usage Example

コード例 #1
0
        public async Task CreateConversationAsync_True()
        {
            var mockUrl = "https://api.imgur.com/3/conversations/Bob";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockConversationEndpointResponses.CreateConversation)
            };

            var client = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new ConversationEndpoint(client,
                new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var created = await endpoint.CreateConversationAsync("Bob", "Hello World!").ConfigureAwait(false);

            Assert.True(created);
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.ConversationEndpoint::CreateConversationAsync