Beispiel #1
0
        private static T ValidateResponse <T>(IRestResponse response) where T : new()
        {
            if (response.ErrorException != null)
            {
                const string message = "Error retrieving response.  Check inner details for more info.";
                var          error   = new PinError
                {
                    Error            = "Unknown error",
                    ErrorDescription = message
                };
                throw new PinPaymentsException(error, message, response.ErrorException);
            }

            // NOTE: Would like to get deserializer from RestClient but there is no public access to it.
            // We know that the PinPayments API will _always_ return JSON, so its cool.
            var deserializer = new RestSharpDataContractJsonDeserializer();

            // A non-20x status code response is an error from the PinPayments API
            if (response.StatusCode.IsNon20XCode())
            {
                var pinError = deserializer.Deserialize <PinError>(response);
                throw new PinPaymentsException(pinError, pinError.ErrorDescription);
            }

            return(deserializer.Deserialize <T>(response));
        }
Beispiel #2
0
        public void GetCleanScheduler()
        {
            var client  = new RestClient("http://localhost:8733/Kepler.Service");
            var request = new RestRequest("GetCleanDataScheduler", Method.GET);

            request.RequestFormat = DataFormat.Json;
            request.AddQueryParameter("schedulerName", "logCleanScheduler");

            var response  = client.Execute(request);
            var scheduler =
                new RestSharpDataContractJsonDeserializer().Deserialize <DataSchedulerContract>(response.Content);

            Console.WriteLine(
                $"Scheduler name {scheduler.Name}; Last start: {scheduler.LastStartTime}; Next start: {scheduler.NextStartTime}; Period: {scheduler.SchedulePeriod}");
        }