예제 #1
0
        /// <summary>
        /// Used to obtain access tokens for the EPiServer ServiceAPI. request an access token for a username, password couplet - Authorize
        /// </summary>
        /// <param name="request">Models.TokenPostRequest</param>
        /// <param name="responseFormatters">response formmaters</param>
        public virtual async Task<Models.TokenPostResponse> Post(Models.TokenPostRequest request, IEnumerable<MediaTypeFormatter> responseFormatters = null)
        {

            var url = "token";
            var req = new HttpRequestMessage(HttpMethod.Post, url);

            if (request.RawHeaders != null)
            {
                foreach (var header in request.RawHeaders)
                {
                    req.Headers.TryAddWithoutValidation(header.Key, string.Join(",", header.Value));
                }
            }
            req.Content = request.Content;
            var response = await proxy.Client.SendAsync(req);
            if (proxy.SchemaValidation.Enabled && proxy.SchemaValidation.RaiseExceptions)
            {
                if (proxy.SchemaValidation.RaiseExceptions)
                {
                    await SchemaValidator.ValidateWithExceptionAsync(Models.TokenPostResponse.GetSchema(ApiMultipleResponse.GetValueAsString(response.StatusCode)), response.Content);
                }

            }
            return new Models.TokenPostResponse
            {
                RawContent = response.Content,
                RawHeaders = response.Headers,
                Formatters = responseFormatters,
                StatusCode = response.StatusCode,
                ReasonPhrase = response.ReasonPhrase,
                SchemaValidation = new Lazy<SchemaValidationResults>(() => SchemaValidator.IsValid(Models.TokenPostResponse.GetSchema(ApiMultipleResponse.GetValueAsString(response.StatusCode)), response.Content), true)
            };
        }
예제 #2
0
        /// <summary>
        /// Used to obtain access tokens for the EPiServer ServiceAPI. request an access token for a username, password couplet - Authorize
        /// </summary>
        /// <param name="json"></param>
        public virtual async Task<Models.TokenPostResponse> Post(string json)
        {

            var url = "token";
            var req = new HttpRequestMessage(HttpMethod.Post, url);
            req.Content = new StringContent(json);
            var response = await proxy.Client.SendAsync(req);

            if (proxy.SchemaValidation.Enabled)
            {
                if (proxy.SchemaValidation.RaiseExceptions)
                {
                    await SchemaValidator.ValidateWithExceptionAsync(Models.TokenPostResponse.GetSchema(ApiMultipleResponse.GetValueAsString(response.StatusCode)), response.Content);
                }

            }

            return new Models.TokenPostResponse
            {
                RawContent = response.Content,
                RawHeaders = response.Headers,
                StatusCode = response.StatusCode,
                ReasonPhrase = response.ReasonPhrase,
                SchemaValidation = new Lazy<SchemaValidationResults>(() => SchemaValidator.IsValid(Models.TokenPostResponse.GetSchema(ApiMultipleResponse.GetValueAsString(response.StatusCode)), response.Content), true)
            };

        }
