...

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

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

     1  // Copyright 2021 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 youtubeanalytics provides access to the YouTube Analytics API.
     8  //
     9  // For product documentation, see: https://developers.google.com/youtube/analytics
    10  //
    11  // # Creating a client
    12  //
    13  // Usage example:
    14  //
    15  //	import "google.golang.org/api/youtubeanalytics/v1"
    16  //	...
    17  //	ctx := context.Background()
    18  //	youtubeanalyticsService, err := youtubeanalytics.NewService(ctx)
    19  //
    20  // In this example, Google Application Default Credentials are used for authentication.
    21  //
    22  // For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
    23  //
    24  // # Other authentication options
    25  //
    26  // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
    27  //
    28  //	youtubeanalyticsService, err := youtubeanalytics.NewService(ctx, option.WithAPIKey("AIza..."))
    29  //
    30  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
    31  //
    32  //	config := &oauth2.Config{...}
    33  //	// ...
    34  //	token, err := config.Exchange(ctx, ...)
    35  //	youtubeanalyticsService, err := youtubeanalytics.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    36  //
    37  // See https://godoc.org/google.golang.org/api/option/ for details on options.
    38  package youtubeanalytics // import "google.golang.org/api/youtubeanalytics/v1"
    39  
    40  import (
    41  	"bytes"
    42  	"context"
    43  	"encoding/json"
    44  	"errors"
    45  	"fmt"
    46  	"io"
    47  	"net/http"
    48  	"net/url"
    49  	"strconv"
    50  	"strings"
    51  
    52  	googleapi "google.golang.org/api/googleapi"
    53  	gensupport "google.golang.org/api/internal/gensupport"
    54  	option "google.golang.org/api/option"
    55  	internaloption "google.golang.org/api/option/internaloption"
    56  	htransport "google.golang.org/api/transport/http"
    57  )
    58  
    59  // Always reference these packages, just in case the auto-generated code
    60  // below doesn't.
    61  var _ = bytes.NewBuffer
    62  var _ = strconv.Itoa
    63  var _ = fmt.Sprintf
    64  var _ = json.NewDecoder
    65  var _ = io.Copy
    66  var _ = url.Parse
    67  var _ = gensupport.MarshalJSON
    68  var _ = googleapi.Version
    69  var _ = errors.New
    70  var _ = strings.Replace
    71  var _ = context.Canceled
    72  var _ = internaloption.WithDefaultEndpoint
    73  
    74  const apiId = "youtubeAnalytics:v1"
    75  const apiName = "youtubeAnalytics"
    76  const apiVersion = "v1"
    77  const basePath = "https://youtubeanalytics.googleapis.com/"
    78  const mtlsBasePath = "https://youtubeanalytics.mtls.googleapis.com/"
    79  
    80  // NewService creates a new Service.
    81  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
    82  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
    83  	opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
    84  	client, endpoint, err := htransport.NewClient(ctx, opts...)
    85  	if err != nil {
    86  		return nil, err
    87  	}
    88  	s, err := New(client)
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  	if endpoint != "" {
    93  		s.BasePath = endpoint
    94  	}
    95  	return s, nil
    96  }
    97  
    98  // New creates a new Service. It uses the provided http.Client for requests.
    99  //
   100  // Deprecated: please use NewService instead.
   101  // To provide a custom HTTP client, use option.WithHTTPClient.
   102  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   103  func New(client *http.Client) (*Service, error) {
   104  	if client == nil {
   105  		return nil, errors.New("client is nil")
   106  	}
   107  	s := &Service{client: client, BasePath: basePath}
   108  	return s, nil
   109  }
   110  
   111  type Service struct {
   112  	client    *http.Client
   113  	BasePath  string // API endpoint base URL
   114  	UserAgent string // optional additional User-Agent fragment
   115  }
   116  
   117  func (s *Service) userAgent() string {
   118  	if s.UserAgent == "" {
   119  		return googleapi.UserAgent
   120  	}
   121  	return googleapi.UserAgent + " " + s.UserAgent
   122  }
   123  

View as plain text