github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/task-tracker/client/tasks/tasks_client.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package tasks
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"github.com/go-openapi/runtime"
    10  	httptransport "github.com/go-openapi/runtime/client"
    11  	"github.com/go-openapi/strfmt"
    12  )
    13  
    14  // New creates a new tasks API client.
    15  func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
    16  	return &Client{transport: transport, formats: formats}
    17  }
    18  
    19  // New creates a new tasks API client with basic auth credentials.
    20  // It takes the following parameters:
    21  // - host: http host (github.com).
    22  // - basePath: any base path for the API client ("/v1", "/v3").
    23  // - scheme: http scheme ("http", "https").
    24  // - user: user for basic authentication header.
    25  // - password: password for basic authentication header.
    26  func NewClientWithBasicAuth(host, basePath, scheme, user, password string) ClientService {
    27  	transport := httptransport.New(host, basePath, []string{scheme})
    28  	transport.DefaultAuthentication = httptransport.BasicAuth(user, password)
    29  	return &Client{transport: transport, formats: strfmt.Default}
    30  }
    31  
    32  // New creates a new tasks API client with a bearer token for authentication.
    33  // It takes the following parameters:
    34  // - host: http host (github.com).
    35  // - basePath: any base path for the API client ("/v1", "/v3").
    36  // - scheme: http scheme ("http", "https").
    37  // - bearerToken: bearer token for Bearer authentication header.
    38  func NewClientWithBearerToken(host, basePath, scheme, bearerToken string) ClientService {
    39  	transport := httptransport.New(host, basePath, []string{scheme})
    40  	transport.DefaultAuthentication = httptransport.BearerToken(bearerToken)
    41  	return &Client{transport: transport, formats: strfmt.Default}
    42  }
    43  
    44  /*
    45  Client for tasks API
    46  */
    47  type Client struct {
    48  	transport runtime.ClientTransport
    49  	formats   strfmt.Registry
    50  }
    51  
    52  // ClientOption is the option for Client methods
    53  type ClientOption func(*runtime.ClientOperation)
    54  
    55  // ClientService is the interface for Client methods
    56  type ClientService interface {
    57  	AddCommentToTask(params *AddCommentToTaskParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*AddCommentToTaskCreated, error)
    58  
    59  	CreateTask(params *CreateTaskParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateTaskCreated, error)
    60  
    61  	DeleteTask(params *DeleteTaskParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteTaskNoContent, error)
    62  
    63  	GetTaskComments(params *GetTaskCommentsParams, opts ...ClientOption) (*GetTaskCommentsOK, error)
    64  
    65  	GetTaskDetails(params *GetTaskDetailsParams, opts ...ClientOption) (*GetTaskDetailsOK, error)
    66  
    67  	ListTasks(params *ListTasksParams, opts ...ClientOption) (*ListTasksOK, error)
    68  
    69  	UpdateTask(params *UpdateTaskParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateTaskOK, error)
    70  
    71  	UploadTaskFile(params *UploadTaskFileParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UploadTaskFileCreated, error)
    72  
    73  	SetTransport(transport runtime.ClientTransport)
    74  }
    75  
    76  /*
    77  	AddCommentToTask adds a comment to a task
    78  
    79  	The comment can contain ___github markdown___ syntax.
    80  
    81  Fenced codeblocks etc are supported through pygments.
    82  */
    83  func (a *Client) AddCommentToTask(params *AddCommentToTaskParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*AddCommentToTaskCreated, error) {
    84  	// TODO: Validate the params before sending
    85  	if params == nil {
    86  		params = NewAddCommentToTaskParams()
    87  	}
    88  	op := &runtime.ClientOperation{
    89  		ID:                 "addCommentToTask",
    90  		Method:             "POST",
    91  		PathPattern:        "/tasks/{id}/comments",
    92  		ProducesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
    93  		ConsumesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
    94  		Schemes:            []string{"http", "https"},
    95  		Params:             params,
    96  		Reader:             &AddCommentToTaskReader{formats: a.formats},
    97  		AuthInfo:           authInfo,
    98  		Context:            params.Context,
    99  		Client:             params.HTTPClient,
   100  	}
   101  	for _, opt := range opts {
   102  		opt(op)
   103  	}
   104  
   105  	result, err := a.transport.Submit(op)
   106  	if err != nil {
   107  		return nil, err
   108  	}
   109  	success, ok := result.(*AddCommentToTaskCreated)
   110  	if ok {
   111  		return success, nil
   112  	}
   113  	// unexpected success response
   114  	unexpectedSuccess := result.(*AddCommentToTaskDefault)
   115  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   116  }
   117  
   118  /*
   119  	CreateTask creates a task object
   120  
   121  	Allows for creating a task.
   122  
   123  This operation requires authentication so that we know which user
   124  created the task.
   125  */
   126  func (a *Client) CreateTask(params *CreateTaskParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateTaskCreated, error) {
   127  	// TODO: Validate the params before sending
   128  	if params == nil {
   129  		params = NewCreateTaskParams()
   130  	}
   131  	op := &runtime.ClientOperation{
   132  		ID:                 "createTask",
   133  		Method:             "POST",
   134  		PathPattern:        "/tasks",
   135  		ProducesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   136  		ConsumesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   137  		Schemes:            []string{"http", "https"},
   138  		Params:             params,
   139  		Reader:             &CreateTaskReader{formats: a.formats},
   140  		AuthInfo:           authInfo,
   141  		Context:            params.Context,
   142  		Client:             params.HTTPClient,
   143  	}
   144  	for _, opt := range opts {
   145  		opt(op)
   146  	}
   147  
   148  	result, err := a.transport.Submit(op)
   149  	if err != nil {
   150  		return nil, err
   151  	}
   152  	success, ok := result.(*CreateTaskCreated)
   153  	if ok {
   154  		return success, nil
   155  	}
   156  	// unexpected success response
   157  	unexpectedSuccess := result.(*CreateTaskDefault)
   158  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   159  }
   160  
   161  /*
   162  DeleteTask deletes a task
   163  
   164  This is a soft delete and changes the task status to ignored.
   165  */
   166  func (a *Client) DeleteTask(params *DeleteTaskParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteTaskNoContent, error) {
   167  	// TODO: Validate the params before sending
   168  	if params == nil {
   169  		params = NewDeleteTaskParams()
   170  	}
   171  	op := &runtime.ClientOperation{
   172  		ID:                 "deleteTask",
   173  		Method:             "DELETE",
   174  		PathPattern:        "/tasks/{id}",
   175  		ProducesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   176  		ConsumesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   177  		Schemes:            []string{"http", "https"},
   178  		Params:             params,
   179  		Reader:             &DeleteTaskReader{formats: a.formats},
   180  		AuthInfo:           authInfo,
   181  		Context:            params.Context,
   182  		Client:             params.HTTPClient,
   183  	}
   184  	for _, opt := range opts {
   185  		opt(op)
   186  	}
   187  
   188  	result, err := a.transport.Submit(op)
   189  	if err != nil {
   190  		return nil, err
   191  	}
   192  	success, ok := result.(*DeleteTaskNoContent)
   193  	if ok {
   194  		return success, nil
   195  	}
   196  	// unexpected success response
   197  	unexpectedSuccess := result.(*DeleteTaskDefault)
   198  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   199  }
   200  
   201  /*
   202  GetTaskComments gets the comments for a task
   203  
   204  The comments require a size parameter.
   205  */
   206  func (a *Client) GetTaskComments(params *GetTaskCommentsParams, opts ...ClientOption) (*GetTaskCommentsOK, error) {
   207  	// TODO: Validate the params before sending
   208  	if params == nil {
   209  		params = NewGetTaskCommentsParams()
   210  	}
   211  	op := &runtime.ClientOperation{
   212  		ID:                 "getTaskComments",
   213  		Method:             "GET",
   214  		PathPattern:        "/tasks/{id}/comments",
   215  		ProducesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   216  		ConsumesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   217  		Schemes:            []string{"http", "https"},
   218  		Params:             params,
   219  		Reader:             &GetTaskCommentsReader{formats: a.formats},
   220  		Context:            params.Context,
   221  		Client:             params.HTTPClient,
   222  	}
   223  	for _, opt := range opts {
   224  		opt(op)
   225  	}
   226  
   227  	result, err := a.transport.Submit(op)
   228  	if err != nil {
   229  		return nil, err
   230  	}
   231  	success, ok := result.(*GetTaskCommentsOK)
   232  	if ok {
   233  		return success, nil
   234  	}
   235  	// unexpected success response
   236  	unexpectedSuccess := result.(*GetTaskCommentsDefault)
   237  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   238  }
   239  
   240  /*
   241  	GetTaskDetails gets the details for a task
   242  
   243  	The details view has more information than the card view.
   244  
   245  You can see who reported the issue and who last updated it when.
   246  
   247  There are also comments for each issue.
   248  */
   249  func (a *Client) GetTaskDetails(params *GetTaskDetailsParams, opts ...ClientOption) (*GetTaskDetailsOK, error) {
   250  	// TODO: Validate the params before sending
   251  	if params == nil {
   252  		params = NewGetTaskDetailsParams()
   253  	}
   254  	op := &runtime.ClientOperation{
   255  		ID:                 "getTaskDetails",
   256  		Method:             "GET",
   257  		PathPattern:        "/tasks/{id}",
   258  		ProducesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   259  		ConsumesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   260  		Schemes:            []string{"http", "https"},
   261  		Params:             params,
   262  		Reader:             &GetTaskDetailsReader{formats: a.formats},
   263  		Context:            params.Context,
   264  		Client:             params.HTTPClient,
   265  	}
   266  	for _, opt := range opts {
   267  		opt(op)
   268  	}
   269  
   270  	result, err := a.transport.Submit(op)
   271  	if err != nil {
   272  		return nil, err
   273  	}
   274  	success, ok := result.(*GetTaskDetailsOK)
   275  	if ok {
   276  		return success, nil
   277  	}
   278  	// unexpected success response
   279  	unexpectedSuccess := result.(*GetTaskDetailsDefault)
   280  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   281  }
   282  
   283  /*
   284  	ListTasks lists the tasks
   285  
   286  	Allows for specifying a number of filter parameters to
   287  
   288  narrow down the results.
   289  Also allows for specifying a **sinceId** and **pageSize** parameter
   290  to page through large result sets.
   291  */
   292  func (a *Client) ListTasks(params *ListTasksParams, opts ...ClientOption) (*ListTasksOK, error) {
   293  	// TODO: Validate the params before sending
   294  	if params == nil {
   295  		params = NewListTasksParams()
   296  	}
   297  	op := &runtime.ClientOperation{
   298  		ID:                 "listTasks",
   299  		Method:             "GET",
   300  		PathPattern:        "/tasks",
   301  		ProducesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   302  		ConsumesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   303  		Schemes:            []string{"http", "https"},
   304  		Params:             params,
   305  		Reader:             &ListTasksReader{formats: a.formats},
   306  		Context:            params.Context,
   307  		Client:             params.HTTPClient,
   308  	}
   309  	for _, opt := range opts {
   310  		opt(op)
   311  	}
   312  
   313  	result, err := a.transport.Submit(op)
   314  	if err != nil {
   315  		return nil, err
   316  	}
   317  	success, ok := result.(*ListTasksOK)
   318  	if ok {
   319  		return success, nil
   320  	}
   321  	// unexpected success response
   322  	unexpectedSuccess := result.(*ListTasksDefault)
   323  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   324  }
   325  
   326  /*
   327  	UpdateTask updates the details for a task
   328  
   329  	Allows for updating a task.
   330  
   331  This operation requires authentication so that we know which user
   332  last updated the task.
   333  */
   334  func (a *Client) UpdateTask(params *UpdateTaskParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateTaskOK, error) {
   335  	// TODO: Validate the params before sending
   336  	if params == nil {
   337  		params = NewUpdateTaskParams()
   338  	}
   339  	op := &runtime.ClientOperation{
   340  		ID:                 "updateTask",
   341  		Method:             "PUT",
   342  		PathPattern:        "/tasks/{id}",
   343  		ProducesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   344  		ConsumesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   345  		Schemes:            []string{"http", "https"},
   346  		Params:             params,
   347  		Reader:             &UpdateTaskReader{formats: a.formats},
   348  		AuthInfo:           authInfo,
   349  		Context:            params.Context,
   350  		Client:             params.HTTPClient,
   351  	}
   352  	for _, opt := range opts {
   353  		opt(op)
   354  	}
   355  
   356  	result, err := a.transport.Submit(op)
   357  	if err != nil {
   358  		return nil, err
   359  	}
   360  	success, ok := result.(*UpdateTaskOK)
   361  	if ok {
   362  		return success, nil
   363  	}
   364  	// unexpected success response
   365  	unexpectedSuccess := result.(*UpdateTaskDefault)
   366  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   367  }
   368  
   369  /*
   370  UploadTaskFile adds a file to a task
   371  
   372  The file can't be larger than **5MB**
   373  */
   374  func (a *Client) UploadTaskFile(params *UploadTaskFileParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UploadTaskFileCreated, error) {
   375  	// TODO: Validate the params before sending
   376  	if params == nil {
   377  		params = NewUploadTaskFileParams()
   378  	}
   379  	op := &runtime.ClientOperation{
   380  		ID:                 "uploadTaskFile",
   381  		Method:             "POST",
   382  		PathPattern:        "/tasks/{id}/files",
   383  		ProducesMediaTypes: []string{"application/vnd.goswagger.examples.task-tracker.v1+json"},
   384  		ConsumesMediaTypes: []string{"multipart/form-data"},
   385  		Schemes:            []string{"http", "https"},
   386  		Params:             params,
   387  		Reader:             &UploadTaskFileReader{formats: a.formats},
   388  		AuthInfo:           authInfo,
   389  		Context:            params.Context,
   390  		Client:             params.HTTPClient,
   391  	}
   392  	for _, opt := range opts {
   393  		opt(op)
   394  	}
   395  
   396  	result, err := a.transport.Submit(op)
   397  	if err != nil {
   398  		return nil, err
   399  	}
   400  	success, ok := result.(*UploadTaskFileCreated)
   401  	if ok {
   402  		return success, nil
   403  	}
   404  	// unexpected success response
   405  	unexpectedSuccess := result.(*UploadTaskFileDefault)
   406  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   407  }
   408  
   409  // SetTransport changes the transport on the client
   410  func (a *Client) SetTransport(transport runtime.ClientTransport) {
   411  	a.transport = transport
   412  }