Exemple #1
0
        //<remarks>
        // Creates a new pet in the store.  Duplicates are allowed
        //</remarks>
        //<returns>
        // pet response
        //</returns>
        //<param name="pet">Pet to add to the store</param>
        public async Task <APIResponse <Pet> > addPetAsync(NewPet pet)
        {
            {
                var response = await httpClient.PostAsync(new Uri(url + "/pets", UriKind.Absolute), new SwaggerHTTPClientOptions(TimeSpan.FromSeconds(30)), new StringContent(JsonConvert.SerializeObject(pet)));

                if (response == null)
                {
                    return(new APIResponse <Pet>(false));
                }

                switch ((int)response.StatusCode)
                {
                case 200:
                {
                    var data = JsonConvert.DeserializeObject <Pet>(await response.Content.ReadAsStringAsync());
                    return(new APIResponse <Pet>(data, response.StatusCode));
                }

                case 200:
                {
                    var data = JsonConvert.DeserializeObject <Pet>(await response.Content.ReadAsStringAsync());
                    return(new APIResponse <Pet>(data, response.StatusCode));
                }

                default:
                {
                    return(new APIResponse <Pet>(response.StatusCode));
                }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Creates a new pet in the store.  Duplicates are allowed
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='pet'>
 /// Pet to add to the store
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <Pet> AddPetAsync(this ISwaggerPetstore operations, NewPet pet, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.AddPetWithHttpMessagesAsync(pet, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemple #3
0
        /// <summary>
        ///  Creates a new pet in the store.  Duplicates are allowed
        /// </summary>
        /// <param name="pet">Pet to add to the store</param>
        /// <returns>ApiResponse of Pet</returns>
        public ApiResponse <Pet> AddPetWithHttpInfo(NewPet pet)
        {
            // verify the required parameter 'pet' is set
            if (pet == null)
            {
                throw new ApiException(400, "Missing required parameter 'pet' when calling AddPet");
            }


            var path_ = "/pet";

            var    pathParams   = new Dictionary <String, String>();
            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

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

            if (http_header_accept != null)
            {
                headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
            }

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            pathParams.Add("format", "json");



            postBody = Configuration.ApiClient.Serialize(pet); // http body (model) parameter



            // make the HTTP request
            IRestResponse response = (IRestResponse)Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams);

            int statusCode = (int)response.StatusCode;

            if (statusCode >= 400)
            {
                throw new ApiException(statusCode, "Error calling AddPet: " + response.Content, response.Content);
            }
            else if (statusCode == 0)
            {
                throw new ApiException(statusCode, "Error calling AddPet: " + response.ErrorMessage, response.ErrorMessage);
            }

            return(new ApiResponse <Pet>(statusCode,
                                         response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                         (Pet)Configuration.ApiClient.Deserialize(response, typeof(Pet))));
        }
Exemple #4
0
 /// <summary>
 /// Creates a new pet in the store.  Duplicates are allowed
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='pet'>
 /// Pet to add to the store
 /// </param>
 public static Pet AddPet(this ISwaggerPetstore operations, NewPet pet)
 {
     return(Task.Factory.StartNew(s => ((ISwaggerPetstore)s).AddPetAsync(pet), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemple #5
0
        /// <summary>
        ///  Creates a new pet in the store.  Duplicates are allowed
        /// </summary>
        /// <param name="pet">Pet to add to the store</param>
        /// <returns>Task of Pet</returns>
        public async System.Threading.Tasks.Task <Pet> AddPetAsync(NewPet pet)
        {
            ApiResponse <Pet> response = await AddPetAsyncWithHttpInfo(pet);

            return(response.Data);
        }
Exemple #6
0
        /// <summary>
        ///  Creates a new pet in the store.  Duplicates are allowed
        /// </summary>
        /// <param name="pet">Pet to add to the store</param>
        /// <returns>Pet</returns>
        public Pet AddPet(NewPet pet)
        {
            ApiResponse <Pet> response = AddPetWithHttpInfo(pet);

            return(response.Data);
        }
        /// <summary>
        ///  Creates a new pet in the store.  Duplicates are allowed
        /// </summary>
        /// <param name="pet">Pet to add to the store</param>
        /// <returns>Task of ApiResponse (Pet)</returns>
        public async System.Threading.Tasks.Task<ApiResponse<Pet>> AddPetAsyncWithHttpInfo (NewPet pet)
        {
            // verify the required parameter 'pet' is set
            if (pet == null) throw new ApiException(400, "Missing required parameter 'pet' when calling AddPet");
            
    
            var path_ = "/pet";
    
            var pathParams = new Dictionary<String, String>();
            var queryParams = new Dictionary<String, String>();
            var headerParams = new Dictionary<String, String>();
            var formParams = new Dictionary<String, String>();
            var fileParams = new Dictionary<String, FileParameter>();
            String postBody = null;

            // to determine the Accept header
            String[] http_header_accepts = new String[] {
                "application/json"
            };
            String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
            if (http_header_accept != null)
                headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            pathParams.Add("format", "json");
            
            
            
            
            postBody = Configuration.ApiClient.Serialize(pet); // http body (model) parameter
            

            

            // make the HTTP request
            IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams);

            int statusCode = (int) response.StatusCode;
 
            if (statusCode >= 400)
                throw new ApiException (statusCode, "Error calling AddPet: " + response.Content, response.Content);
            else if (statusCode == 0)
                throw new ApiException (statusCode, "Error calling AddPet: " + response.ErrorMessage, response.ErrorMessage);

            return new ApiResponse<Pet>(statusCode,
                response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                (Pet) Configuration.ApiClient.Deserialize(response, typeof(Pet)));
            
        }
        /// <summary>
        ///  Creates a new pet in the store.  Duplicates are allowed
        /// </summary>
        /// <param name="pet">Pet to add to the store</param>
        /// <returns>Task of Pet</returns>
        public async System.Threading.Tasks.Task<Pet> AddPetAsync (NewPet pet)
        {
             ApiResponse<Pet> response = await AddPetAsyncWithHttpInfo(pet);
             return response.Data;

        }
 /// <summary>
 ///  Creates a new pet in the store.  Duplicates are allowed
 /// </summary>
 /// <param name="pet">Pet to add to the store</param> 
 /// <returns>Pet</returns>
 public Pet AddPet (NewPet pet)
 {
      ApiResponse<Pet> response = AddPetWithHttpInfo(pet);
      return response.Data;
 }
Exemple #10
0
 public override Task <HttpResponseMessage> AddPet([BindRequired, FromBody] NewPet body)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Creates a new pet in the store.  Duplicates are allowed
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='pet'>
 /// Pet to add to the store
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task<Pet> AddPetAsync(this ISwaggerPetstore operations, NewPet pet, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.AddPetWithHttpMessagesAsync(pet, null, cancellationToken).ConfigureAwait(false))
     {
         return _result.Body;
     }
 }
 /// <summary>
 /// Creates a new pet in the store.  Duplicates are allowed
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='pet'>
 /// Pet to add to the store
 /// </param>
 public static Pet AddPet(this ISwaggerPetstore operations, NewPet pet)
 {
     return Task.Factory.StartNew(s => ((ISwaggerPetstore)s).AddPetAsync(pet), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Exemple #13
0
        /// <summary>
        /// Creates a new pet in the store.  Duplicates are allowed
        /// </summary>
        /// <param name='pet'>
        /// Pet to add to the store
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <HttpOperationResponse <Pet> > AddPetWithHttpMessagesAsync(NewPet pet, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (pet == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "pet");
            }
            if (pet != null)
            {
                pet.Validate();
            }
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("pet", pet);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "AddPet", tracingParameters);
            }
            // Construct URL
            var _baseUrl = this.BaseUri.AbsoluteUri;
            var _url     = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "pets").ToString();
            // Create HTTP transport objects
            HttpRequestMessage  _httpRequest  = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("POST");
            _httpRequest.RequestUri = new Uri(_url);
            // Set Headers
            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            _requestContent      = SafeJsonConvert.SerializeObject(pet, this.SerializationSettings);
            _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
            _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await this.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if ((int)_statusCode != 200)
            {
                var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                try
                {
                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    Error _errorBody = SafeJsonConvert.DeserializeObject <Error>(_responseContent, this.DeserializationSettings);
                    if (_errorBody != null)
                    {
                        ex.Body = _errorBody;
                    }
                }
                catch (JsonException)
                {
                    // Ignore the exception
                }
                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new HttpOperationResponse <Pet>();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            // Deserialize Response
            if ((int)_statusCode == 200)
            {
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                try
                {
                    _result.Body = SafeJsonConvert.DeserializeObject <Pet>(_responseContent, this.DeserializationSettings);
                }
                catch (JsonException ex)
                {
                    _httpRequest.Dispose();
                    if (_httpResponse != null)
                    {
                        _httpResponse.Dispose();
                    }
                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
                }
            }
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }