...

Source file src/google.golang.org/api/displayvideo/v4/displayvideo-gen.go

Documentation: google.golang.org/api/displayvideo/v4

     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 displayvideo provides access to the Display & Video 360 API.
     8  //
     9  // For product documentation, see: https://developers.google.com/display-video/
    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/displayvideo/v4"
    27  //	...
    28  //	ctx := context.Background()
    29  //	displayvideoService, err := displayvideo.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  // By default, all available scopes (see "Constants") are used to authenticate.
    38  // To restrict scopes, use [google.golang.org/api/option.WithScopes]:
    39  //
    40  //	displayvideoService, err := displayvideo.NewService(ctx, option.WithScopes(displayvideo.DoubleclickbidmanagerScope))
    41  //
    42  // To use an API key for authentication (note: some APIs do not support API
    43  // keys), use [google.golang.org/api/option.WithAPIKey]:
    44  //
    45  //	displayvideoService, err := displayvideo.NewService(ctx, option.WithAPIKey("AIza..."))
    46  //
    47  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
    48  // flow, use [google.golang.org/api/option.WithTokenSource]:
    49  //
    50  //	config := &oauth2.Config{...}
    51  //	// ...
    52  //	token, err := config.Exchange(ctx, ...)
    53  //	displayvideoService, err := displayvideo.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    54  //
    55  // See [google.golang.org/api/option.ClientOption] for details on options.
    56  package displayvideo // import "google.golang.org/api/displayvideo/v4"
    57  
    58  import (
    59  	"bytes"
    60  	"context"
    61  	"encoding/json"
    62  	"errors"
    63  	"fmt"
    64  	"io"
    65  	"net/http"
    66  	"net/url"
    67  	"strconv"
    68  	"strings"
    69  
    70  	googleapi "google.golang.org/api/googleapi"
    71  	internal "google.golang.org/api/internal"
    72  	gensupport "google.golang.org/api/internal/gensupport"
    73  	option "google.golang.org/api/option"
    74  	internaloption "google.golang.org/api/option/internaloption"
    75  	htransport "google.golang.org/api/transport/http"
    76  )
    77  
    78  // Always reference these packages, just in case the auto-generated code
    79  // below doesn't.
    80  var _ = bytes.NewBuffer
    81  var _ = strconv.Itoa
    82  var _ = fmt.Sprintf
    83  var _ = json.NewDecoder
    84  var _ = io.Copy
    85  var _ = url.Parse
    86  var _ = gensupport.MarshalJSON
    87  var _ = googleapi.Version
    88  var _ = errors.New
    89  var _ = strings.Replace
    90  var _ = context.Canceled
    91  var _ = internaloption.WithDefaultEndpoint
    92  var _ = internal.Version
    93  
    94  const apiId = "displayvideo:v4"
    95  const apiName = "displayvideo"
    96  const apiVersion = "v4"
    97  const basePath = "https://displayvideo.googleapis.com/"
    98  const basePathTemplate = "https://displayvideo.UNIVERSE_DOMAIN/"
    99  const mtlsBasePath = "https://displayvideo.mtls.googleapis.com/"
   100  const defaultUniverseDomain = "googleapis.com"
   101  
   102  // OAuth2 scopes used by this API.
   103  const (
   104  	// Create, see, edit, and permanently delete your Display & Video 360
   105  	// entities and reports
   106  	DisplayVideoScope = "https://www.googleapis.com/auth/display-video"
   107  
   108  	// View and manage your reports in DoubleClick Bid Manager
   109  	DoubleclickbidmanagerScope = "https://www.googleapis.com/auth/doubleclickbidmanager"
   110  )
   111  
   112  // NewService creates a new Service.
   113  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
   114  	scopesOption := internaloption.WithDefaultScopes(
   115  		"https://www.googleapis.com/auth/display-video",
   116  		"https://www.googleapis.com/auth/doubleclickbidmanager",
   117  	)
   118  	// NOTE: prepend, so we don't override user-specified scopes.
   119  	opts = append([]option.ClientOption{scopesOption}, opts...)
   120  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
   121  	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
   122  	opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
   123  	opts = append(opts, internaloption.WithDefaultUniverseDomain(defaultUniverseDomain))
   124  	client, endpoint, err := htransport.NewClient(ctx, opts...)
   125  	if err != nil {
   126  		return nil, err
   127  	}
   128  	s, err := New(client)
   129  	if err != nil {
   130  		return nil, err
   131  	}
   132  	if endpoint != "" {
   133  		s.BasePath = endpoint
   134  	}
   135  	return s, nil
   136  }
   137  
   138  // New creates a new Service. It uses the provided http.Client for requests.
   139  //
   140  // Deprecated: please use NewService instead.
   141  // To provide a custom HTTP client, use option.WithHTTPClient.
   142  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   143  func New(client *http.Client) (*Service, error) {
   144  	if client == nil {
   145  		return nil, errors.New("client is nil")
   146  	}
   147  	s := &Service{client: client, BasePath: basePath}
   148  	s.Media = NewMediaService(s)
   149  	s.Sdfdownloadtasks = NewSdfdownloadtasksService(s)
   150  	return s, nil
   151  }
   152  
   153  type Service struct {
   154  	client    *http.Client
   155  	BasePath  string // API endpoint base URL
   156  	UserAgent string // optional additional User-Agent fragment
   157  
   158  	Media *MediaService
   159  
   160  	Sdfdownloadtasks *SdfdownloadtasksService
   161  }
   162  
   163  func (s *Service) userAgent() string {
   164  	if s.UserAgent == "" {
   165  		return googleapi.UserAgent
   166  	}
   167  	return googleapi.UserAgent + " " + s.UserAgent
   168  }
   169  
   170  func NewMediaService(s *Service) *MediaService {
   171  	rs := &MediaService{s: s}
   172  	return rs
   173  }
   174  
   175  type MediaService struct {
   176  	s *Service
   177  }
   178  
   179  func NewSdfdownloadtasksService(s *Service) *SdfdownloadtasksService {
   180  	rs := &SdfdownloadtasksService{s: s}
   181  	rs.Operations = NewSdfdownloadtasksOperationsService(s)
   182  	return rs
   183  }
   184  
   185  type SdfdownloadtasksService struct {
   186  	s *Service
   187  
   188  	Operations *SdfdownloadtasksOperationsService
   189  }
   190  
   191  func NewSdfdownloadtasksOperationsService(s *Service) *SdfdownloadtasksOperationsService {
   192  	rs := &SdfdownloadtasksOperationsService{s: s}
   193  	return rs
   194  }
   195  
   196  type SdfdownloadtasksOperationsService struct {
   197  	s *Service
   198  }
   199  
   200  // GoogleBytestreamMedia: Media resource.
   201  type GoogleBytestreamMedia struct {
   202  	// ResourceName: Name of the media resource.
   203  	ResourceName string `json:"resourceName,omitempty"`
   204  
   205  	// ServerResponse contains the HTTP response code and headers from the
   206  	// server.
   207  	googleapi.ServerResponse `json:"-"`
   208  
   209  	// ForceSendFields is a list of field names (e.g. "ResourceName") to
   210  	// unconditionally include in API requests. By default, fields with
   211  	// empty or default values are omitted from API requests. However, any
   212  	// non-pointer, non-interface field appearing in ForceSendFields will be
   213  	// sent to the server regardless of whether the field is empty or not.
   214  	// This may be used to include empty fields in Patch requests.
   215  	ForceSendFields []string `json:"-"`
   216  
   217  	// NullFields is a list of field names (e.g. "ResourceName") to include
   218  	// in API requests with the JSON null value. By default, fields with
   219  	// empty values are omitted from API requests. However, any field with
   220  	// an empty value appearing in NullFields will be sent to the server as
   221  	// null. It is an error if a field in this list has a non-empty value.
   222  	// This may be used to include null fields in Patch requests.
   223  	NullFields []string `json:"-"`
   224  }
   225  
   226  func (s *GoogleBytestreamMedia) MarshalJSON() ([]byte, error) {
   227  	type NoMethod GoogleBytestreamMedia
   228  	raw := NoMethod(*s)
   229  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   230  }
   231  
   232  // Operation: This resource represents a long-running operation that is
   233  // the result of a network API call.
   234  type Operation struct {
   235  	// Done: If the value is `false`, it means the operation is still in
   236  	// progress. If `true`, the operation is completed, and either `error`
   237  	// or `response` is available.
   238  	Done bool `json:"done,omitempty"`
   239  
   240  	// Error: The error result of the operation in case of failure or
   241  	// cancellation.
   242  	Error *Status `json:"error,omitempty"`
   243  
   244  	// Metadata: Service-specific metadata associated with the operation. It
   245  	// typically contains progress information and common metadata such as
   246  	// create time. Some services might not provide such metadata. Any
   247  	// method that returns a long-running operation should document the
   248  	// metadata type, if any.
   249  	Metadata googleapi.RawMessage `json:"metadata,omitempty"`
   250  
   251  	// Name: The server-assigned name, which is only unique within the same
   252  	// service that originally returns it. If you use the default HTTP
   253  	// mapping, the `name` should be a resource name ending with
   254  	// `operations/{unique_id}`.
   255  	Name string `json:"name,omitempty"`
   256  
   257  	// Response: The normal, successful response of the operation. If the
   258  	// original method returns no data on success, such as `Delete`, the
   259  	// response is `google.protobuf.Empty`. If the original method is
   260  	// standard `Get`/`Create`/`Update`, the response should be the
   261  	// resource. For other methods, the response should have the type
   262  	// `XxxResponse`, where `Xxx` is the original method name. For example,
   263  	// if the original method name is `TakeSnapshot()`, the inferred
   264  	// response type is `TakeSnapshotResponse`.
   265  	Response googleapi.RawMessage `json:"response,omitempty"`
   266  
   267  	// ServerResponse contains the HTTP response code and headers from the
   268  	// server.
   269  	googleapi.ServerResponse `json:"-"`
   270  
   271  	// ForceSendFields is a list of field names (e.g. "Done") to
   272  	// unconditionally include in API requests. By default, fields with
   273  	// empty or default values are omitted from API requests. However, any
   274  	// non-pointer, non-interface field appearing in ForceSendFields will be
   275  	// sent to the server regardless of whether the field is empty or not.
   276  	// This may be used to include empty fields in Patch requests.
   277  	ForceSendFields []string `json:"-"`
   278  
   279  	// NullFields is a list of field names (e.g. "Done") to include in API
   280  	// requests with the JSON null value. By default, fields with empty
   281  	// values are omitted from API requests. However, any field with an
   282  	// empty value appearing in NullFields will be sent to the server as
   283  	// null. It is an error if a field in this list has a non-empty value.
   284  	// This may be used to include null fields in Patch requests.
   285  	NullFields []string `json:"-"`
   286  }
   287  
   288  func (s *Operation) MarshalJSON() ([]byte, error) {
   289  	type NoMethod Operation
   290  	raw := NoMethod(*s)
   291  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   292  }
   293  
   294  // Status: The `Status` type defines a logical error model that is
   295  // suitable for different programming environments, including REST APIs
   296  // and RPC APIs. It is used by gRPC (https://github.com/grpc). Each
   297  // `Status` message contains three pieces of data: error code, error
   298  // message, and error details. You can find out more about this error
   299  // model and how to work with it in the API Design Guide
   300  // (https://cloud.google.com/apis/design/errors).
   301  type Status struct {
   302  	// Code: The status code, which should be an enum value of
   303  	// google.rpc.Code.
   304  	Code int64 `json:"code,omitempty"`
   305  
   306  	// Details: A list of messages that carry the error details. There is a
   307  	// common set of message types for APIs to use.
   308  	Details []googleapi.RawMessage `json:"details,omitempty"`
   309  
   310  	// Message: A developer-facing error message, which should be in
   311  	// English. Any user-facing error message should be localized and sent
   312  	// in the google.rpc.Status.details field, or localized by the client.
   313  	Message string `json:"message,omitempty"`
   314  
   315  	// ForceSendFields is a list of field names (e.g. "Code") to
   316  	// unconditionally include in API requests. By default, fields with
   317  	// empty or default values are omitted from API requests. However, any
   318  	// non-pointer, non-interface field appearing in ForceSendFields will be
   319  	// sent to the server regardless of whether the field is empty or not.
   320  	// This may be used to include empty fields in Patch requests.
   321  	ForceSendFields []string `json:"-"`
   322  
   323  	// NullFields is a list of field names (e.g. "Code") to include in API
   324  	// requests with the JSON null value. By default, fields with empty
   325  	// values are omitted from API requests. However, any field with an
   326  	// empty value appearing in NullFields will be sent to the server as
   327  	// null. It is an error if a field in this list has a non-empty value.
   328  	// This may be used to include null fields in Patch requests.
   329  	NullFields []string `json:"-"`
   330  }
   331  
   332  func (s *Status) MarshalJSON() ([]byte, error) {
   333  	type NoMethod Status
   334  	raw := NoMethod(*s)
   335  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   336  }
   337  
   338  // method id "displayvideo.media.download":
   339  
   340  type MediaDownloadCall struct {
   341  	s            *Service
   342  	resourceName string
   343  	urlParams_   gensupport.URLParams
   344  	ifNoneMatch_ string
   345  	ctx_         context.Context
   346  	header_      http.Header
   347  }
   348  
   349  // Download: Downloads media. Download is supported on the URI
   350  // `/download/{resource_name=**}?alt=media.` **Note**: Download requests
   351  // will not be successful without including `alt=media` query string.
   352  //
   353  //   - resourceName: Name of the media that is being downloaded. See
   354  //     ReadRequest.resource_name.
   355  func (r *MediaService) Download(resourceName string) *MediaDownloadCall {
   356  	c := &MediaDownloadCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   357  	c.resourceName = resourceName
   358  	return c
   359  }
   360  
   361  // Fields allows partial responses to be retrieved. See
   362  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
   363  // for more information.
   364  func (c *MediaDownloadCall) Fields(s ...googleapi.Field) *MediaDownloadCall {
   365  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   366  	return c
   367  }
   368  
   369  // IfNoneMatch sets the optional parameter which makes the operation
   370  // fail if the object's ETag matches the given value. This is useful for
   371  // getting updates only after the object has changed since the last
   372  // request. Use googleapi.IsNotModified to check whether the response
   373  // error from Do is the result of In-None-Match.
   374  func (c *MediaDownloadCall) IfNoneMatch(entityTag string) *MediaDownloadCall {
   375  	c.ifNoneMatch_ = entityTag
   376  	return c
   377  }
   378  
   379  // Context sets the context to be used in this call's Do and Download
   380  // methods. Any pending HTTP request will be aborted if the provided
   381  // context is canceled.
   382  func (c *MediaDownloadCall) Context(ctx context.Context) *MediaDownloadCall {
   383  	c.ctx_ = ctx
   384  	return c
   385  }
   386  
   387  // Header returns an http.Header that can be modified by the caller to
   388  // add HTTP headers to the request.
   389  func (c *MediaDownloadCall) Header() http.Header {
   390  	if c.header_ == nil {
   391  		c.header_ = make(http.Header)
   392  	}
   393  	return c.header_
   394  }
   395  
   396  func (c *MediaDownloadCall) doRequest(alt string) (*http.Response, error) {
   397  	reqHeaders := make(http.Header)
   398  	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/"+internal.Version)
   399  	for k, v := range c.header_ {
   400  		reqHeaders[k] = v
   401  	}
   402  	reqHeaders.Set("User-Agent", c.s.userAgent())
   403  	if c.ifNoneMatch_ != "" {
   404  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   405  	}
   406  	var body io.Reader = nil
   407  	c.urlParams_.Set("alt", alt)
   408  	c.urlParams_.Set("prettyPrint", "false")
   409  	urls := googleapi.ResolveRelative(c.s.BasePath, "download/{+resourceName}")
   410  	urls += "?" + c.urlParams_.Encode()
   411  	req, err := http.NewRequest("GET", urls, body)
   412  	if err != nil {
   413  		return nil, err
   414  	}
   415  	req.Header = reqHeaders
   416  	googleapi.Expand(req.URL, map[string]string{
   417  		"resourceName": c.resourceName,
   418  	})
   419  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   420  }
   421  
   422  // Download fetches the API endpoint's "media" value, instead of the normal
   423  // API response value. If the returned error is nil, the Response is guaranteed to
   424  // have a 2xx status code. Callers must close the Response.Body as usual.
   425  func (c *MediaDownloadCall) Download(opts ...googleapi.CallOption) (*http.Response, error) {
   426  	gensupport.SetOptions(c.urlParams_, opts...)
   427  	res, err := c.doRequest("media")
   428  	if err != nil {
   429  		return nil, err
   430  	}
   431  	if err := googleapi.CheckResponse(res); err != nil {
   432  		res.Body.Close()
   433  		return nil, gensupport.WrapError(err)
   434  	}
   435  	return res, nil
   436  }
   437  
   438  // Do executes the "displayvideo.media.download" call.
   439  // Exactly one of *GoogleBytestreamMedia or error will be non-nil. Any
   440  // non-2xx status code is an error. Response headers are in either
   441  // *GoogleBytestreamMedia.ServerResponse.Header or (if a response was
   442  // returned at all) in error.(*googleapi.Error).Header. Use
   443  // googleapi.IsNotModified to check whether the returned error was
   444  // because http.StatusNotModified was returned.
   445  func (c *MediaDownloadCall) Do(opts ...googleapi.CallOption) (*GoogleBytestreamMedia, error) {
   446  	gensupport.SetOptions(c.urlParams_, opts...)
   447  	res, err := c.doRequest("json")
   448  	if res != nil && res.StatusCode == http.StatusNotModified {
   449  		if res.Body != nil {
   450  			res.Body.Close()
   451  		}
   452  		return nil, gensupport.WrapError(&googleapi.Error{
   453  			Code:   res.StatusCode,
   454  			Header: res.Header,
   455  		})
   456  	}
   457  	if err != nil {
   458  		return nil, err
   459  	}
   460  	defer googleapi.CloseBody(res)
   461  	if err := googleapi.CheckResponse(res); err != nil {
   462  		return nil, gensupport.WrapError(err)
   463  	}
   464  	ret := &GoogleBytestreamMedia{
   465  		ServerResponse: googleapi.ServerResponse{
   466  			Header:         res.Header,
   467  			HTTPStatusCode: res.StatusCode,
   468  		},
   469  	}
   470  	target := &ret
   471  	if err := gensupport.DecodeResponse(target, res); err != nil {
   472  		return nil, err
   473  	}
   474  	return ret, nil
   475  	// {
   476  	//   "description": "Downloads media. Download is supported on the URI `/download/{resource_name=**}?alt=media.` **Note**: Download requests will not be successful without including `alt=media` query string.",
   477  	//   "flatPath": "download/{downloadId}",
   478  	//   "httpMethod": "GET",
   479  	//   "id": "displayvideo.media.download",
   480  	//   "parameterOrder": [
   481  	//     "resourceName"
   482  	//   ],
   483  	//   "parameters": {
   484  	//     "resourceName": {
   485  	//       "description": "Name of the media that is being downloaded. See ReadRequest.resource_name.",
   486  	//       "location": "path",
   487  	//       "pattern": "^.*$",
   488  	//       "required": true,
   489  	//       "type": "string"
   490  	//     }
   491  	//   },
   492  	//   "path": "download/{+resourceName}",
   493  	//   "response": {
   494  	//     "$ref": "GoogleBytestreamMedia"
   495  	//   },
   496  	//   "scopes": [
   497  	//     "https://www.googleapis.com/auth/display-video",
   498  	//     "https://www.googleapis.com/auth/doubleclickbidmanager"
   499  	//   ],
   500  	//   "supportsMediaDownload": true
   501  	// }
   502  
   503  }
   504  
   505  // method id "displayvideo.media.upload":
   506  
   507  type MediaUploadCall struct {
   508  	s                     *Service
   509  	resourceName          string
   510  	googlebytestreammedia *GoogleBytestreamMedia
   511  	urlParams_            gensupport.URLParams
   512  	mediaInfo_            *gensupport.MediaInfo
   513  	ctx_                  context.Context
   514  	header_               http.Header
   515  }
   516  
   517  // Upload: Uploads media. Upload is supported on the URI
   518  // `/upload/media/{resource_name=**}?upload_type=media.` **Note**:
   519  // Upload requests will not be successful without including
   520  // `upload_type=media` query string.
   521  //
   522  //   - resourceName: Name of the media that is being downloaded. See
   523  //     ReadRequest.resource_name.
   524  func (r *MediaService) Upload(resourceName string, googlebytestreammedia *GoogleBytestreamMedia) *MediaUploadCall {
   525  	c := &MediaUploadCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   526  	c.resourceName = resourceName
   527  	c.googlebytestreammedia = googlebytestreammedia
   528  	return c
   529  }
   530  
   531  // Media specifies the media to upload in one or more chunks. The chunk
   532  // size may be controlled by supplying a MediaOption generated by
   533  // googleapi.ChunkSize. The chunk size defaults to
   534  // googleapi.DefaultUploadChunkSize.The Content-Type header used in the
   535  // upload request will be determined by sniffing the contents of r,
   536  // unless a MediaOption generated by googleapi.ContentType is
   537  // supplied.
   538  // At most one of Media and ResumableMedia may be set.
   539  func (c *MediaUploadCall) Media(r io.Reader, options ...googleapi.MediaOption) *MediaUploadCall {
   540  	c.mediaInfo_ = gensupport.NewInfoFromMedia(r, options)
   541  	return c
   542  }
   543  
   544  // ResumableMedia specifies the media to upload in chunks and can be
   545  // canceled with ctx.
   546  //
   547  // Deprecated: use Media instead.
   548  //
   549  // At most one of Media and ResumableMedia may be set. mediaType
   550  // identifies the MIME media type of the upload, such as "image/png". If
   551  // mediaType is "", it will be auto-detected. The provided ctx will
   552  // supersede any context previously provided to the Context method.
   553  func (c *MediaUploadCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *MediaUploadCall {
   554  	c.ctx_ = ctx
   555  	c.mediaInfo_ = gensupport.NewInfoFromResumableMedia(r, size, mediaType)
   556  	return c
   557  }
   558  
   559  // ProgressUpdater provides a callback function that will be called
   560  // after every chunk. It should be a low-latency function in order to
   561  // not slow down the upload operation. This should only be called when
   562  // using ResumableMedia (as opposed to Media).
   563  func (c *MediaUploadCall) ProgressUpdater(pu googleapi.ProgressUpdater) *MediaUploadCall {
   564  	c.mediaInfo_.SetProgressUpdater(pu)
   565  	return c
   566  }
   567  
   568  // Fields allows partial responses to be retrieved. See
   569  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
   570  // for more information.
   571  func (c *MediaUploadCall) Fields(s ...googleapi.Field) *MediaUploadCall {
   572  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   573  	return c
   574  }
   575  
   576  // Context sets the context to be used in this call's Do method. Any
   577  // pending HTTP request will be aborted if the provided context is
   578  // canceled.
   579  // This context will supersede any context previously provided to the
   580  // ResumableMedia method.
   581  func (c *MediaUploadCall) Context(ctx context.Context) *MediaUploadCall {
   582  	c.ctx_ = ctx
   583  	return c
   584  }
   585  
   586  // Header returns an http.Header that can be modified by the caller to
   587  // add HTTP headers to the request.
   588  func (c *MediaUploadCall) Header() http.Header {
   589  	if c.header_ == nil {
   590  		c.header_ = make(http.Header)
   591  	}
   592  	return c.header_
   593  }
   594  
   595  func (c *MediaUploadCall) doRequest(alt string) (*http.Response, error) {
   596  	reqHeaders := make(http.Header)
   597  	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/"+internal.Version)
   598  	for k, v := range c.header_ {
   599  		reqHeaders[k] = v
   600  	}
   601  	reqHeaders.Set("User-Agent", c.s.userAgent())
   602  	var body io.Reader = nil
   603  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.googlebytestreammedia)
   604  	if err != nil {
   605  		return nil, err
   606  	}
   607  	reqHeaders.Set("Content-Type", "application/json")
   608  	c.urlParams_.Set("alt", alt)
   609  	c.urlParams_.Set("prettyPrint", "false")
   610  	urls := googleapi.ResolveRelative(c.s.BasePath, "media/{+resourceName}")
   611  	if c.mediaInfo_ != nil {
   612  		urls = googleapi.ResolveRelative(c.s.BasePath, "/upload/media/{+resourceName}")
   613  		c.urlParams_.Set("uploadType", c.mediaInfo_.UploadType())
   614  	}
   615  	if body == nil {
   616  		body = new(bytes.Buffer)
   617  		reqHeaders.Set("Content-Type", "application/json")
   618  	}
   619  	body, getBody, cleanup := c.mediaInfo_.UploadRequest(reqHeaders, body)
   620  	defer cleanup()
   621  	urls += "?" + c.urlParams_.Encode()
   622  	req, err := http.NewRequest("POST", urls, body)
   623  	if err != nil {
   624  		return nil, err
   625  	}
   626  	req.Header = reqHeaders
   627  	req.GetBody = getBody
   628  	googleapi.Expand(req.URL, map[string]string{
   629  		"resourceName": c.resourceName,
   630  	})
   631  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   632  }
   633  
   634  // Do executes the "displayvideo.media.upload" call.
   635  // Exactly one of *GoogleBytestreamMedia or error will be non-nil. Any
   636  // non-2xx status code is an error. Response headers are in either
   637  // *GoogleBytestreamMedia.ServerResponse.Header or (if a response was
   638  // returned at all) in error.(*googleapi.Error).Header. Use
   639  // googleapi.IsNotModified to check whether the returned error was
   640  // because http.StatusNotModified was returned.
   641  func (c *MediaUploadCall) Do(opts ...googleapi.CallOption) (*GoogleBytestreamMedia, error) {
   642  	gensupport.SetOptions(c.urlParams_, opts...)
   643  	res, err := c.doRequest("json")
   644  	if res != nil && res.StatusCode == http.StatusNotModified {
   645  		if res.Body != nil {
   646  			res.Body.Close()
   647  		}
   648  		return nil, gensupport.WrapError(&googleapi.Error{
   649  			Code:   res.StatusCode,
   650  			Header: res.Header,
   651  		})
   652  	}
   653  	if err != nil {
   654  		return nil, err
   655  	}
   656  	defer googleapi.CloseBody(res)
   657  	if err := googleapi.CheckResponse(res); err != nil {
   658  		return nil, gensupport.WrapError(err)
   659  	}
   660  	rx := c.mediaInfo_.ResumableUpload(res.Header.Get("Location"))
   661  	if rx != nil {
   662  		rx.Client = c.s.client
   663  		rx.UserAgent = c.s.userAgent()
   664  		ctx := c.ctx_
   665  		if ctx == nil {
   666  			ctx = context.TODO()
   667  		}
   668  		res, err = rx.Upload(ctx)
   669  		if err != nil {
   670  			return nil, err
   671  		}
   672  		defer res.Body.Close()
   673  		if err := googleapi.CheckResponse(res); err != nil {
   674  			return nil, gensupport.WrapError(err)
   675  		}
   676  	}
   677  	ret := &GoogleBytestreamMedia{
   678  		ServerResponse: googleapi.ServerResponse{
   679  			Header:         res.Header,
   680  			HTTPStatusCode: res.StatusCode,
   681  		},
   682  	}
   683  	target := &ret
   684  	if err := gensupport.DecodeResponse(target, res); err != nil {
   685  		return nil, err
   686  	}
   687  	return ret, nil
   688  	// {
   689  	//   "description": "Uploads media. Upload is supported on the URI `/upload/media/{resource_name=**}?upload_type=media.` **Note**: Upload requests will not be successful without including `upload_type=media` query string.",
   690  	//   "flatPath": "media/{mediaId}",
   691  	//   "httpMethod": "POST",
   692  	//   "id": "displayvideo.media.upload",
   693  	//   "mediaUpload": {
   694  	//     "accept": [
   695  	//       "*/*"
   696  	//     ],
   697  	//     "protocols": {
   698  	//       "simple": {
   699  	//         "multipart": true,
   700  	//         "path": "/upload/media/{+resourceName}"
   701  	//       }
   702  	//     }
   703  	//   },
   704  	//   "parameterOrder": [
   705  	//     "resourceName"
   706  	//   ],
   707  	//   "parameters": {
   708  	//     "resourceName": {
   709  	//       "description": "Name of the media that is being downloaded. See ReadRequest.resource_name.",
   710  	//       "location": "path",
   711  	//       "pattern": "^.*$",
   712  	//       "required": true,
   713  	//       "type": "string"
   714  	//     }
   715  	//   },
   716  	//   "path": "media/{+resourceName}",
   717  	//   "request": {
   718  	//     "$ref": "GoogleBytestreamMedia"
   719  	//   },
   720  	//   "response": {
   721  	//     "$ref": "GoogleBytestreamMedia"
   722  	//   },
   723  	//   "scopes": [
   724  	//     "https://www.googleapis.com/auth/display-video",
   725  	//     "https://www.googleapis.com/auth/doubleclickbidmanager"
   726  	//   ],
   727  	//   "supportsMediaUpload": true
   728  	// }
   729  
   730  }
   731  
   732  // method id "displayvideo.sdfdownloadtasks.operations.get":
   733  
   734  type SdfdownloadtasksOperationsGetCall struct {
   735  	s            *Service
   736  	name         string
   737  	urlParams_   gensupport.URLParams
   738  	ifNoneMatch_ string
   739  	ctx_         context.Context
   740  	header_      http.Header
   741  }
   742  
   743  // Get: Gets the latest state of an asynchronous SDF download task
   744  // operation. Clients should poll this method at intervals of 30
   745  // seconds.
   746  //
   747  // - name: The name of the operation resource.
   748  func (r *SdfdownloadtasksOperationsService) Get(name string) *SdfdownloadtasksOperationsGetCall {
   749  	c := &SdfdownloadtasksOperationsGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   750  	c.name = name
   751  	return c
   752  }
   753  
   754  // Fields allows partial responses to be retrieved. See
   755  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
   756  // for more information.
   757  func (c *SdfdownloadtasksOperationsGetCall) Fields(s ...googleapi.Field) *SdfdownloadtasksOperationsGetCall {
   758  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   759  	return c
   760  }
   761  
   762  // IfNoneMatch sets the optional parameter which makes the operation
   763  // fail if the object's ETag matches the given value. This is useful for
   764  // getting updates only after the object has changed since the last
   765  // request. Use googleapi.IsNotModified to check whether the response
   766  // error from Do is the result of In-None-Match.
   767  func (c *SdfdownloadtasksOperationsGetCall) IfNoneMatch(entityTag string) *SdfdownloadtasksOperationsGetCall {
   768  	c.ifNoneMatch_ = entityTag
   769  	return c
   770  }
   771  
   772  // Context sets the context to be used in this call's Do method. Any
   773  // pending HTTP request will be aborted if the provided context is
   774  // canceled.
   775  func (c *SdfdownloadtasksOperationsGetCall) Context(ctx context.Context) *SdfdownloadtasksOperationsGetCall {
   776  	c.ctx_ = ctx
   777  	return c
   778  }
   779  
   780  // Header returns an http.Header that can be modified by the caller to
   781  // add HTTP headers to the request.
   782  func (c *SdfdownloadtasksOperationsGetCall) Header() http.Header {
   783  	if c.header_ == nil {
   784  		c.header_ = make(http.Header)
   785  	}
   786  	return c.header_
   787  }
   788  
   789  func (c *SdfdownloadtasksOperationsGetCall) doRequest(alt string) (*http.Response, error) {
   790  	reqHeaders := make(http.Header)
   791  	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/"+internal.Version)
   792  	for k, v := range c.header_ {
   793  		reqHeaders[k] = v
   794  	}
   795  	reqHeaders.Set("User-Agent", c.s.userAgent())
   796  	if c.ifNoneMatch_ != "" {
   797  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   798  	}
   799  	var body io.Reader = nil
   800  	c.urlParams_.Set("alt", alt)
   801  	c.urlParams_.Set("prettyPrint", "false")
   802  	urls := googleapi.ResolveRelative(c.s.BasePath, "v4/{+name}")
   803  	urls += "?" + c.urlParams_.Encode()
   804  	req, err := http.NewRequest("GET", urls, body)
   805  	if err != nil {
   806  		return nil, err
   807  	}
   808  	req.Header = reqHeaders
   809  	googleapi.Expand(req.URL, map[string]string{
   810  		"name": c.name,
   811  	})
   812  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   813  }
   814  
   815  // Do executes the "displayvideo.sdfdownloadtasks.operations.get" call.
   816  // Exactly one of *Operation or error will be non-nil. Any non-2xx
   817  // status code is an error. Response headers are in either
   818  // *Operation.ServerResponse.Header or (if a response was returned at
   819  // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
   820  // to check whether the returned error was because
   821  // http.StatusNotModified was returned.
   822  func (c *SdfdownloadtasksOperationsGetCall) Do(opts ...googleapi.CallOption) (*Operation, error) {
   823  	gensupport.SetOptions(c.urlParams_, opts...)
   824  	res, err := c.doRequest("json")
   825  	if res != nil && res.StatusCode == http.StatusNotModified {
   826  		if res.Body != nil {
   827  			res.Body.Close()
   828  		}
   829  		return nil, gensupport.WrapError(&googleapi.Error{
   830  			Code:   res.StatusCode,
   831  			Header: res.Header,
   832  		})
   833  	}
   834  	if err != nil {
   835  		return nil, err
   836  	}
   837  	defer googleapi.CloseBody(res)
   838  	if err := googleapi.CheckResponse(res); err != nil {
   839  		return nil, gensupport.WrapError(err)
   840  	}
   841  	ret := &Operation{
   842  		ServerResponse: googleapi.ServerResponse{
   843  			Header:         res.Header,
   844  			HTTPStatusCode: res.StatusCode,
   845  		},
   846  	}
   847  	target := &ret
   848  	if err := gensupport.DecodeResponse(target, res); err != nil {
   849  		return nil, err
   850  	}
   851  	return ret, nil
   852  	// {
   853  	//   "description": "Gets the latest state of an asynchronous SDF download task operation. Clients should poll this method at intervals of 30 seconds.",
   854  	//   "flatPath": "v4/sdfdownloadtasks/operations/{operationsId}",
   855  	//   "httpMethod": "GET",
   856  	//   "id": "displayvideo.sdfdownloadtasks.operations.get",
   857  	//   "parameterOrder": [
   858  	//     "name"
   859  	//   ],
   860  	//   "parameters": {
   861  	//     "name": {
   862  	//       "description": "The name of the operation resource.",
   863  	//       "location": "path",
   864  	//       "pattern": "^sdfdownloadtasks/operations/[^/]+$",
   865  	//       "required": true,
   866  	//       "type": "string"
   867  	//     }
   868  	//   },
   869  	//   "path": "v4/{+name}",
   870  	//   "response": {
   871  	//     "$ref": "Operation"
   872  	//   },
   873  	//   "scopes": [
   874  	//     "https://www.googleapis.com/auth/display-video",
   875  	//     "https://www.googleapis.com/auth/doubleclickbidmanager"
   876  	//   ]
   877  	// }
   878  
   879  }
   880  

View as plain text