github.com/launchdarkly/api-client-go@v5.3.0+incompatible/api_data_export_destinations.go (about)

     1  
     2  /*
     3   * LaunchDarkly REST API
     4   *
     5   * Build custom integrations with the LaunchDarkly REST API
     6   *
     7   * API version: 5.3.0
     8   * Contact: support@launchdarkly.com
     9   * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
    10   */
    11  
    12  package ldapi
    13  
    14  import (
    15  	"context"
    16  	"io/ioutil"
    17  	"net/http"
    18  	"net/url"
    19  	"strings"
    20  	"fmt"
    21  )
    22  
    23  // Linger please
    24  var (
    25  	_ context.Context
    26  )
    27  
    28  type DataExportDestinationsApiService service
    29  
    30  /*
    31  DataExportDestinationsApiService Get a single data export destination by ID
    32   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
    33   * @param projectKey The project key, used to tie the flags together under one project so they can be managed together.
    34   * @param environmentKey The environment key, used to tie together flag configuration and users under one environment so they can be managed together.
    35   * @param destinationId The data export destination ID.
    36  
    37  
    38  */
    39  func (a *DataExportDestinationsApiService) DeleteDestination(ctx context.Context, projectKey string, environmentKey string, destinationId string) (*http.Response, error) {
    40  	var (
    41  		localVarHttpMethod = strings.ToUpper("Delete")
    42  		localVarPostBody   interface{}
    43  		localVarFileName   string
    44  		localVarFileBytes  []byte
    45  		
    46  	)
    47  
    48  	// create path and map variables
    49  	localVarPath := a.client.cfg.BasePath + "/destinations/{projectKey}/{environmentKey}/{destinationId}"
    50  	localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
    51  	localVarPath = strings.Replace(localVarPath, "{"+"environmentKey"+"}", fmt.Sprintf("%v", environmentKey), -1)
    52  	localVarPath = strings.Replace(localVarPath, "{"+"destinationId"+"}", fmt.Sprintf("%v", destinationId), -1)
    53  
    54  	localVarHeaderParams := make(map[string]string)
    55  	localVarQueryParams := url.Values{}
    56  	localVarFormParams := url.Values{}
    57  
    58  	// to determine the Content-Type header
    59  	localVarHttpContentTypes := []string{"application/json"}
    60  
    61  	// set Content-Type header
    62  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
    63  	if localVarHttpContentType != "" {
    64  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
    65  	}
    66  
    67  	// to determine the Accept header
    68  	localVarHttpHeaderAccepts := []string{"application/json"}
    69  
    70  	// set Accept header
    71  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
    72  	if localVarHttpHeaderAccept != "" {
    73  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
    74  	}
    75  	if ctx != nil {
    76  		// API Key Authentication
    77  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
    78  			var key string
    79  			if auth.Prefix != "" {
    80  				key = auth.Prefix + " " + auth.Key
    81  			} else {
    82  				key = auth.Key
    83  			}
    84  			localVarHeaderParams["Authorization"] = key
    85  			
    86  		}
    87  	}
    88  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  
    93  	localVarHttpResponse, err := a.client.callAPI(r)
    94  	if err != nil || localVarHttpResponse == nil {
    95  		return localVarHttpResponse, err
    96  	}
    97  
    98  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
    99  	localVarHttpResponse.Body.Close()
   100  	if err != nil {
   101  		return localVarHttpResponse, err
   102  	}
   103  
   104  
   105  	if localVarHttpResponse.StatusCode >= 300 {
   106  		newErr := GenericSwaggerError{
   107  			body: localVarBody,
   108  			error: localVarHttpResponse.Status,
   109  		}
   110  		
   111  		return localVarHttpResponse, newErr
   112  	}
   113  
   114  	return localVarHttpResponse, nil
   115  }
   116  
   117  /*
   118  DataExportDestinationsApiService Get a single data export destination by ID
   119   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   120   * @param projectKey The project key, used to tie the flags together under one project so they can be managed together.
   121   * @param environmentKey The environment key, used to tie together flag configuration and users under one environment so they can be managed together.
   122   * @param destinationId The data export destination ID.
   123  
   124  @return Destination
   125  */
   126  func (a *DataExportDestinationsApiService) GetDestination(ctx context.Context, projectKey string, environmentKey string, destinationId string) (Destination, *http.Response, error) {
   127  	var (
   128  		localVarHttpMethod = strings.ToUpper("Get")
   129  		localVarPostBody   interface{}
   130  		localVarFileName   string
   131  		localVarFileBytes  []byte
   132  		localVarReturnValue Destination
   133  	)
   134  
   135  	// create path and map variables
   136  	localVarPath := a.client.cfg.BasePath + "/destinations/{projectKey}/{environmentKey}/{destinationId}"
   137  	localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
   138  	localVarPath = strings.Replace(localVarPath, "{"+"environmentKey"+"}", fmt.Sprintf("%v", environmentKey), -1)
   139  	localVarPath = strings.Replace(localVarPath, "{"+"destinationId"+"}", fmt.Sprintf("%v", destinationId), -1)
   140  
   141  	localVarHeaderParams := make(map[string]string)
   142  	localVarQueryParams := url.Values{}
   143  	localVarFormParams := url.Values{}
   144  
   145  	// to determine the Content-Type header
   146  	localVarHttpContentTypes := []string{"application/json"}
   147  
   148  	// set Content-Type header
   149  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   150  	if localVarHttpContentType != "" {
   151  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   152  	}
   153  
   154  	// to determine the Accept header
   155  	localVarHttpHeaderAccepts := []string{"application/json"}
   156  
   157  	// set Accept header
   158  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   159  	if localVarHttpHeaderAccept != "" {
   160  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   161  	}
   162  	if ctx != nil {
   163  		// API Key Authentication
   164  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   165  			var key string
   166  			if auth.Prefix != "" {
   167  				key = auth.Prefix + " " + auth.Key
   168  			} else {
   169  				key = auth.Key
   170  			}
   171  			localVarHeaderParams["Authorization"] = key
   172  			
   173  		}
   174  	}
   175  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   176  	if err != nil {
   177  		return localVarReturnValue, nil, err
   178  	}
   179  
   180  	localVarHttpResponse, err := a.client.callAPI(r)
   181  	if err != nil || localVarHttpResponse == nil {
   182  		return localVarReturnValue, localVarHttpResponse, err
   183  	}
   184  
   185  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   186  	localVarHttpResponse.Body.Close()
   187  	if err != nil {
   188  		return localVarReturnValue, localVarHttpResponse, err
   189  	}
   190  
   191  	if localVarHttpResponse.StatusCode < 300 {
   192  		// If we succeed, return the data, otherwise pass on to decode error.
   193  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   194  		return localVarReturnValue, localVarHttpResponse, err
   195  	}
   196  
   197  	if localVarHttpResponse.StatusCode >= 300 {
   198  		newErr := GenericSwaggerError{
   199  			body: localVarBody,
   200  			error: localVarHttpResponse.Status,
   201  		}
   202  		
   203  		if localVarHttpResponse.StatusCode == 200 {
   204  			var v Destination
   205  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   206  				if err != nil {
   207  					newErr.error = err.Error()
   208  					return localVarReturnValue, localVarHttpResponse, newErr
   209  				}
   210  				newErr.model = v
   211  				return localVarReturnValue, localVarHttpResponse, newErr
   212  		}
   213  		
   214  		return localVarReturnValue, localVarHttpResponse, newErr
   215  	}
   216  
   217  	return localVarReturnValue, localVarHttpResponse, nil
   218  }
   219  
   220  /*
   221  DataExportDestinationsApiService Returns a list of all data export destinations.
   222   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   223  
   224  @return Destinations
   225  */
   226  func (a *DataExportDestinationsApiService) GetDestinations(ctx context.Context) (Destinations, *http.Response, error) {
   227  	var (
   228  		localVarHttpMethod = strings.ToUpper("Get")
   229  		localVarPostBody   interface{}
   230  		localVarFileName   string
   231  		localVarFileBytes  []byte
   232  		localVarReturnValue Destinations
   233  	)
   234  
   235  	// create path and map variables
   236  	localVarPath := a.client.cfg.BasePath + "/destinations"
   237  
   238  	localVarHeaderParams := make(map[string]string)
   239  	localVarQueryParams := url.Values{}
   240  	localVarFormParams := url.Values{}
   241  
   242  	// to determine the Content-Type header
   243  	localVarHttpContentTypes := []string{"application/json"}
   244  
   245  	// set Content-Type header
   246  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   247  	if localVarHttpContentType != "" {
   248  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   249  	}
   250  
   251  	// to determine the Accept header
   252  	localVarHttpHeaderAccepts := []string{"application/json"}
   253  
   254  	// set Accept header
   255  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   256  	if localVarHttpHeaderAccept != "" {
   257  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   258  	}
   259  	if ctx != nil {
   260  		// API Key Authentication
   261  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   262  			var key string
   263  			if auth.Prefix != "" {
   264  				key = auth.Prefix + " " + auth.Key
   265  			} else {
   266  				key = auth.Key
   267  			}
   268  			localVarHeaderParams["Authorization"] = key
   269  			
   270  		}
   271  	}
   272  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   273  	if err != nil {
   274  		return localVarReturnValue, nil, err
   275  	}
   276  
   277  	localVarHttpResponse, err := a.client.callAPI(r)
   278  	if err != nil || localVarHttpResponse == nil {
   279  		return localVarReturnValue, localVarHttpResponse, err
   280  	}
   281  
   282  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   283  	localVarHttpResponse.Body.Close()
   284  	if err != nil {
   285  		return localVarReturnValue, localVarHttpResponse, err
   286  	}
   287  
   288  	if localVarHttpResponse.StatusCode < 300 {
   289  		// If we succeed, return the data, otherwise pass on to decode error.
   290  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   291  		return localVarReturnValue, localVarHttpResponse, err
   292  	}
   293  
   294  	if localVarHttpResponse.StatusCode >= 300 {
   295  		newErr := GenericSwaggerError{
   296  			body: localVarBody,
   297  			error: localVarHttpResponse.Status,
   298  		}
   299  		
   300  		if localVarHttpResponse.StatusCode == 200 {
   301  			var v Destinations
   302  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   303  				if err != nil {
   304  					newErr.error = err.Error()
   305  					return localVarReturnValue, localVarHttpResponse, newErr
   306  				}
   307  				newErr.model = v
   308  				return localVarReturnValue, localVarHttpResponse, newErr
   309  		}
   310  		
   311  		return localVarReturnValue, localVarHttpResponse, newErr
   312  	}
   313  
   314  	return localVarReturnValue, localVarHttpResponse, nil
   315  }
   316  
   317  /*
   318  DataExportDestinationsApiService Perform a partial update to a data export destination.
   319   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   320   * @param projectKey The project key, used to tie the flags together under one project so they can be managed together.
   321   * @param environmentKey The environment key, used to tie together flag configuration and users under one environment so they can be managed together.
   322   * @param destinationId The data export destination ID.
   323   * @param patchOnly Requires a JSON Patch representation of the desired changes to the project. &#39;http://jsonpatch.com/&#39; Feature flag patches also support JSON Merge Patch format. &#39;https://tools.ietf.org/html/rfc7386&#39; The addition of comments is also supported.
   324  
   325  @return Destination
   326  */
   327  func (a *DataExportDestinationsApiService) PatchDestination(ctx context.Context, projectKey string, environmentKey string, destinationId string, patchOnly []PatchOperation) (Destination, *http.Response, error) {
   328  	var (
   329  		localVarHttpMethod = strings.ToUpper("Patch")
   330  		localVarPostBody   interface{}
   331  		localVarFileName   string
   332  		localVarFileBytes  []byte
   333  		localVarReturnValue Destination
   334  	)
   335  
   336  	// create path and map variables
   337  	localVarPath := a.client.cfg.BasePath + "/destinations/{projectKey}/{environmentKey}/{destinationId}"
   338  	localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
   339  	localVarPath = strings.Replace(localVarPath, "{"+"environmentKey"+"}", fmt.Sprintf("%v", environmentKey), -1)
   340  	localVarPath = strings.Replace(localVarPath, "{"+"destinationId"+"}", fmt.Sprintf("%v", destinationId), -1)
   341  
   342  	localVarHeaderParams := make(map[string]string)
   343  	localVarQueryParams := url.Values{}
   344  	localVarFormParams := url.Values{}
   345  
   346  	// to determine the Content-Type header
   347  	localVarHttpContentTypes := []string{"application/json"}
   348  
   349  	// set Content-Type header
   350  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   351  	if localVarHttpContentType != "" {
   352  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   353  	}
   354  
   355  	// to determine the Accept header
   356  	localVarHttpHeaderAccepts := []string{"application/json"}
   357  
   358  	// set Accept header
   359  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   360  	if localVarHttpHeaderAccept != "" {
   361  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   362  	}
   363  	// body params
   364  	localVarPostBody = &patchOnly
   365  	if ctx != nil {
   366  		// API Key Authentication
   367  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   368  			var key string
   369  			if auth.Prefix != "" {
   370  				key = auth.Prefix + " " + auth.Key
   371  			} else {
   372  				key = auth.Key
   373  			}
   374  			localVarHeaderParams["Authorization"] = key
   375  			
   376  		}
   377  	}
   378  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   379  	if err != nil {
   380  		return localVarReturnValue, nil, err
   381  	}
   382  
   383  	localVarHttpResponse, err := a.client.callAPI(r)
   384  	if err != nil || localVarHttpResponse == nil {
   385  		return localVarReturnValue, localVarHttpResponse, err
   386  	}
   387  
   388  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   389  	localVarHttpResponse.Body.Close()
   390  	if err != nil {
   391  		return localVarReturnValue, localVarHttpResponse, err
   392  	}
   393  
   394  	if localVarHttpResponse.StatusCode < 300 {
   395  		// If we succeed, return the data, otherwise pass on to decode error.
   396  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   397  		return localVarReturnValue, localVarHttpResponse, err
   398  	}
   399  
   400  	if localVarHttpResponse.StatusCode >= 300 {
   401  		newErr := GenericSwaggerError{
   402  			body: localVarBody,
   403  			error: localVarHttpResponse.Status,
   404  		}
   405  		
   406  		if localVarHttpResponse.StatusCode == 200 {
   407  			var v Destination
   408  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   409  				if err != nil {
   410  					newErr.error = err.Error()
   411  					return localVarReturnValue, localVarHttpResponse, newErr
   412  				}
   413  				newErr.model = v
   414  				return localVarReturnValue, localVarHttpResponse, newErr
   415  		}
   416  		
   417  		return localVarReturnValue, localVarHttpResponse, newErr
   418  	}
   419  
   420  	return localVarReturnValue, localVarHttpResponse, nil
   421  }
   422  
   423  /*
   424  DataExportDestinationsApiService Create a new data export destination
   425   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   426   * @param projectKey The project key, used to tie the flags together under one project so they can be managed together.
   427   * @param environmentKey The environment key, used to tie together flag configuration and users under one environment so they can be managed together.
   428   * @param destinationBody Create a new data export destination.
   429  
   430  @return Destination
   431  */
   432  func (a *DataExportDestinationsApiService) PostDestination(ctx context.Context, projectKey string, environmentKey string, destinationBody DestinationBody) (Destination, *http.Response, error) {
   433  	var (
   434  		localVarHttpMethod = strings.ToUpper("Post")
   435  		localVarPostBody   interface{}
   436  		localVarFileName   string
   437  		localVarFileBytes  []byte
   438  		localVarReturnValue Destination
   439  	)
   440  
   441  	// create path and map variables
   442  	localVarPath := a.client.cfg.BasePath + "/destinations/{projectKey}/{environmentKey}"
   443  	localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
   444  	localVarPath = strings.Replace(localVarPath, "{"+"environmentKey"+"}", fmt.Sprintf("%v", environmentKey), -1)
   445  
   446  	localVarHeaderParams := make(map[string]string)
   447  	localVarQueryParams := url.Values{}
   448  	localVarFormParams := url.Values{}
   449  
   450  	// to determine the Content-Type header
   451  	localVarHttpContentTypes := []string{"application/json"}
   452  
   453  	// set Content-Type header
   454  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   455  	if localVarHttpContentType != "" {
   456  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   457  	}
   458  
   459  	// to determine the Accept header
   460  	localVarHttpHeaderAccepts := []string{"application/json"}
   461  
   462  	// set Accept header
   463  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   464  	if localVarHttpHeaderAccept != "" {
   465  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   466  	}
   467  	// body params
   468  	localVarPostBody = &destinationBody
   469  	if ctx != nil {
   470  		// API Key Authentication
   471  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   472  			var key string
   473  			if auth.Prefix != "" {
   474  				key = auth.Prefix + " " + auth.Key
   475  			} else {
   476  				key = auth.Key
   477  			}
   478  			localVarHeaderParams["Authorization"] = key
   479  			
   480  		}
   481  	}
   482  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   483  	if err != nil {
   484  		return localVarReturnValue, nil, err
   485  	}
   486  
   487  	localVarHttpResponse, err := a.client.callAPI(r)
   488  	if err != nil || localVarHttpResponse == nil {
   489  		return localVarReturnValue, localVarHttpResponse, err
   490  	}
   491  
   492  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   493  	localVarHttpResponse.Body.Close()
   494  	if err != nil {
   495  		return localVarReturnValue, localVarHttpResponse, err
   496  	}
   497  
   498  	if localVarHttpResponse.StatusCode < 300 {
   499  		// If we succeed, return the data, otherwise pass on to decode error.
   500  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   501  		return localVarReturnValue, localVarHttpResponse, err
   502  	}
   503  
   504  	if localVarHttpResponse.StatusCode >= 300 {
   505  		newErr := GenericSwaggerError{
   506  			body: localVarBody,
   507  			error: localVarHttpResponse.Status,
   508  		}
   509  		
   510  		if localVarHttpResponse.StatusCode == 201 {
   511  			var v Destination
   512  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   513  				if err != nil {
   514  					newErr.error = err.Error()
   515  					return localVarReturnValue, localVarHttpResponse, newErr
   516  				}
   517  				newErr.model = v
   518  				return localVarReturnValue, localVarHttpResponse, newErr
   519  		}
   520  		
   521  		return localVarReturnValue, localVarHttpResponse, newErr
   522  	}
   523  
   524  	return localVarReturnValue, localVarHttpResponse, nil
   525  }
   526