예제 #3
0
        /// <summary>
        /// Versioning the EPiServer ServiceAPI. Obtain the version of the EPiServer ServiceAPI - Api Version
        /// </summary>
        /// <param name="request">ApiRequest</param>
        /// <param name="responseFormatters">response formmaters</param>
        public virtual async Task<Models.VersionGetResponse> Get(ApiRequest request, IEnumerable<MediaTypeFormatter> responseFormatters = null)
        {

            var url = "version";
            var req = new HttpRequestMessage(HttpMethod.Get, url);

            if (string.IsNullOrEmpty(proxy.OAuthAccessToken))
                throw new InvalidOperationException("This API call is secured with OAuth, you must provide an access token (set OAuthAccessToken before calling this method)");
            req.Headers.Add("Authorization", "Bearer " + proxy.OAuthAccessToken);
            if (request.RawHeaders != null)
            {
                foreach (var header in request.RawHeaders)
                {
                    req.Headers.TryAddWithoutValidation(header.Key, string.Join(",", header.Value));
                }
            }
            var response = await proxy.Client.SendAsync(req);
            if (proxy.SchemaValidation.Enabled && proxy.SchemaValidation.RaiseExceptions)
            {
                if (proxy.SchemaValidation.RaiseExceptions)
                {
                    await SchemaValidator.ValidateWithExceptionAsync("{  \"$schema\": \"http://json-schema.org/draft-04/schema#\",  \"title\": \"API Version\",  \"description\": \"A Version description for the EPiServer ServiceAPI\",  \"type\": \"object\",  \"properties\": {    \"Component\": {      \"type\": \"string\"    },    \"Version\": {      \"type\": \"string\"    }  },  \"required\": [\"Component\", \"Version\"]}", response.Content);
                }

            }
            return new Models.VersionGetResponse
            {
                RawContent = response.Content,
                RawHeaders = response.Headers,
                Formatters = responseFormatters,
                StatusCode = response.StatusCode,
                ReasonPhrase = response.ReasonPhrase,
                SchemaValidation = new Lazy<SchemaValidationResults>(() => SchemaValidator.IsValid("{  \"$schema\": \"http://json-schema.org/draft-04/schema#\",  \"title\": \"API Version\",  \"description\": \"A Version description for the EPiServer ServiceAPI\",  \"type\": \"object\",  \"properties\": {    \"Component\": {      \"type\": \"string\"    },    \"Version\": {      \"type\": \"string\"    }  },  \"required\": [\"Component\", \"Version\"]}", response.Content), true)
            };
        }
예제 #4
0
        /// <summary>
        /// gets an order by id
        /// </summary>
        /// <param name="id"></param>
        public virtual async Task <Models.OrdersGetResponse> Get(string id)
        {
            var url = "orders/{id}";

            url = url.Replace("{id}", id.ToString());
            var req      = new HttpRequestMessage(HttpMethod.Get, url);
            var response = await proxy.Client.SendAsync(req);

            if (proxy.SchemaValidation.Enabled)
            {
                if (proxy.SchemaValidation.RaiseExceptions)
                {
                    await SchemaValidator.ValidateWithExceptionAsync("", response.Content);
                }
            }

            return(new Models.OrdersGetResponse
            {
                RawContent = response.Content,
                RawHeaders = response.Headers,
                StatusCode = response.StatusCode,
                ReasonPhrase = response.ReasonPhrase,
                SchemaValidation = new Lazy <SchemaValidationResults>(() => SchemaValidator.IsValid("", response.Content), true)
            });
        }
예제 #5
0
        /// <summary>
        /// gets an order by id
        /// </summary>
        /// <param name="request">Models.OrdersGetRequest</param>
        /// <param name="responseFormatters">response formmaters</param>
        public virtual async Task <Models.OrdersGetResponse> Get(Models.OrdersGetRequest request, IEnumerable <MediaTypeFormatter> responseFormatters = null)
        {
            var url = "orders/{id}";

            if (request.UriParameters == null)
            {
                throw new InvalidOperationException("Uri Parameters cannot be null");
            }

            if (request.UriParameters.Id == null)
            {
                throw new InvalidOperationException("Uri Parameter Id cannot be null");
            }

            url = url.Replace("{id}", request.UriParameters.Id.ToString());
            var req = new HttpRequestMessage(HttpMethod.Get, url);

            if (request.RawHeaders != null)
            {
                foreach (var header in request.RawHeaders)
                {
                    req.Headers.TryAddWithoutValidation(header.Key, string.Join(",", header.Value));
                }
            }
            var response = await proxy.Client.SendAsync(req);

            if (proxy.SchemaValidation.Enabled && proxy.SchemaValidation.RaiseExceptions)
            {
                if (proxy.SchemaValidation.RaiseExceptions)
                {
                    await SchemaValidator.ValidateWithExceptionAsync("", response.Content);
                }
            }
            return(new Models.OrdersGetResponse
            {
                RawContent = response.Content,
                RawHeaders = response.Headers,
                Formatters = responseFormatters,
                StatusCode = response.StatusCode,
                ReasonPhrase = response.ReasonPhrase,
                SchemaValidation = new Lazy <SchemaValidationResults>(() => SchemaValidator.IsValid("", response.Content), true)
            });
        }