コード例 #1
0
        public MoviesApi(HttpClient httpClient)
        {
            if (httpClient.BaseAddress == null)
                throw new InvalidOperationException("You must set the BaseAddress property of the HttpClient instance");


            client = httpClient;

            SchemaValidation = new SchemaValidationSettings
            {
                Enabled = true,
                RaiseExceptions = true
            };
        }
コード例 #2
0
        public MoviesApi(string endpointUrl)
        {
            SchemaValidation = new SchemaValidationSettings
            {
                Enabled = true,
                RaiseExceptions = true
            };


            if (string.IsNullOrWhiteSpace(endpointUrl))
                throw new ArgumentException("You must specify the endpoint URL", "endpointUrl");

            if (endpointUrl.Contains("{"))
            {
                var regex = new Regex(@"\{([^\}]+)\}");
                var matches = regex.Matches(endpointUrl);
                var parameters = new List<string>();
                foreach (Match match in matches)
                {
                    parameters.Add(match.Groups[1].Value);
                }
                throw new InvalidOperationException("Please replace parameter/s " + string.Join(", ", parameters) + " in the URL before passing it to the constructor ");
            }

            client = new HttpClient { BaseAddress = new Uri(endpointUrl) };
        }