Пример #1
0
        public async Task <OMNIReportsResponse> ExecuteAsync(GetOMNIReportsExecuteContext context)
        {
            using (var client = HttpClientProvider.GetHttpClient(configuration))
            {
                NameValueCollection queryParameters = HttpUtility.ParseQueryString(string.Empty);
                SetQueryParamIfNotNull(queryParameters, "bulkId", context.BulkId);
                SetQueryParamIfNotNull(queryParameters, "messageId", context.MessageId);
                SetQueryParamIfNotNull(queryParameters, "limit", context.Limit);
                SetQueryParamIfNotNull(queryParameters, "channel", context.Channel);

                string queryString = queryParameters.ToString();
                string endpoint    = path + "?" + queryString;

                var response = await client.GetAsync(endpoint);

                string contents = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <OMNIReportsResponse>(contents, Settings));
                }
                else
                {
                    throw new InfobipApiException(
                              response.StatusCode,
                              JsonConvert.DeserializeObject <ApiErrorResponse>(contents, Settings)
                              );
                }
            }
        }
Пример #2
0
        protected static async Task <OMNIReportsResponse> GetOmniReportAsync(string bulkId)
        {
            Console.WriteLine("-------------------------------");
            Console.WriteLine("Fetching reports...");

            GetOMNIReports omniReportsClient     = new GetOMNIReports(BASIC_AUTH_CONFIGURATION);
            GetOMNIReportsExecuteContext context = new GetOMNIReportsExecuteContext
            {
                BulkId = bulkId
            };
            OMNIReportsResponse response = await omniReportsClient.ExecuteAsync(context);

            if (!response.Results.Any())
            {
                Console.WriteLine("No report to fetch.");
                return(new OMNIReportsResponse());
            }
            Console.WriteLine("Fetching report complete.");

            foreach (OMNIReport report in response.Results)
            {
                Console.WriteLine("-------------------------------");
                Console.WriteLine("Message ID: " + report.MessageId);
                Console.WriteLine("Sent at: " + report.SentAt);
                Console.WriteLine("Channel: " + report.Channel);
                Console.WriteLine("Status: " + report.Status.Name);
                Console.WriteLine("Price: " + report.Price.PricePerMessage + " " + report.Price.Currency);
                Console.WriteLine("-------------------------------");
            }

            return(response);
        }