...

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

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

     1  // Copyright 2020 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 oauth2 provides access to the Google OAuth2 API.
     8  //
     9  // For product documentation, see: https://developers.google.com/accounts/docs/OAuth2
    10  //
    11  // # Creating a client
    12  //
    13  // Usage example:
    14  //
    15  //	import "google.golang.org/api/oauth2/v1"
    16  //	...
    17  //	ctx := context.Background()
    18  //	oauth2Service, err := oauth2.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  // By default, all available scopes (see "Constants") are used to authenticate. To restrict scopes, use option.WithScopes:
    27  //
    28  //	oauth2Service, err := oauth2.NewService(ctx, option.WithScopes(oauth2.UserinfoProfileScope))
    29  //
    30  // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
    31  //
    32  //	oauth2Service, err := oauth2.NewService(ctx, option.WithAPIKey("AIza..."))
    33  //
    34  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
    35  //
    36  //	config := &oauth2.Config{...}
    37  //	// ...
    38  //	token, err := config.Exchange(ctx, ...)
    39  //	oauth2Service, err := oauth2.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    40  //
    41  // See https://godoc.org/google.golang.org/api/option/ for details on options.
    42  package oauth2 // import "google.golang.org/api/oauth2/v1"
    43  
    44  import (
    45  	"bytes"
    46  	"context"
    47  	"encoding/json"
    48  	"errors"
    49  	"fmt"
    50  	"io"
    51  	"net/http"
    52  	"net/url"
    53  	"strconv"
    54  	"strings"
    55  
    56  	googleapi "google.golang.org/api/googleapi"
    57  	gensupport "google.golang.org/api/internal/gensupport"
    58  	option "google.golang.org/api/option"
    59  	internaloption "google.golang.org/api/option/internaloption"
    60  	htransport "google.golang.org/api/transport/http"
    61  )
    62  
    63  // Always reference these packages, just in case the auto-generated code
    64  // below doesn't.
    65  var _ = bytes.NewBuffer
    66  var _ = strconv.Itoa
    67  var _ = fmt.Sprintf
    68  var _ = json.NewDecoder
    69  var _ = io.Copy
    70  var _ = url.Parse
    71  var _ = gensupport.MarshalJSON
    72  var _ = googleapi.Version
    73  var _ = errors.New
    74  var _ = strings.Replace
    75  var _ = context.Canceled
    76  var _ = internaloption.WithDefaultEndpoint
    77  
    78  const apiId = "oauth2:v1"
    79  const apiName = "oauth2"
    80  const apiVersion = "v1"
    81  const basePath = "https://www.googleapis.com/"
    82  
    83  // OAuth2 scopes used by this API.
    84  const (
    85  	// Associate you with your personal info on Google
    86  	PlusMeScope = "https://www.googleapis.com/auth/plus.me"
    87  
    88  	// View your email address
    89  	UserinfoEmailScope = "https://www.googleapis.com/auth/userinfo.email"
    90  
    91  	// See your personal info, including any personal info you've made
    92  	// publicly available
    93  	UserinfoProfileScope = "https://www.googleapis.com/auth/userinfo.profile"
    94  )
    95  
    96  // NewService creates a new Service.
    97  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
    98  	scopesOption := option.WithScopes(
    99  		"https://www.googleapis.com/auth/plus.me",
   100  		"https://www.googleapis.com/auth/userinfo.email",
   101  		"https://www.googleapis.com/auth/userinfo.profile",
   102  	)
   103  	// NOTE: prepend, so we don't override user-specified scopes.
   104  	opts = append([]option.ClientOption{scopesOption}, opts...)
   105  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
   106  	client, endpoint, err := htransport.NewClient(ctx, opts...)
   107  	if err != nil {
   108  		return nil, err
   109  	}
   110  	s, err := New(client)
   111  	if err != nil {
   112  		return nil, err
   113  	}
   114  	if endpoint != "" {
   115  		s.BasePath = endpoint
   116  	}
   117  	return s, nil
   118  }
   119  
   120  // New creates a new Service. It uses the provided http.Client for requests.
   121  //
   122  // Deprecated: please use NewService instead.
   123  // To provide a custom HTTP client, use option.WithHTTPClient.
   124  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   125  func New(client *http.Client) (*Service, error) {
   126  	if client == nil {
   127  		return nil, errors.New("client is nil")
   128  	}
   129  	s := &Service{client: client, BasePath: basePath}
   130  	s.Userinfo = NewUserinfoService(s)
   131  	return s, nil
   132  }
   133  
   134  type Service struct {
   135  	client    *http.Client
   136  	BasePath  string // API endpoint base URL
   137  	UserAgent string // optional additional User-Agent fragment
   138  
   139  	Userinfo *UserinfoService
   140  }
   141  
   142  func (s *Service) userAgent() string {
   143  	if s.UserAgent == "" {
   144  		return googleapi.UserAgent
   145  	}
   146  	return googleapi.UserAgent + " " + s.UserAgent
   147  }
   148  
   149  func NewUserinfoService(s *Service) *UserinfoService {
   150  	rs := &UserinfoService{s: s}
   151  	rs.V2 = NewUserinfoV2Service(s)
   152  	return rs
   153  }
   154  
   155  type UserinfoService struct {
   156  	s *Service
   157  
   158  	V2 *UserinfoV2Service
   159  }
   160  
   161  func NewUserinfoV2Service(s *Service) *UserinfoV2Service {
   162  	rs := &UserinfoV2Service{s: s}
   163  	rs.Me = NewUserinfoV2MeService(s)
   164  	return rs
   165  }
   166  
   167  type UserinfoV2Service struct {
   168  	s *Service
   169  
   170  	Me *UserinfoV2MeService
   171  }
   172  
   173  func NewUserinfoV2MeService(s *Service) *UserinfoV2MeService {
   174  	rs := &UserinfoV2MeService{s: s}
   175  	return rs
   176  }
   177  
   178  type UserinfoV2MeService struct {
   179  	s *Service
   180  }
   181  
   182  type Tokeninfo struct {
   183  	// AccessType: The access type granted with this token. It can be
   184  	// offline or online.
   185  	AccessType string `json:"access_type,omitempty"`
   186  
   187  	// Audience: Who is the intended audience for this token. In general the
   188  	// same as issued_to.
   189  	Audience string `json:"audience,omitempty"`
   190  
   191  	// Email: The email address of the user. Present only if the email scope
   192  	// is present in the request.
   193  	Email string `json:"email,omitempty"`
   194  
   195  	// EmailVerified: Boolean flag which is true if the email address is
   196  	// verified. Present only if the email scope is present in the request.
   197  	EmailVerified bool `json:"email_verified,omitempty"`
   198  
   199  	// ExpiresIn: The expiry time of the token, as number of seconds left
   200  	// until expiry.
   201  	ExpiresIn int64 `json:"expires_in,omitempty"`
   202  
   203  	// IssuedAt: The issue time of the token, as number of seconds.
   204  	IssuedAt int64 `json:"issued_at,omitempty"`
   205  
   206  	// IssuedTo: To whom was the token issued to. In general the same as
   207  	// audience.
   208  	IssuedTo string `json:"issued_to,omitempty"`
   209  
   210  	// Issuer: Who issued the token.
   211  	Issuer string `json:"issuer,omitempty"`
   212  
   213  	// Nonce: Nonce of the id token.
   214  	Nonce string `json:"nonce,omitempty"`
   215  
   216  	// Scope: The space separated list of scopes granted to this token.
   217  	Scope string `json:"scope,omitempty"`
   218  
   219  	// UserId: The obfuscated user id.
   220  	UserId string `json:"user_id,omitempty"`
   221  
   222  	// VerifiedEmail: Boolean flag which is true if the email address is
   223  	// verified. Present only if the email scope is present in the request.
   224  	VerifiedEmail bool `json:"verified_email,omitempty"`
   225  
   226  	// ServerResponse contains the HTTP response code and headers from the
   227  	// server.
   228  	googleapi.ServerResponse `json:"-"`
   229  
   230  	// ForceSendFields is a list of field names (e.g. "AccessType") to
   231  	// unconditionally include in API requests. By default, fields with
   232  	// empty values are omitted from API requests. However, any non-pointer,
   233  	// non-interface field appearing in ForceSendFields will be sent to the
   234  	// server regardless of whether the field is empty or not. This may be
   235  	// used to include empty fields in Patch requests.
   236  	ForceSendFields []string `json:"-"`
   237  
   238  	// NullFields is a list of field names (e.g. "AccessType") to include in
   239  	// API requests with the JSON null value. By default, fields with empty
   240  	// values are omitted from API requests. However, any field with an
   241  	// empty value appearing in NullFields will be sent to the server as
   242  	// null. It is an error if a field in this list has a non-empty value.
   243  	// This may be used to include null fields in Patch requests.
   244  	NullFields []string `json:"-"`
   245  }
   246  
   247  func (s *Tokeninfo) MarshalJSON() ([]byte, error) {
   248  	type NoMethod Tokeninfo
   249  	raw := NoMethod(*s)
   250  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   251  }
   252  
   253  type Userinfoplus struct {
   254  	// Email: The user's email address.
   255  	Email string `json:"email,omitempty"`
   256  
   257  	// FamilyName: The user's last name.
   258  	FamilyName string `json:"family_name,omitempty"`
   259  
   260  	// Gender: The user's gender.
   261  	Gender string `json:"gender,omitempty"`
   262  
   263  	// GivenName: The user's first name.
   264  	GivenName string `json:"given_name,omitempty"`
   265  
   266  	// Hd: The hosted domain e.g. example.com if the user is Google apps
   267  	// user.
   268  	Hd string `json:"hd,omitempty"`
   269  
   270  	// Id: The obfuscated ID of the user.
   271  	Id string `json:"id,omitempty"`
   272  
   273  	// Link: URL of the profile page.
   274  	Link string `json:"link,omitempty"`
   275  
   276  	// Locale: The user's preferred locale.
   277  	Locale string `json:"locale,omitempty"`
   278  
   279  	// Name: The user's full name.
   280  	Name string `json:"name,omitempty"`
   281  
   282  	// Picture: URL of the user's picture image.
   283  	Picture string `json:"picture,omitempty"`
   284  
   285  	// VerifiedEmail: Boolean flag which is true if the email address is
   286  	// verified. Always verified because we only return the user's primary
   287  	// email address.
   288  	//
   289  	// Default: true
   290  	VerifiedEmail *bool `json:"verified_email,omitempty"`
   291  
   292  	// ServerResponse contains the HTTP response code and headers from the
   293  	// server.
   294  	googleapi.ServerResponse `json:"-"`
   295  
   296  	// ForceSendFields is a list of field names (e.g. "Email") to
   297  	// unconditionally include in API requests. By default, fields with
   298  	// empty values are omitted from API requests. However, any non-pointer,
   299  	// non-interface field appearing in ForceSendFields will be sent to the
   300  	// server regardless of whether the field is empty or not. This may be
   301  	// used to include empty fields in Patch requests.
   302  	ForceSendFields []string `json:"-"`
   303  
   304  	// NullFields is a list of field names (e.g. "Email") to include in API
   305  	// requests with the JSON null value. By default, fields with empty
   306  	// values are omitted from API requests. However, any field with an
   307  	// empty value appearing in NullFields will be sent to the server as
   308  	// null. It is an error if a field in this list has a non-empty value.
   309  	// This may be used to include null fields in Patch requests.
   310  	NullFields []string `json:"-"`
   311  }
   312  
   313  func (s *Userinfoplus) MarshalJSON() ([]byte, error) {
   314  	type NoMethod Userinfoplus
   315  	raw := NoMethod(*s)
   316  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   317  }
   318  
   319  // method id "oauth2.tokeninfo":
   320  
   321  type TokeninfoCall struct {
   322  	s          *Service
   323  	urlParams_ gensupport.URLParams
   324  	ctx_       context.Context
   325  	header_    http.Header
   326  }
   327  
   328  // Tokeninfo: Get token info
   329  func (s *Service) Tokeninfo() *TokeninfoCall {
   330  	c := &TokeninfoCall{s: s, urlParams_: make(gensupport.URLParams)}
   331  	return c
   332  }
   333  
   334  // AccessToken sets the optional parameter "access_token": The oauth2
   335  // access token
   336  func (c *TokeninfoCall) AccessToken(accessToken string) *TokeninfoCall {
   337  	c.urlParams_.Set("access_token", accessToken)
   338  	return c
   339  }
   340  
   341  // IdToken sets the optional parameter "id_token": The ID token
   342  func (c *TokeninfoCall) IdToken(idToken string) *TokeninfoCall {
   343  	c.urlParams_.Set("id_token", idToken)
   344  	return c
   345  }
   346  
   347  // Fields allows partial responses to be retrieved. See
   348  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
   349  // for more information.
   350  func (c *TokeninfoCall) Fields(s ...googleapi.Field) *TokeninfoCall {
   351  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   352  	return c
   353  }
   354  
   355  // Context sets the context to be used in this call's Do method. Any
   356  // pending HTTP request will be aborted if the provided context is
   357  // canceled.
   358  func (c *TokeninfoCall) Context(ctx context.Context) *TokeninfoCall {
   359  	c.ctx_ = ctx
   360  	return c
   361  }
   362  
   363  // Header returns an http.Header that can be modified by the caller to
   364  // add HTTP headers to the request.
   365  func (c *TokeninfoCall) Header() http.Header {
   366  	if c.header_ == nil {
   367  		c.header_ = make(http.Header)
   368  	}
   369  	return c.header_
   370  }
   371  
   372  func (c *TokeninfoCall) doRequest(alt string) (*http.Response, error) {
   373  	reqHeaders := make(http.Header)
   374  	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20200317")
   375  	for k, v := range c.header_ {
   376  		reqHeaders[k] = v
   377  	}
   378  	reqHeaders.Set("User-Agent", c.s.userAgent())
   379  	var body io.Reader = nil
   380  	c.urlParams_.Set("alt", alt)
   381  	c.urlParams_.Set("prettyPrint", "false")
   382  	urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v1/tokeninfo")
   383  	urls += "?" + c.urlParams_.Encode()
   384  	req, err := http.NewRequest("POST", urls, body)
   385  	if err != nil {
   386  		return nil, err
   387  	}
   388  	req.Header = reqHeaders
   389  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   390  }
   391  
   392  // Do executes the "oauth2.tokeninfo" call.
   393  // Exactly one of *Tokeninfo or error will be non-nil. Any non-2xx
   394  // status code is an error. Response headers are in either
   395  // *Tokeninfo.ServerResponse.Header or (if a response was returned at
   396  // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
   397  // to check whether the returned error was because
   398  // http.StatusNotModified was returned.
   399  func (c *TokeninfoCall) Do(opts ...googleapi.CallOption) (*Tokeninfo, error) {
   400  	gensupport.SetOptions(c.urlParams_, opts...)
   401  	res, err := c.doRequest("json")
   402  	if res != nil && res.StatusCode == http.StatusNotModified {
   403  		if res.Body != nil {
   404  			res.Body.Close()
   405  		}
   406  		return nil, &googleapi.Error{
   407  			Code:   res.StatusCode,
   408  			Header: res.Header,
   409  		}
   410  	}
   411  	if err != nil {
   412  		return nil, err
   413  	}
   414  	defer googleapi.CloseBody(res)
   415  	if err := googleapi.CheckResponse(res); err != nil {
   416  		return nil, err
   417  	}
   418  	ret := &Tokeninfo{
   419  		ServerResponse: googleapi.ServerResponse{
   420  			Header:         res.Header,
   421  			HTTPStatusCode: res.StatusCode,
   422  		},
   423  	}
   424  	target := &ret
   425  	if err := gensupport.DecodeResponse(target, res); err != nil {
   426  		return nil, err
   427  	}
   428  	return ret, nil
   429  	// {
   430  	//   "description": "Get token info",
   431  	//   "httpMethod": "POST",
   432  	//   "id": "oauth2.tokeninfo",
   433  	//   "parameters": {
   434  	//     "access_token": {
   435  	//       "description": "The oauth2 access token",
   436  	//       "location": "query",
   437  	//       "type": "string"
   438  	//     },
   439  	//     "id_token": {
   440  	//       "description": "The ID token",
   441  	//       "location": "query",
   442  	//       "type": "string"
   443  	//     }
   444  	//   },
   445  	//   "path": "oauth2/v1/tokeninfo",
   446  	//   "response": {
   447  	//     "$ref": "Tokeninfo"
   448  	//   }
   449  	// }
   450  
   451  }
   452  
   453  // method id "oauth2.userinfo.get":
   454  
   455  type UserinfoGetCall struct {
   456  	s            *Service
   457  	urlParams_   gensupport.URLParams
   458  	ifNoneMatch_ string
   459  	ctx_         context.Context
   460  	header_      http.Header
   461  }
   462  
   463  // Get: Get user info
   464  func (r *UserinfoService) Get() *UserinfoGetCall {
   465  	c := &UserinfoGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   466  	return c
   467  }
   468  
   469  // Fields allows partial responses to be retrieved. See
   470  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
   471  // for more information.
   472  func (c *UserinfoGetCall) Fields(s ...googleapi.Field) *UserinfoGetCall {
   473  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   474  	return c
   475  }
   476  
   477  // IfNoneMatch sets the optional parameter which makes the operation
   478  // fail if the object's ETag matches the given value. This is useful for
   479  // getting updates only after the object has changed since the last
   480  // request. Use googleapi.IsNotModified to check whether the response
   481  // error from Do is the result of In-None-Match.
   482  func (c *UserinfoGetCall) IfNoneMatch(entityTag string) *UserinfoGetCall {
   483  	c.ifNoneMatch_ = entityTag
   484  	return c
   485  }
   486  
   487  // Context sets the context to be used in this call's Do method. Any
   488  // pending HTTP request will be aborted if the provided context is
   489  // canceled.
   490  func (c *UserinfoGetCall) Context(ctx context.Context) *UserinfoGetCall {
   491  	c.ctx_ = ctx
   492  	return c
   493  }
   494  
   495  // Header returns an http.Header that can be modified by the caller to
   496  // add HTTP headers to the request.
   497  func (c *UserinfoGetCall) Header() http.Header {
   498  	if c.header_ == nil {
   499  		c.header_ = make(http.Header)
   500  	}
   501  	return c.header_
   502  }
   503  
   504  func (c *UserinfoGetCall) doRequest(alt string) (*http.Response, error) {
   505  	reqHeaders := make(http.Header)
   506  	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20200317")
   507  	for k, v := range c.header_ {
   508  		reqHeaders[k] = v
   509  	}
   510  	reqHeaders.Set("User-Agent", c.s.userAgent())
   511  	if c.ifNoneMatch_ != "" {
   512  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   513  	}
   514  	var body io.Reader = nil
   515  	c.urlParams_.Set("alt", alt)
   516  	c.urlParams_.Set("prettyPrint", "false")
   517  	urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v1/userinfo")
   518  	urls += "?" + c.urlParams_.Encode()
   519  	req, err := http.NewRequest("GET", urls, body)
   520  	if err != nil {
   521  		return nil, err
   522  	}
   523  	req.Header = reqHeaders
   524  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   525  }
   526  
   527  // Do executes the "oauth2.userinfo.get" call.
   528  // Exactly one of *Userinfoplus or error will be non-nil. Any non-2xx
   529  // status code is an error. Response headers are in either
   530  // *Userinfoplus.ServerResponse.Header or (if a response was returned at
   531  // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
   532  // to check whether the returned error was because
   533  // http.StatusNotModified was returned.
   534  func (c *UserinfoGetCall) Do(opts ...googleapi.CallOption) (*Userinfoplus, error) {
   535  	gensupport.SetOptions(c.urlParams_, opts...)
   536  	res, err := c.doRequest("json")
   537  	if res != nil && res.StatusCode == http.StatusNotModified {
   538  		if res.Body != nil {
   539  			res.Body.Close()
   540  		}
   541  		return nil, &googleapi.Error{
   542  			Code:   res.StatusCode,
   543  			Header: res.Header,
   544  		}
   545  	}
   546  	if err != nil {
   547  		return nil, err
   548  	}
   549  	defer googleapi.CloseBody(res)
   550  	if err := googleapi.CheckResponse(res); err != nil {
   551  		return nil, err
   552  	}
   553  	ret := &Userinfoplus{
   554  		ServerResponse: googleapi.ServerResponse{
   555  			Header:         res.Header,
   556  			HTTPStatusCode: res.StatusCode,
   557  		},
   558  	}
   559  	target := &ret
   560  	if err := gensupport.DecodeResponse(target, res); err != nil {
   561  		return nil, err
   562  	}
   563  	return ret, nil
   564  	// {
   565  	//   "description": "Get user info",
   566  	//   "httpMethod": "GET",
   567  	//   "id": "oauth2.userinfo.get",
   568  	//   "path": "oauth2/v1/userinfo",
   569  	//   "response": {
   570  	//     "$ref": "Userinfoplus"
   571  	//   },
   572  	//   "scopes": [
   573  	//     "https://www.googleapis.com/auth/plus.me",
   574  	//     "https://www.googleapis.com/auth/userinfo.email",
   575  	//     "https://www.googleapis.com/auth/userinfo.profile"
   576  	//   ]
   577  	// }
   578  
   579  }
   580  
   581  // method id "oauth2.userinfo.v2.me.get":
   582  
   583  type UserinfoV2MeGetCall struct {
   584  	s            *Service
   585  	urlParams_   gensupport.URLParams
   586  	ifNoneMatch_ string
   587  	ctx_         context.Context
   588  	header_      http.Header
   589  }
   590  
   591  // Get: Get user info
   592  func (r *UserinfoV2MeService) Get() *UserinfoV2MeGetCall {
   593  	c := &UserinfoV2MeGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   594  	return c
   595  }
   596  
   597  // Fields allows partial responses to be retrieved. See
   598  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
   599  // for more information.
   600  func (c *UserinfoV2MeGetCall) Fields(s ...googleapi.Field) *UserinfoV2MeGetCall {
   601  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   602  	return c
   603  }
   604  
   605  // IfNoneMatch sets the optional parameter which makes the operation
   606  // fail if the object's ETag matches the given value. This is useful for
   607  // getting updates only after the object has changed since the last
   608  // request. Use googleapi.IsNotModified to check whether the response
   609  // error from Do is the result of In-None-Match.
   610  func (c *UserinfoV2MeGetCall) IfNoneMatch(entityTag string) *UserinfoV2MeGetCall {
   611  	c.ifNoneMatch_ = entityTag
   612  	return c
   613  }
   614  
   615  // Context sets the context to be used in this call's Do method. Any
   616  // pending HTTP request will be aborted if the provided context is
   617  // canceled.
   618  func (c *UserinfoV2MeGetCall) Context(ctx context.Context) *UserinfoV2MeGetCall {
   619  	c.ctx_ = ctx
   620  	return c
   621  }
   622  
   623  // Header returns an http.Header that can be modified by the caller to
   624  // add HTTP headers to the request.
   625  func (c *UserinfoV2MeGetCall) Header() http.Header {
   626  	if c.header_ == nil {
   627  		c.header_ = make(http.Header)
   628  	}
   629  	return c.header_
   630  }
   631  
   632  func (c *UserinfoV2MeGetCall) doRequest(alt string) (*http.Response, error) {
   633  	reqHeaders := make(http.Header)
   634  	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20200317")
   635  	for k, v := range c.header_ {
   636  		reqHeaders[k] = v
   637  	}
   638  	reqHeaders.Set("User-Agent", c.s.userAgent())
   639  	if c.ifNoneMatch_ != "" {
   640  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   641  	}
   642  	var body io.Reader = nil
   643  	c.urlParams_.Set("alt", alt)
   644  	c.urlParams_.Set("prettyPrint", "false")
   645  	urls := googleapi.ResolveRelative(c.s.BasePath, "userinfo/v2/me")
   646  	urls += "?" + c.urlParams_.Encode()
   647  	req, err := http.NewRequest("GET", urls, body)
   648  	if err != nil {
   649  		return nil, err
   650  	}
   651  	req.Header = reqHeaders
   652  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   653  }
   654  
   655  // Do executes the "oauth2.userinfo.v2.me.get" call.
   656  // Exactly one of *Userinfoplus or error will be non-nil. Any non-2xx
   657  // status code is an error. Response headers are in either
   658  // *Userinfoplus.ServerResponse.Header or (if a response was returned at
   659  // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
   660  // to check whether the returned error was because
   661  // http.StatusNotModified was returned.
   662  func (c *UserinfoV2MeGetCall) Do(opts ...googleapi.CallOption) (*Userinfoplus, error) {
   663  	gensupport.SetOptions(c.urlParams_, opts...)
   664  	res, err := c.doRequest("json")
   665  	if res != nil && res.StatusCode == http.StatusNotModified {
   666  		if res.Body != nil {
   667  			res.Body.Close()
   668  		}
   669  		return nil, &googleapi.Error{
   670  			Code:   res.StatusCode,
   671  			Header: res.Header,
   672  		}
   673  	}
   674  	if err != nil {
   675  		return nil, err
   676  	}
   677  	defer googleapi.CloseBody(res)
   678  	if err := googleapi.CheckResponse(res); err != nil {
   679  		return nil, err
   680  	}
   681  	ret := &Userinfoplus{
   682  		ServerResponse: googleapi.ServerResponse{
   683  			Header:         res.Header,
   684  			HTTPStatusCode: res.StatusCode,
   685  		},
   686  	}
   687  	target := &ret
   688  	if err := gensupport.DecodeResponse(target, res); err != nil {
   689  		return nil, err
   690  	}
   691  	return ret, nil
   692  	// {
   693  	//   "description": "Get user info",
   694  	//   "httpMethod": "GET",
   695  	//   "id": "oauth2.userinfo.v2.me.get",
   696  	//   "path": "userinfo/v2/me",
   697  	//   "response": {
   698  	//     "$ref": "Userinfoplus"
   699  	//   },
   700  	//   "scopes": [
   701  	//     "https://www.googleapis.com/auth/plus.me",
   702  	//     "https://www.googleapis.com/auth/userinfo.email",
   703  	//     "https://www.googleapis.com/auth/userinfo.profile"
   704  	//   ]
   705  	// }
   706  
   707  }
   708  

View as plain text