/// <inheritdoc />
        /// <summary>
        /// Add a metric Post a new score/stat for an activity occurrence without ending the occurrence itself
        /// </summary>
        /// <param name="metric">The new metric</param>
        public void AddMetric(MetricResource metric)
        {
            mWebCallEvent.WebPath = "/metrics";
            if (!string.IsNullOrEmpty(mWebCallEvent.WebPath))
            {
                mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json");
            }

            mWebCallEvent.HeaderParams.Clear();
            mWebCallEvent.QueryParams.Clear();
            mWebCallEvent.AuthSettings.Clear();
            mWebCallEvent.PostBody = null;

            mWebCallEvent.PostBody = KnetikClient.Serialize(metric); // http body (model) parameter

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant");

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_password_grant");

            // make the HTTP request
            mAddMetricStartTime       = DateTime.Now;
            mWebCallEvent.Context     = mAddMetricResponseContext;
            mWebCallEvent.RequestType = KnetikRequestType.POST;

            KnetikLogger.LogRequest(mAddMetricStartTime, "AddMetric", "Sending server request...");
            KnetikGlobalEventSystem.Publish(mWebCallEvent);
        }
        private MetricResource CalculateResource(string[] values)
        {
            MetricResource Resource = new MetricResource
            {
                Attrition = (values[33] != "N/A") ? Convert.ToDecimal(values[33]) : 0,
                AvailabilityofResource = values[34]
            };

            return(Resource);
        }
        public void TestReadFullResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"meta\": {\"page\": 10,\"page_size\": 5,\"first_page_url\": \"https://insights.twilio.com/v1/Voice/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Metrics?Direction=both&Edge=sdk_edge&PageSize=5&Page=0\",\"previous_page_url\": \"https://insights.twilio.com/v1/Voice/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Metrics?Direction=both&Edge=sdk_edge&PageSize=5&Page=9&PageToken=DP10\",\"next_page_url\": null,\"key\": \"metrics\",\"url\": \"https://insights.twilio.com/v1/Voice/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Metrics?Direction=both&Edge=sdk_edge&PageSize=5&Page=10\"},\"metrics\": [{\"timestamp\": \"2019-10-07T22:32:06Z\",\"call_sid\": \"CA7569efe0253644fa4a88aa97beca3310\",\"account_sid\": \"AC998c10b68cbfda9f67277f7d8f4439c9\",\"edge\": \"sdk_edge\",\"direction\": \"both\",\"sdk_edge\": {\"interval\": {\"packets_received\": 50,\"packets_lost\": 0,\"audio_in\": {\"value\": 81.0},\"audio_out\": {\"value\": 5237.0},\"jitter\": {\"value\": 9},\"mos\": {\"value\": 4.39},\"rtt\": {\"value\": 81}},\"cumulative\": {\"bytes_received\": 547788,\"bytes_sent\": 329425,\"packets_received\": 3900,\"packets_lost\": 0,\"packets_sent\": 3934}},\"client_edge\": null,\"carrier_edge\": null,\"sip_edge\": null,\"gateway\": null,\"client\": null}]}"
                         ));

            var response = MetricResource.Read("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient);

            Assert.NotNull(response);
        }
        public void TestReadRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Get,
                Twilio.Rest.Domain.Insights,
                "/v1/Voice/CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Metrics",
                ""
                );

            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                MetricResource.Read("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
        /// <summary>
        /// Add a metric Post a new score/stat for an activity occurrence without ending the occurrence itself
        /// </summary>
        /// <exception cref="com.knetikcloud.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="metric">The new metric (optional)</param>
        /// <returns>ApiResponse of Object(void)</returns>
        public ApiResponse <Object> AddMetricWithHttpInfo(MetricResource metric = null)
        {
            var    localVarPath         = "/metrics";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (metric != null && metric.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(metric); // http body (model) parameter
            }
            else
            {
                localVarPostBody = metric; // byte array
            }

            // authentication (oauth2_client_credentials_grant) required
            // oauth required
            if (!String.IsNullOrEmpty(Configuration.AccessToken))
            {
                localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
            }
            // authentication (oauth2_password_grant) required
            // oauth required
            if (!String.IsNullOrEmpty(Configuration.AccessToken))
            {
                localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath,
                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("AddMetric", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <Object>(localVarStatusCode,
                                            localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                            null));
        }
 /// <summary>
 /// Add a metric Post a new score/stat for an activity occurrence without ending the occurrence itself
 /// </summary>
 /// <exception cref="com.knetikcloud.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="metric">The new metric (optional)</param>
 /// <returns></returns>
 public void AddMetric(MetricResource metric = null)
 {
     AddMetricWithHttpInfo(metric);
 }