...

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

Documentation: google.golang.org/api/playcustomapp/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 playcustomapp provides access to the Google Play Custom App Publishing API.
     8  //
     9  // For product documentation, see: https://developers.google.com/android/work/play/custom-app-api/
    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/playcustomapp/v1"
    27  //	...
    28  //	ctx := context.Background()
    29  //	playcustomappService, err := playcustomapp.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  //	playcustomappService, err := playcustomapp.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  //	playcustomappService, err := playcustomapp.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    49  //
    50  // See [google.golang.org/api/option.ClientOption] for details on options.
    51  package playcustomapp // import "google.golang.org/api/playcustomapp/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 = "playcustomapp:v1"
    90  const apiName = "playcustomapp"
    91  const apiVersion = "v1"
    92  const basePath = "https://playcustomapp.googleapis.com/"
    93  const basePathTemplate = "https://playcustomapp.UNIVERSE_DOMAIN/"
    94  const mtlsBasePath = "https://playcustomapp.mtls.googleapis.com/"
    95  
    96  // OAuth2 scopes used by this API.
    97  const (
    98  	// View and manage your Google Play Developer account
    99  	AndroidpublisherScope = "https://www.googleapis.com/auth/androidpublisher"
   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/androidpublisher",
   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.Accounts = NewAccountsService(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  	Accounts *AccountsService
   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 NewAccountsService(s *Service) *AccountsService {
   157  	rs := &AccountsService{s: s}
   158  	rs.CustomApps = NewAccountsCustomAppsService(s)
   159  	return rs
   160  }
   161  
   162  type AccountsService struct {
   163  	s *Service
   164  
   165  	CustomApps *AccountsCustomAppsService
   166  }
   167  
   168  func NewAccountsCustomAppsService(s *Service) *AccountsCustomAppsService {
   169  	rs := &AccountsCustomAppsService{s: s}
   170  	return rs
   171  }
   172  
   173  type AccountsCustomAppsService struct {
   174  	s *Service
   175  }
   176  
   177  // CustomApp: This resource represents a custom app.
   178  type CustomApp struct {
   179  	// LanguageCode: Default listing language in BCP 47 format.
   180  	LanguageCode string `json:"languageCode,omitempty"`
   181  	// Organizations: Organizations to which the custom app should be made
   182  	// available. If the request contains any organizations, then the app will be
   183  	// restricted to only these organizations. To support the organization linked
   184  	// to the developer account, the organization ID should be provided explicitly
   185  	// together with other organizations. If no organizations are provided, then
   186  	// the app is only available to the organization linked to the developer
   187  	// account.
   188  	Organizations []*Organization `json:"organizations,omitempty"`
   189  	// PackageName: Output only. Package name of the created Android app. Only
   190  	// present in the API response.
   191  	PackageName string `json:"packageName,omitempty"`
   192  	// Title: Title for the Android app.
   193  	Title string `json:"title,omitempty"`
   194  
   195  	// ServerResponse contains the HTTP response code and headers from the server.
   196  	googleapi.ServerResponse `json:"-"`
   197  	// ForceSendFields is a list of field names (e.g. "LanguageCode") to
   198  	// unconditionally include in API requests. By default, fields with empty or
   199  	// default values are omitted from API requests. See
   200  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   201  	// details.
   202  	ForceSendFields []string `json:"-"`
   203  	// NullFields is a list of field names (e.g. "LanguageCode") to include in API
   204  	// requests with the JSON null value. By default, fields with empty values are
   205  	// omitted from API requests. See
   206  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   207  	NullFields []string `json:"-"`
   208  }
   209  
   210  func (s *CustomApp) MarshalJSON() ([]byte, error) {
   211  	type NoMethod CustomApp
   212  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   213  }
   214  
   215  // Organization: Represents an organization that can access a custom app.
   216  type Organization struct {
   217  	// OrganizationId: Required. ID of the organization.
   218  	OrganizationId string `json:"organizationId,omitempty"`
   219  	// OrganizationName: Optional. A human-readable name of the organization, to
   220  	// help recognize the organization.
   221  	OrganizationName string `json:"organizationName,omitempty"`
   222  	// ForceSendFields is a list of field names (e.g. "OrganizationId") to
   223  	// unconditionally include in API requests. By default, fields with empty or
   224  	// default values are omitted from API requests. See
   225  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   226  	// details.
   227  	ForceSendFields []string `json:"-"`
   228  	// NullFields is a list of field names (e.g. "OrganizationId") to include in
   229  	// API requests with the JSON null value. By default, fields with empty values
   230  	// are omitted from API requests. See
   231  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   232  	NullFields []string `json:"-"`
   233  }
   234  
   235  func (s *Organization) MarshalJSON() ([]byte, error) {
   236  	type NoMethod Organization
   237  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   238  }
   239  
   240  type AccountsCustomAppsCreateCall struct {
   241  	s          *Service
   242  	account    int64
   243  	customapp  *CustomApp
   244  	urlParams_ gensupport.URLParams
   245  	mediaInfo_ *gensupport.MediaInfo
   246  	ctx_       context.Context
   247  	header_    http.Header
   248  }
   249  
   250  // Create: Creates a new custom app.
   251  //
   252  // - account: Developer account ID.
   253  func (r *AccountsCustomAppsService) Create(account int64, customapp *CustomApp) *AccountsCustomAppsCreateCall {
   254  	c := &AccountsCustomAppsCreateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   255  	c.account = account
   256  	c.customapp = customapp
   257  	return c
   258  }
   259  
   260  // Media specifies the media to upload in one or more chunks. The chunk size
   261  // may be controlled by supplying a MediaOption generated by
   262  // googleapi.ChunkSize. The chunk size defaults to
   263  // googleapi.DefaultUploadChunkSize.The Content-Type header used in the upload
   264  // request will be determined by sniffing the contents of r, unless a
   265  // MediaOption generated by googleapi.ContentType is supplied.
   266  // At most one of Media and ResumableMedia may be set.
   267  func (c *AccountsCustomAppsCreateCall) Media(r io.Reader, options ...googleapi.MediaOption) *AccountsCustomAppsCreateCall {
   268  	c.mediaInfo_ = gensupport.NewInfoFromMedia(r, options)
   269  	return c
   270  }
   271  
   272  // ResumableMedia specifies the media to upload in chunks and can be canceled
   273  // with ctx.
   274  //
   275  // Deprecated: use Media instead.
   276  //
   277  // At most one of Media and ResumableMedia may be set. mediaType identifies the
   278  // MIME media type of the upload, such as "image/png". If mediaType is "", it
   279  // will be auto-detected. The provided ctx will supersede any context
   280  // previously provided to the Context method.
   281  func (c *AccountsCustomAppsCreateCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *AccountsCustomAppsCreateCall {
   282  	c.ctx_ = ctx
   283  	c.mediaInfo_ = gensupport.NewInfoFromResumableMedia(r, size, mediaType)
   284  	return c
   285  }
   286  
   287  // ProgressUpdater provides a callback function that will be called after every
   288  // chunk. It should be a low-latency function in order to not slow down the
   289  // upload operation. This should only be called when using ResumableMedia (as
   290  // opposed to Media).
   291  func (c *AccountsCustomAppsCreateCall) ProgressUpdater(pu googleapi.ProgressUpdater) *AccountsCustomAppsCreateCall {
   292  	c.mediaInfo_.SetProgressUpdater(pu)
   293  	return c
   294  }
   295  
   296  // Fields allows partial responses to be retrieved. See
   297  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   298  // details.
   299  func (c *AccountsCustomAppsCreateCall) Fields(s ...googleapi.Field) *AccountsCustomAppsCreateCall {
   300  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   301  	return c
   302  }
   303  
   304  // Context sets the context to be used in this call's Do method.
   305  // This context will supersede any context previously provided to the
   306  // ResumableMedia method.
   307  func (c *AccountsCustomAppsCreateCall) Context(ctx context.Context) *AccountsCustomAppsCreateCall {
   308  	c.ctx_ = ctx
   309  	return c
   310  }
   311  
   312  // Header returns a http.Header that can be modified by the caller to add
   313  // headers to the request.
   314  func (c *AccountsCustomAppsCreateCall) Header() http.Header {
   315  	if c.header_ == nil {
   316  		c.header_ = make(http.Header)
   317  	}
   318  	return c.header_
   319  }
   320  
   321  func (c *AccountsCustomAppsCreateCall) doRequest(alt string) (*http.Response, error) {
   322  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
   323  	var body io.Reader = nil
   324  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.customapp)
   325  	if err != nil {
   326  		return nil, err
   327  	}
   328  	c.urlParams_.Set("alt", alt)
   329  	c.urlParams_.Set("prettyPrint", "false")
   330  	urls := googleapi.ResolveRelative(c.s.BasePath, "playcustomapp/v1/accounts/{account}/customApps")
   331  	if c.mediaInfo_ != nil {
   332  		urls = googleapi.ResolveRelative(c.s.BasePath, "/upload/playcustomapp/v1/accounts/{account}/customApps")
   333  		c.urlParams_.Set("uploadType", c.mediaInfo_.UploadType())
   334  	}
   335  	if body == nil {
   336  		body = new(bytes.Buffer)
   337  		reqHeaders.Set("Content-Type", "application/json")
   338  	}
   339  	body, getBody, cleanup := c.mediaInfo_.UploadRequest(reqHeaders, body)
   340  	defer cleanup()
   341  	urls += "?" + c.urlParams_.Encode()
   342  	req, err := http.NewRequest("POST", urls, body)
   343  	if err != nil {
   344  		return nil, err
   345  	}
   346  	req.Header = reqHeaders
   347  	req.GetBody = getBody
   348  	googleapi.Expand(req.URL, map[string]string{
   349  		"account": strconv.FormatInt(c.account, 10),
   350  	})
   351  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   352  }
   353  
   354  // Do executes the "playcustomapp.accounts.customApps.create" call.
   355  // Any non-2xx status code is an error. Response headers are in either
   356  // *CustomApp.ServerResponse.Header or (if a response was returned at all) in
   357  // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
   358  // whether the returned error was because http.StatusNotModified was returned.
   359  func (c *AccountsCustomAppsCreateCall) Do(opts ...googleapi.CallOption) (*CustomApp, error) {
   360  	gensupport.SetOptions(c.urlParams_, opts...)
   361  	res, err := c.doRequest("json")
   362  	if res != nil && res.StatusCode == http.StatusNotModified {
   363  		if res.Body != nil {
   364  			res.Body.Close()
   365  		}
   366  		return nil, gensupport.WrapError(&googleapi.Error{
   367  			Code:   res.StatusCode,
   368  			Header: res.Header,
   369  		})
   370  	}
   371  	if err != nil {
   372  		return nil, err
   373  	}
   374  	defer googleapi.CloseBody(res)
   375  	if err := googleapi.CheckResponse(res); err != nil {
   376  		return nil, gensupport.WrapError(err)
   377  	}
   378  	rx := c.mediaInfo_.ResumableUpload(res.Header.Get("Location"))
   379  	if rx != nil {
   380  		rx.Client = c.s.client
   381  		rx.UserAgent = c.s.userAgent()
   382  		ctx := c.ctx_
   383  		if ctx == nil {
   384  			ctx = context.TODO()
   385  		}
   386  		res, err = rx.Upload(ctx)
   387  		if err != nil {
   388  			return nil, err
   389  		}
   390  		defer res.Body.Close()
   391  		if err := googleapi.CheckResponse(res); err != nil {
   392  			return nil, gensupport.WrapError(err)
   393  		}
   394  	}
   395  	ret := &CustomApp{
   396  		ServerResponse: googleapi.ServerResponse{
   397  			Header:         res.Header,
   398  			HTTPStatusCode: res.StatusCode,
   399  		},
   400  	}
   401  	target := &ret
   402  	if err := gensupport.DecodeResponse(target, res); err != nil {
   403  		return nil, err
   404  	}
   405  	return ret, nil
   406  }
   407  

View as plain text