private Uri BuildApiUrl(string resourceName, Dictionary <string, object> routeValues)
        {
            if (!routeValues.ContainsKey("api-version"))
            {
                routeValues["api-version"] = _apiVersion;
            }

            var relativeUrl = VssHttpUriUtility.ReplaceRouteValues($"_apis/{resourceName}", routeValues, appendUnusedAsQueryParams: true);

            return(VssHttpUriUtility.ConcatUri(_uri, relativeUrl));
        }
示例#2
0
        /// <summary>
        /// Call a web API method using the given verb and payload.
        /// </summary>
        /// <typeparam name="T">The type of result expected</typeparam>
        /// <param name="resourceUrl">The Url for the resource</param>
        /// <param name="verb">The Http verb to use</param>
        /// <param name="payload">The payload, if specified.</param>
        /// <returns>Deserialized data of type <typeparamref name="T"/></returns>
        public T CallApi <T>(
            string resourceUrl,
            HttpMethod verb = null,
            string payload  = null)
        {
            if (verb == null)
            {
                verb = HttpMethod.Get;
            }

            var message = new HttpRequestMessage(verb, VssHttpUriUtility.ConcatUri(this.BaseAddress, resourceUrl));

            message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            if (verb == HttpMethod.Post || verb.Method == "PATCH")
            {
                message.Content = new StringContent(payload, null, "application/json");
            }

            return(this.SendAsync <T>(message).SyncResult());
        }