BalihooBlipDotNet.BlipRequest.ExecuteCommand C# (CSharp) Method

ExecuteCommand() private method

Executes the specified HTTP command.
private ExecuteCommand ( Command command, string path, string content = null ) : Task
command Command The HTTP command.
path string The URI path for the API function to be executed.
content string Any content that may need to be supplied to the API. Defaults to null.
return Task
        internal async Task<BlipResponse> ExecuteCommand(Command command, string path, string content=null)
        {
            var encodedPath = Uri.EscapeUriString(path);

            using (var httpClient = new HttpClient())
            using (var client = ConfigureClient(httpClient))
            {
                switch (command)
                {
                    case Command.Get:
                        {
                            using (var response = await client.GetAsync(encodedPath))
                            {
                                response.EnsureSuccessStatusCode();
                                return await BuildResponse(response);
                            }
                        }
                    case Command.Put:
                        {
                            using (var httpContent = new StringContent(content, Encoding.UTF8, "application/json"))
                            using (var response = await client.PutAsync(encodedPath, httpContent))
                            {
                                response.EnsureSuccessStatusCode();
                                return await BuildResponse(response);
                            }
                        }
                    case Command.Post:
                        {
                            using (var httpContent = new StringContent(content, Encoding.UTF8, "application/json"))
                            using (var response = await client.PostAsync(encodedPath, httpContent))
                            {
                                response.EnsureSuccessStatusCode();
                                return await BuildResponse(response);
                            }
                        }
                    case Command.Delete:
                        {
                            using (var response = await client.DeleteAsync(encodedPath))
                            {
                                response.EnsureSuccessStatusCode();
                                return await BuildResponse(response);
                            }
                        }
                    default:
                        throw new ArgumentOutOfRangeException($"Invalid HTTP Command: {command}");
                }
            }
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Get a list of data projections available for an individual brand.
        /// </summary>
        /// <param name="brandKey">The unique identifier for a single brand.</param>
        /// <returns>BlipResponse object with a status code and body text if applicable.</returns>
        public BlipResponse GetBrandProjections(string brandKey)
        {
            var path    = $"/brand/{brandKey}/projection";
            var request = new BlipRequest(Credentials, Endpoint);

            return(request.ExecuteCommand(BlipRequest.Command.Get, path).Result);
        }
All Usage Examples Of BalihooBlipDotNet.BlipRequest::ExecuteCommand