...

Source file src/google.golang.org/api/groupsmigration/v1/groupsmigration-gen.go

Documentation: google.golang.org/api/groupsmigration/v1

     1  // Copyright 2024 Google LLC.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Code generated file. DO NOT EDIT.
     6  
     7  // Package groupsmigration provides access to the Groups Migration API.
     8  //
     9  // For product documentation, see: https://developers.google.com/google-apps/groups-migration/
    10  //
    11  // # Library status
    12  //
    13  // These client libraries are officially supported by Google. However, this
    14  // library is considered complete and is in maintenance mode. This means
    15  // that we will address critical bugs and security issues but will not add
    16  // any new features.
    17  //
    18  // When possible, we recommend using our newer
    19  // [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go)
    20  // that are still actively being worked and iterated on.
    21  //
    22  // # Creating a client
    23  //
    24  // Usage example:
    25  //
    26  //	import "google.golang.org/api/groupsmigration/v1"
    27  //	...
    28  //	ctx := context.Background()
    29  //	groupsmigrationService, err := groupsmigration.NewService(ctx)
    30  //
    31  // In this example, Google Application Default Credentials are used for
    32  // authentication. For information on how to create and obtain Application
    33  // Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
    34  //
    35  // # Other authentication options
    36  //
    37  // To use an API key for authentication (note: some APIs do not support API
    38  // keys), use [google.golang.org/api/option.WithAPIKey]:
    39  //
    40  //	groupsmigrationService, err := groupsmigration.NewService(ctx, option.WithAPIKey("AIza..."))
    41  //
    42  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
    43  // flow, use [google.golang.org/api/option.WithTokenSource]:
    44  //
    45  //	config := &oauth2.Config{...}
    46  //	// ...
    47  //	token, err := config.Exchange(ctx, ...)
    48  //	groupsmigrationService, err := groupsmigration.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    49  //
    50  // See [google.golang.org/api/option.ClientOption] for details on options.
    51  package groupsmigration // import "google.golang.org/api/groupsmigration/v1"
    52  
    53  import (
    54  	"bytes"
    55  	"context"
    56  	"encoding/json"
    57  	"errors"
    58  	"fmt"
    59  	"io"
    60  	"net/http"
    61  	"net/url"
    62  	"strconv"
    63  	"strings"
    64  
    65  	googleapi "google.golang.org/api/googleapi"
    66  	internal "google.golang.org/api/internal"
    67  	gensupport "google.golang.org/api/internal/gensupport"
    68  	option "google.golang.org/api/option"
    69  	internaloption "google.golang.org/api/option/internaloption"
    70  	htransport "google.golang.org/api/transport/http"
    71  )
    72  
    73  // Always reference these packages, just in case the auto-generated code
    74  // below doesn't.
    75  var _ = bytes.NewBuffer
    76  var _ = strconv.Itoa
    77  var _ = fmt.Sprintf
    78  var _ = json.NewDecoder
    79  var _ = io.Copy
    80  var _ = url.Parse
    81  var _ = gensupport.MarshalJSON
    82  var _ = googleapi.Version
    83  var _ = errors.New
    84  var _ = strings.Replace
    85  var _ = context.Canceled
    86  var _ = internaloption.WithDefaultEndpoint
    87  var _ = internal.Version
    88  
    89  const apiId = "groupsmigration:v1"
    90  const apiName = "groupsmigration"
    91  const apiVersion = "v1"
    92  const basePath = "https://groupsmigration.googleapis.com/"
    93  const basePathTemplate = "https://groupsmigration.UNIVERSE_DOMAIN/"
    94  const mtlsBasePath = "https://groupsmigration.mtls.googleapis.com/"
    95  
    96  // OAuth2 scopes used by this API.
    97  const (
    98  	// Upload messages to any Google group in your domain
    99  	AppsGroupsMigrationScope = "https://www.googleapis.com/auth/apps.groups.migration"
   100  )
   101  
   102  // NewService creates a new Service.
   103  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
   104  	scopesOption := internaloption.WithDefaultScopes(
   105  		"https://www.googleapis.com/auth/apps.groups.migration",
   106  	)
   107  	// NOTE: prepend, so we don't override user-specified scopes.
   108  	opts = append([]option.ClientOption{scopesOption}, opts...)
   109  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
   110  	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
   111  	opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
   112  	opts = append(opts, internaloption.EnableNewAuthLibrary())
   113  	client, endpoint, err := htransport.NewClient(ctx, opts...)
   114  	if err != nil {
   115  		return nil, err
   116  	}
   117  	s, err := New(client)
   118  	if err != nil {
   119  		return nil, err
   120  	}
   121  	if endpoint != "" {
   122  		s.BasePath = endpoint
   123  	}
   124  	return s, nil
   125  }
   126  
   127  // New creates a new Service. It uses the provided http.Client for requests.
   128  //
   129  // Deprecated: please use NewService instead.
   130  // To provide a custom HTTP client, use option.WithHTTPClient.
   131  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   132  func New(client *http.Client) (*Service, error) {
   133  	if client == nil {
   134  		return nil, errors.New("client is nil")
   135  	}
   136  	s := &Service{client: client, BasePath: basePath}
   137  	s.Archive = NewArchiveService(s)
   138  	return s, nil
   139  }
   140  
   141  type Service struct {
   142  	client    *http.Client
   143  	BasePath  string // API endpoint base URL
   144  	UserAgent string // optional additional User-Agent fragment
   145  
   146  	Archive *ArchiveService
   147  }
   148  
   149  func (s *Service) userAgent() string {
   150  	if s.UserAgent == "" {
   151  		return googleapi.UserAgent
   152  	}
   153  	return googleapi.UserAgent + " " + s.UserAgent
   154  }
   155  
   156  func NewArchiveService(s *Service) *ArchiveService {
   157  	rs := &ArchiveService{s: s}
   158  	return rs
   159  }
   160  
   161  type ArchiveService struct {
   162  	s *Service
   163  }
   164  
   165  // Groups: JSON response template for groups migration API.
   166  type Groups struct {
   167  	// Kind: The kind of insert resource this is.
   168  	Kind string `json:"kind,omitempty"`
   169  	// ResponseCode: The status of the insert request.
   170  	ResponseCode string `json:"responseCode,omitempty"`
   171  
   172  	// ServerResponse contains the HTTP response code and headers from the server.
   173  	googleapi.ServerResponse `json:"-"`
   174  	// ForceSendFields is a list of field names (e.g. "Kind") to unconditionally
   175  	// include in API requests. By default, fields with empty or default values are
   176  	// omitted from API requests. See
   177  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   178  	// details.
   179  	ForceSendFields []string `json:"-"`
   180  	// NullFields is a list of field names (e.g. "Kind") to include in API requests
   181  	// with the JSON null value. By default, fields with empty values are omitted
   182  	// from API requests. See
   183  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   184  	NullFields []string `json:"-"`
   185  }
   186  
   187  func (s *Groups) MarshalJSON() ([]byte, error) {
   188  	type NoMethod Groups
   189  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   190  }
   191  
   192  type ArchiveInsertCall struct {
   193  	s          *Service
   194  	groupId    string
   195  	urlParams_ gensupport.URLParams
   196  	mediaInfo_ *gensupport.MediaInfo
   197  	ctx_       context.Context
   198  	header_    http.Header
   199  }
   200  
   201  // Insert: Inserts a new mail into the archive of the Google group.
   202  //
   203  // - groupId: The group ID.
   204  func (r *ArchiveService) Insert(groupId string) *ArchiveInsertCall {
   205  	c := &ArchiveInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   206  	c.groupId = groupId
   207  	return c
   208  }
   209  
   210  // Media specifies the media to upload in one or more chunks. The chunk size
   211  // may be controlled by supplying a MediaOption generated by
   212  // googleapi.ChunkSize. The chunk size defaults to
   213  // googleapi.DefaultUploadChunkSize.The Content-Type header used in the upload
   214  // request will be determined by sniffing the contents of r, unless a
   215  // MediaOption generated by googleapi.ContentType is supplied.
   216  // At most one of Media and ResumableMedia may be set.
   217  func (c *ArchiveInsertCall) Media(r io.Reader, options ...googleapi.MediaOption) *ArchiveInsertCall {
   218  	c.mediaInfo_ = gensupport.NewInfoFromMedia(r, options)
   219  	return c
   220  }
   221  
   222  // ResumableMedia specifies the media to upload in chunks and can be canceled
   223  // with ctx.
   224  //
   225  // Deprecated: use Media instead.
   226  //
   227  // At most one of Media and ResumableMedia may be set. mediaType identifies the
   228  // MIME media type of the upload, such as "image/png". If mediaType is "", it
   229  // will be auto-detected. The provided ctx will supersede any context
   230  // previously provided to the Context method.
   231  func (c *ArchiveInsertCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *ArchiveInsertCall {
   232  	c.ctx_ = ctx
   233  	c.mediaInfo_ = gensupport.NewInfoFromResumableMedia(r, size, mediaType)
   234  	return c
   235  }
   236  
   237  // ProgressUpdater provides a callback function that will be called after every
   238  // chunk. It should be a low-latency function in order to not slow down the
   239  // upload operation. This should only be called when using ResumableMedia (as
   240  // opposed to Media).
   241  func (c *ArchiveInsertCall) ProgressUpdater(pu googleapi.ProgressUpdater) *ArchiveInsertCall {
   242  	c.mediaInfo_.SetProgressUpdater(pu)
   243  	return c
   244  }
   245  
   246  // Fields allows partial responses to be retrieved. See
   247  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   248  // details.
   249  func (c *ArchiveInsertCall) Fields(s ...googleapi.Field) *ArchiveInsertCall {
   250  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   251  	return c
   252  }
   253  
   254  // Context sets the context to be used in this call's Do method.
   255  // This context will supersede any context previously provided to the
   256  // ResumableMedia method.
   257  func (c *ArchiveInsertCall) Context(ctx context.Context) *ArchiveInsertCall {
   258  	c.ctx_ = ctx
   259  	return c
   260  }
   261  
   262  // Header returns a http.Header that can be modified by the caller to add
   263  // headers to the request.
   264  func (c *ArchiveInsertCall) Header() http.Header {
   265  	if c.header_ == nil {
   266  		c.header_ = make(http.Header)
   267  	}
   268  	return c.header_
   269  }
   270  
   271  func (c *ArchiveInsertCall) doRequest(alt string) (*http.Response, error) {
   272  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   273  	var body io.Reader = nil
   274  	c.urlParams_.Set("alt", alt)
   275  	c.urlParams_.Set("prettyPrint", "false")
   276  	urls := googleapi.ResolveRelative(c.s.BasePath, "groups/v1/groups/{groupId}/archive")
   277  	if c.mediaInfo_ != nil {
   278  		urls = googleapi.ResolveRelative(c.s.BasePath, "/upload/groups/v1/groups/{groupId}/archive")
   279  		c.urlParams_.Set("uploadType", c.mediaInfo_.UploadType())
   280  	}
   281  	if body == nil {
   282  		body = new(bytes.Buffer)
   283  		reqHeaders.Set("Content-Type", "application/json")
   284  	}
   285  	body, getBody, cleanup := c.mediaInfo_.UploadRequest(reqHeaders, body)
   286  	defer cleanup()
   287  	urls += "?" + c.urlParams_.Encode()
   288  	req, err := http.NewRequest("POST", urls, body)
   289  	if err != nil {
   290  		return nil, err
   291  	}
   292  	req.Header = reqHeaders
   293  	req.GetBody = getBody
   294  	googleapi.Expand(req.URL, map[string]string{
   295  		"groupId": c.groupId,
   296  	})
   297  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   298  }
   299  
   300  // Do executes the "groupsmigration.archive.insert" call.
   301  // Any non-2xx status code is an error. Response headers are in either
   302  // *Groups.ServerResponse.Header or (if a response was returned at all) in
   303  // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
   304  // whether the returned error was because http.StatusNotModified was returned.
   305  func (c *ArchiveInsertCall) Do(opts ...googleapi.CallOption) (*Groups, error) {
   306  	gensupport.SetOptions(c.urlParams_, opts...)
   307  	res, err := c.doRequest("json")
   308  	if res != nil && res.StatusCode == http.StatusNotModified {
   309  		if res.Body != nil {
   310  			res.Body.Close()
   311  		}
   312  		return nil, gensupport.WrapError(&googleapi.Error{
   313  			Code:   res.StatusCode,
   314  			Header: res.Header,
   315  		})
   316  	}
   317  	if err != nil {
   318  		return nil, err
   319  	}
   320  	defer googleapi.CloseBody(res)
   321  	if err := googleapi.CheckResponse(res); err != nil {
   322  		return nil, gensupport.WrapError(err)
   323  	}
   324  	rx := c.mediaInfo_.ResumableUpload(res.Header.Get("Location"))
   325  	if rx != nil {
   326  		rx.Client = c.s.client
   327  		rx.UserAgent = c.s.userAgent()
   328  		ctx := c.ctx_
   329  		if ctx == nil {
   330  			ctx = context.TODO()
   331  		}
   332  		res, err = rx.Upload(ctx)
   333  		if err != nil {
   334  			return nil, err
   335  		}
   336  		defer res.Body.Close()
   337  		if err := googleapi.CheckResponse(res); err != nil {
   338  			return nil, gensupport.WrapError(err)
   339  		}
   340  	}
   341  	ret := &Groups{
   342  		ServerResponse: googleapi.ServerResponse{
   343  			Header:         res.Header,
   344  			HTTPStatusCode: res.StatusCode,
   345  		},
   346  	}
   347  	target := &ret
   348  	if err := gensupport.DecodeResponse(target, res); err != nil {
   349  		return nil, err
   350  	}
   351  	return ret, nil
   352  }
   353  

View as plain text