示例#1
0
        /// <summary>
        /// Register a new user Create a new user.
        /// </summary>
        /// <exception cref="PollinationSDK.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="userCreate"></param>
        /// <param name="cancellationToken">Cancellation Token to cancel request (optional) </param>
        /// <returns>Task of ApiResponse (CreatedContent)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <CreatedContent> > CreateUserWithHttpInfoAsync(UserCreate userCreate, CancellationToken cancellationToken = default(CancellationToken))
        {
            // verify the required parameter 'userCreate' is set
            if (userCreate == null)
            {
                throw new ApiException(400, "Missing required parameter 'userCreate' when calling UserApi->CreateUser");
            }

            var    localVarPath         = "/user";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

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

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (userCreate != null && userCreate.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(userCreate); // http body (model) parameter
            }
            else
            {
                localVarPostBody = userCreate; // byte array
            }

            // authentication (JWTAuth) required
            // http bearer authentication required
            if (!String.IsNullOrEmpty(this.Configuration.AccessToken))
            {
                localVarHeaderParams["Authorization"] = "Bearer " + this.Configuration.AccessToken;
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType, cancellationToken);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("CreateUser", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <CreatedContent>(localVarStatusCode,
                                                    localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)),
                                                    (CreatedContent)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(CreatedContent))));
        }