...

Text file src/google.golang.org/api/google-api-go-generator/testdata/repeated.want

Documentation: google.golang.org/api/google-api-go-generator/testdata

     1// Copyright YEAR 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 repeated provides access to the Example API.
     8//
     9// # Library status
    10//
    11// These client libraries are officially supported by Google. However, this
    12// library is considered complete and is in maintenance mode. This means
    13// that we will address critical bugs and security issues but will not add
    14// any new features.
    15//
    16// When possible, we recommend using our newer
    17// [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go)
    18// that are still actively being worked and iterated on.
    19//
    20// # Creating a client
    21//
    22// Usage example:
    23//
    24//	import "google.golang.org/api/repeated/v1"
    25//	...
    26//	ctx := context.Background()
    27//	repeatedService, err := repeated.NewService(ctx)
    28//
    29// In this example, Google Application Default Credentials are used for
    30// authentication. For information on how to create and obtain Application
    31// Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
    32//
    33// # Other authentication options
    34//
    35// To use an API key for authentication (note: some APIs do not support API
    36// keys), use [google.golang.org/api/option.WithAPIKey]:
    37//
    38//	repeatedService, err := repeated.NewService(ctx, option.WithAPIKey("AIza..."))
    39//
    40// To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
    41// flow, use [google.golang.org/api/option.WithTokenSource]:
    42//
    43//	config := &oauth2.Config{...}
    44//	// ...
    45//	token, err := config.Exchange(ctx, ...)
    46//	repeatedService, err := repeated.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    47//
    48// See [google.golang.org/api/option.ClientOption] for details on options.
    49package repeated // import "google.golang.org/api/repeated/v1"
    50
    51import (
    52	"bytes"
    53	"context"
    54	"encoding/json"
    55	"errors"
    56	"fmt"
    57	"io"
    58	"net/http"
    59	"net/url"
    60	"strconv"
    61	"strings"
    62
    63	googleapi "google.golang.org/api/googleapi"
    64	internal "google.golang.org/api/internal"
    65	gensupport "google.golang.org/api/internal/gensupport"
    66	option "google.golang.org/api/option"
    67	internaloption "google.golang.org/api/option/internaloption"
    68	htransport "google.golang.org/api/transport/http"
    69)
    70
    71// Always reference these packages, just in case the auto-generated code
    72// below doesn't.
    73var _ = bytes.NewBuffer
    74var _ = strconv.Itoa
    75var _ = fmt.Sprintf
    76var _ = json.NewDecoder
    77var _ = io.Copy
    78var _ = url.Parse
    79var _ = gensupport.MarshalJSON
    80var _ = googleapi.Version
    81var _ = errors.New
    82var _ = strings.Replace
    83var _ = context.Canceled
    84var _ = internaloption.WithDefaultEndpoint
    85var _ = internal.Version
    86
    87const apiId = "repeated:v1"
    88const apiName = "repeated"
    89const apiVersion = "v1"
    90const basePath = "https://www.googleapis.com/discovery/v1/apis"
    91const basePathTemplate = "https://www.UNIVERSE_DOMAIN/discovery/v1/apis"
    92
    93// NewService creates a new Service.
    94func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
    95	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
    96	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
    97	opts = append(opts, internaloption.EnableNewAuthLibrary())
    98	client, endpoint, err := htransport.NewClient(ctx, opts...)
    99	if err != nil {
   100		return nil, err
   101	}
   102	s, err := New(client)
   103	if err != nil {
   104		return nil, err
   105	}
   106	if endpoint != "" {
   107		s.BasePath = endpoint
   108	}
   109	return s, nil
   110}
   111
   112// New creates a new Service. It uses the provided http.Client for requests.
   113//
   114// Deprecated: please use NewService instead.
   115// To provide a custom HTTP client, use option.WithHTTPClient.
   116// If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   117func New(client *http.Client) (*Service, error) {
   118	if client == nil {
   119		return nil, errors.New("client is nil")
   120	}
   121	s := &Service{client: client, BasePath: basePath}
   122	s.Accounts = NewAccountsService(s)
   123	return s, nil
   124}
   125
   126type Service struct {
   127	client    *http.Client
   128	BasePath  string // API endpoint base URL
   129	UserAgent string // optional additional User-Agent fragment
   130
   131	Accounts *AccountsService
   132}
   133
   134func (s *Service) userAgent() string {
   135	if s.UserAgent == "" {
   136		return googleapi.UserAgent
   137	}
   138	return googleapi.UserAgent + " " + s.UserAgent
   139}
   140
   141func NewAccountsService(s *Service) *AccountsService {
   142	rs := &AccountsService{s: s}
   143	rs.Reports = NewAccountsReportsService(s)
   144	return rs
   145}
   146
   147type AccountsService struct {
   148	s *Service
   149
   150	Reports *AccountsReportsService
   151}
   152
   153func NewAccountsReportsService(s *Service) *AccountsReportsService {
   154	rs := &AccountsReportsService{s: s}
   155	return rs
   156}
   157
   158type AccountsReportsService struct {
   159	s *Service
   160}
   161
   162type AccountsReportsGenerateCall struct {
   163	s            *Service
   164	accountId    string
   165	urlParams_   gensupport.URLParams
   166	ifNoneMatch_ string
   167	ctx_         context.Context
   168	header_      http.Header
   169}
   170
   171// Generate: Generate an AdSense report based on the report request sent in the
   172// query parameters. Returns the result as JSON; to retrieve output in CSV
   173// format specify "alt=csv" as a query parameter.
   174//
   175// - accountId: Account upon which to report.
   176func (r *AccountsReportsService) Generate(ids []int64, currency string, accountId string, dimension []string) *AccountsReportsGenerateCall {
   177	c := &AccountsReportsGenerateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   178	var ids_ []string
   179	for _, v := range ids {
   180		ids_ = append(ids_, fmt.Sprint(v))
   181	}
   182	c.urlParams_.SetMulti("ids", ids_)
   183	c.urlParams_.Set("currency", currency)
   184	c.accountId = accountId
   185	c.urlParams_.SetMulti("dimension", append([]string{}, dimension...))
   186	return c
   187}
   188
   189// Currency sets the optional parameter "currency": Optional currency to use
   190// when reporting on monetary metrics. Defaults to the account's currency if
   191// not set.
   192func (c *AccountsReportsGenerateCall) Currency(currency string) *AccountsReportsGenerateCall {
   193	c.urlParams_.Set("currency", currency)
   194	return c
   195}
   196
   197// Dimension sets the optional parameter "dimension": Dimensions to base the
   198// report on.
   199func (c *AccountsReportsGenerateCall) Dimension(dimension ...string) *AccountsReportsGenerateCall {
   200	c.urlParams_.SetMulti("dimension", append([]string{}, dimension...))
   201	return c
   202}
   203
   204// Ids sets the optional parameter "ids": Select only user profiles with these
   205// IDs.
   206func (c *AccountsReportsGenerateCall) Ids(ids ...int64) *AccountsReportsGenerateCall {
   207	var ids_ []string
   208	for _, v := range ids {
   209		ids_ = append(ids_, fmt.Sprint(v))
   210	}
   211	c.urlParams_.SetMulti("ids", ids_)
   212	return c
   213}
   214
   215// Fields allows partial responses to be retrieved. See
   216// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   217// details.
   218func (c *AccountsReportsGenerateCall) Fields(s ...googleapi.Field) *AccountsReportsGenerateCall {
   219	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   220	return c
   221}
   222
   223// IfNoneMatch sets an optional parameter which makes the operation fail if the
   224// object's ETag matches the given value. This is useful for getting updates
   225// only after the object has changed since the last request.
   226func (c *AccountsReportsGenerateCall) IfNoneMatch(entityTag string) *AccountsReportsGenerateCall {
   227	c.ifNoneMatch_ = entityTag
   228	return c
   229}
   230
   231// Context sets the context to be used in this call's Do method.
   232func (c *AccountsReportsGenerateCall) Context(ctx context.Context) *AccountsReportsGenerateCall {
   233	c.ctx_ = ctx
   234	return c
   235}
   236
   237// Header returns a http.Header that can be modified by the caller to add
   238// headers to the request.
   239func (c *AccountsReportsGenerateCall) Header() http.Header {
   240	if c.header_ == nil {
   241		c.header_ = make(http.Header)
   242	}
   243	return c.header_
   244}
   245
   246func (c *AccountsReportsGenerateCall) doRequest(alt string) (*http.Response, error) {
   247	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   248	if c.ifNoneMatch_ != "" {
   249		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   250	}
   251	var body io.Reader = nil
   252	c.urlParams_.Set("alt", alt)
   253	c.urlParams_.Set("prettyPrint", "false")
   254	urls := googleapi.ResolveRelative(c.s.BasePath, "accounts/{accountId}/reports")
   255	urls += "?" + c.urlParams_.Encode()
   256	req, err := http.NewRequest("GET", urls, body)
   257	if err != nil {
   258		return nil, err
   259	}
   260	req.Header = reqHeaders
   261	googleapi.Expand(req.URL, map[string]string{
   262		"accountId": c.accountId,
   263	})
   264	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   265}
   266
   267// Do executes the "adsense.accounts.reports.generate" call.
   268func (c *AccountsReportsGenerateCall) Do(opts ...googleapi.CallOption) error {
   269	gensupport.SetOptions(c.urlParams_, opts...)
   270	res, err := c.doRequest("json")
   271	if err != nil {
   272		return err
   273	}
   274	defer googleapi.CloseBody(res)
   275	if err := googleapi.CheckResponse(res); err != nil {
   276		return gensupport.WrapError(err)
   277	}
   278	return nil
   279}

View as plain text