bunnyshell.com/sdk@v0.16.0/api_event.go (about)

     1  /*
     2  API Bunnyshell Environments
     3  
     4  Interact with Bunnyshell Platform
     5  
     6  API version: 1.1.0
     7  Contact: osi+support@bunnyshell.com
     8  */
     9  
    10  // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
    11  
    12  package sdk
    13  
    14  import (
    15  	"bytes"
    16  	"context"
    17  	"io"
    18  	"net/http"
    19  	"net/url"
    20  	"strings"
    21  )
    22  
    23  // EventAPIService EventAPI service
    24  type EventAPIService service
    25  
    26  type ApiEventListRequest struct {
    27  	ctx          context.Context
    28  	ApiService   *EventAPIService
    29  	page         *int32
    30  	type_        *string
    31  	status       *string
    32  	environment  *string
    33  	organization *string
    34  }
    35  
    36  // The collection page number
    37  func (r ApiEventListRequest) Page(page int32) ApiEventListRequest {
    38  	r.page = &page
    39  	return r
    40  }
    41  
    42  // Filter by type
    43  func (r ApiEventListRequest) Type_(type_ string) ApiEventListRequest {
    44  	r.type_ = &type_
    45  	return r
    46  }
    47  
    48  // Filter by status
    49  func (r ApiEventListRequest) Status(status string) ApiEventListRequest {
    50  	r.status = &status
    51  	return r
    52  }
    53  
    54  // Filter by environment
    55  func (r ApiEventListRequest) Environment(environment string) ApiEventListRequest {
    56  	r.environment = &environment
    57  	return r
    58  }
    59  
    60  // Filter by organization
    61  func (r ApiEventListRequest) Organization(organization string) ApiEventListRequest {
    62  	r.organization = &organization
    63  	return r
    64  }
    65  
    66  func (r ApiEventListRequest) Execute() (*PaginatedEventCollection, *http.Response, error) {
    67  	return r.ApiService.EventListExecute(r)
    68  }
    69  
    70  /*
    71  EventList List events matching any selected filters.
    72  
    73  List events matching any selected filters.
    74  
    75  	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
    76  	@return ApiEventListRequest
    77  */
    78  func (a *EventAPIService) EventList(ctx context.Context) ApiEventListRequest {
    79  	return ApiEventListRequest{
    80  		ApiService: a,
    81  		ctx:        ctx,
    82  	}
    83  }
    84  
    85  // Execute executes the request
    86  //
    87  //	@return PaginatedEventCollection
    88  func (a *EventAPIService) EventListExecute(r ApiEventListRequest) (*PaginatedEventCollection, *http.Response, error) {
    89  	var (
    90  		localVarHTTPMethod  = http.MethodGet
    91  		localVarPostBody    interface{}
    92  		formFiles           []formFile
    93  		localVarReturnValue *PaginatedEventCollection
    94  	)
    95  
    96  	localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "EventAPIService.EventList")
    97  	if err != nil {
    98  		return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
    99  	}
   100  
   101  	localVarPath := localBasePath + "/v1/events"
   102  
   103  	localVarHeaderParams := make(map[string]string)
   104  	localVarQueryParams := url.Values{}
   105  	localVarFormParams := url.Values{}
   106  
   107  	if r.page != nil {
   108  		parameterAddToHeaderOrQuery(localVarQueryParams, "page", r.page, "")
   109  	} else {
   110  		var defaultValue int32 = 1
   111  		r.page = &defaultValue
   112  	}
   113  	if r.type_ != nil {
   114  		parameterAddToHeaderOrQuery(localVarQueryParams, "type", r.type_, "")
   115  	}
   116  	if r.status != nil {
   117  		parameterAddToHeaderOrQuery(localVarQueryParams, "status", r.status, "")
   118  	}
   119  	if r.environment != nil {
   120  		parameterAddToHeaderOrQuery(localVarQueryParams, "environment", r.environment, "")
   121  	}
   122  	if r.organization != nil {
   123  		parameterAddToHeaderOrQuery(localVarQueryParams, "organization", r.organization, "")
   124  	}
   125  	// to determine the Content-Type header
   126  	localVarHTTPContentTypes := []string{}
   127  
   128  	// set Content-Type header
   129  	localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
   130  	if localVarHTTPContentType != "" {
   131  		localVarHeaderParams["Content-Type"] = localVarHTTPContentType
   132  	}
   133  
   134  	// to determine the Accept header
   135  	localVarHTTPHeaderAccepts := []string{"application/hal+json", "application/problem+json"}
   136  
   137  	// set Accept header
   138  	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
   139  	if localVarHTTPHeaderAccept != "" {
   140  		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
   141  	}
   142  	if r.ctx != nil {
   143  		// API Key Authentication
   144  		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
   145  			if apiKey, ok := auth["JWT"]; ok {
   146  				var key string
   147  				if apiKey.Prefix != "" {
   148  					key = apiKey.Prefix + " " + apiKey.Key
   149  				} else {
   150  					key = apiKey.Key
   151  				}
   152  				localVarHeaderParams["Authorization"] = key
   153  			}
   154  		}
   155  	}
   156  	if r.ctx != nil {
   157  		// API Key Authentication
   158  		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
   159  			if apiKey, ok := auth["ApiKeyAuth"]; ok {
   160  				var key string
   161  				if apiKey.Prefix != "" {
   162  					key = apiKey.Prefix + " " + apiKey.Key
   163  				} else {
   164  					key = apiKey.Key
   165  				}
   166  				localVarHeaderParams["X-Auth-Token"] = key
   167  			}
   168  		}
   169  	}
   170  	req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
   171  	if err != nil {
   172  		return localVarReturnValue, nil, err
   173  	}
   174  
   175  	localVarHTTPResponse, err := a.client.callAPI(req)
   176  	if err != nil || localVarHTTPResponse == nil {
   177  		return localVarReturnValue, localVarHTTPResponse, err
   178  	}
   179  
   180  	localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
   181  	localVarHTTPResponse.Body.Close()
   182  	localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
   183  	if err != nil {
   184  		return localVarReturnValue, localVarHTTPResponse, err
   185  	}
   186  
   187  	if localVarHTTPResponse.StatusCode >= 300 {
   188  		newErr := &GenericOpenAPIError{
   189  			body:  localVarBody,
   190  			error: localVarHTTPResponse.Status,
   191  		}
   192  		if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 {
   193  			var v ProblemGeneric
   194  			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
   195  			if err != nil {
   196  				newErr.error = err.Error()
   197  				return localVarReturnValue, localVarHTTPResponse, newErr
   198  			}
   199  			newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
   200  			newErr.model = v
   201  		}
   202  		return localVarReturnValue, localVarHTTPResponse, newErr
   203  	}
   204  
   205  	err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
   206  	if err != nil {
   207  		newErr := &GenericOpenAPIError{
   208  			body:  localVarBody,
   209  			error: err.Error(),
   210  		}
   211  		return localVarReturnValue, localVarHTTPResponse, newErr
   212  	}
   213  
   214  	return localVarReturnValue, localVarHTTPResponse, nil
   215  }
   216  
   217  type ApiEventViewRequest struct {
   218  	ctx        context.Context
   219  	ApiService *EventAPIService
   220  	id         string
   221  }
   222  
   223  func (r ApiEventViewRequest) Execute() (*EventItem, *http.Response, error) {
   224  	return r.ApiService.EventViewExecute(r)
   225  }
   226  
   227  /*
   228  EventView View a specific event.
   229  
   230  View a specific event.
   231  
   232  	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   233  	@param id Resource identifier
   234  	@return ApiEventViewRequest
   235  */
   236  func (a *EventAPIService) EventView(ctx context.Context, id string) ApiEventViewRequest {
   237  	return ApiEventViewRequest{
   238  		ApiService: a,
   239  		ctx:        ctx,
   240  		id:         id,
   241  	}
   242  }
   243  
   244  // Execute executes the request
   245  //
   246  //	@return EventItem
   247  func (a *EventAPIService) EventViewExecute(r ApiEventViewRequest) (*EventItem, *http.Response, error) {
   248  	var (
   249  		localVarHTTPMethod  = http.MethodGet
   250  		localVarPostBody    interface{}
   251  		formFiles           []formFile
   252  		localVarReturnValue *EventItem
   253  	)
   254  
   255  	localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "EventAPIService.EventView")
   256  	if err != nil {
   257  		return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
   258  	}
   259  
   260  	localVarPath := localBasePath + "/v1/events/{id}"
   261  	localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1)
   262  
   263  	localVarHeaderParams := make(map[string]string)
   264  	localVarQueryParams := url.Values{}
   265  	localVarFormParams := url.Values{}
   266  
   267  	// to determine the Content-Type header
   268  	localVarHTTPContentTypes := []string{}
   269  
   270  	// set Content-Type header
   271  	localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
   272  	if localVarHTTPContentType != "" {
   273  		localVarHeaderParams["Content-Type"] = localVarHTTPContentType
   274  	}
   275  
   276  	// to determine the Accept header
   277  	localVarHTTPHeaderAccepts := []string{"application/hal+json", "application/problem+json"}
   278  
   279  	// set Accept header
   280  	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
   281  	if localVarHTTPHeaderAccept != "" {
   282  		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
   283  	}
   284  	if r.ctx != nil {
   285  		// API Key Authentication
   286  		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
   287  			if apiKey, ok := auth["JWT"]; ok {
   288  				var key string
   289  				if apiKey.Prefix != "" {
   290  					key = apiKey.Prefix + " " + apiKey.Key
   291  				} else {
   292  					key = apiKey.Key
   293  				}
   294  				localVarHeaderParams["Authorization"] = key
   295  			}
   296  		}
   297  	}
   298  	if r.ctx != nil {
   299  		// API Key Authentication
   300  		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
   301  			if apiKey, ok := auth["ApiKeyAuth"]; ok {
   302  				var key string
   303  				if apiKey.Prefix != "" {
   304  					key = apiKey.Prefix + " " + apiKey.Key
   305  				} else {
   306  					key = apiKey.Key
   307  				}
   308  				localVarHeaderParams["X-Auth-Token"] = key
   309  			}
   310  		}
   311  	}
   312  	req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
   313  	if err != nil {
   314  		return localVarReturnValue, nil, err
   315  	}
   316  
   317  	localVarHTTPResponse, err := a.client.callAPI(req)
   318  	if err != nil || localVarHTTPResponse == nil {
   319  		return localVarReturnValue, localVarHTTPResponse, err
   320  	}
   321  
   322  	localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
   323  	localVarHTTPResponse.Body.Close()
   324  	localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
   325  	if err != nil {
   326  		return localVarReturnValue, localVarHTTPResponse, err
   327  	}
   328  
   329  	if localVarHTTPResponse.StatusCode >= 300 {
   330  		newErr := &GenericOpenAPIError{
   331  			body:  localVarBody,
   332  			error: localVarHTTPResponse.Status,
   333  		}
   334  		if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 {
   335  			var v ProblemGeneric
   336  			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
   337  			if err != nil {
   338  				newErr.error = err.Error()
   339  				return localVarReturnValue, localVarHTTPResponse, newErr
   340  			}
   341  			newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
   342  			newErr.model = v
   343  		}
   344  		return localVarReturnValue, localVarHTTPResponse, newErr
   345  	}
   346  
   347  	err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
   348  	if err != nil {
   349  		newErr := &GenericOpenAPIError{
   350  			body:  localVarBody,
   351  			error: err.Error(),
   352  		}
   353  		return localVarReturnValue, localVarHTTPResponse, newErr
   354  	}
   355  
   356  	return localVarReturnValue, localVarHTTPResponse, nil
   357  }