Skip to content

Commit

Permalink
google-api-go-client: add support for "repeated" params
Browse files Browse the repository at this point in the history
Fixes googleapis#105 and googleapis#110.

Recommended reading order:
1) google-api-go-generator/gen.go
2) google-api-go-generator/gen_test.go
3) internal/params.go
4) google-api-go-generator/testdata/repeated.*
5) google-api-go-generator/testdata/param-rename.*
6) spot-check random APIs and/or other testdata/*

The problem with the last solution was that sometimes the generator
changes the argument name from the API name, and this was not being
handled properly. There is now a new test (param-rename.*) that
checks for the proper renaming of argument to API names.

Specifically, the only changes made since the last
review (apart from the new unit test) were to
lines 1577-1585 (arg.goname => arg.apiname) in
google-api-go-generator/gen.go.

The original implementation (which was reverted) and its review
is located here: https://code-review.googlesource.com/#/c/3520/
and the accidentally-submitted version is located here:
https://code-review.googlesource.com/#/c/3610/
which was also reverted.

Change-Id: I8ccf11cd2ef62430beac842fb6ef237ef7c730ca
Reviewed-on: https://code-review.googlesource.com/3732
Reviewed-by: Michael McGreevy <[email protected]>
  • Loading branch information
gmlewis committed Nov 16, 2015
1 parent c12ea1c commit 4d6c29d
Show file tree
Hide file tree
Showing 148 changed files with 54,476 additions and 77,638 deletions.
247 changes: 107 additions & 140 deletions adexchangebuyer/v1.2/adexchangebuyer-gen.go

Large diffs are not rendered by default.

753 changes: 329 additions & 424 deletions adexchangebuyer/v1.3/adexchangebuyer-gen.go

Large diffs are not rendered by default.

1,082 changes: 469 additions & 613 deletions adexchangebuyer/v1.4/adexchangebuyer-gen.go

Large diffs are not rendered by default.

752 changes: 308 additions & 444 deletions adexchangeseller/v1.1/adexchangeseller-gen.go

Large diffs are not rendered by default.

533 changes: 209 additions & 324 deletions adexchangeseller/v1/adexchangeseller-gen.go

Large diffs are not rendered by default.

631 changes: 261 additions & 370 deletions adexchangeseller/v2.0/adexchangeseller-gen.go

Large diffs are not rendered by default.

201 changes: 79 additions & 122 deletions admin/datatransfer/v1/admin-gen.go

Large diffs are not rendered by default.

3,145 changes: 1,314 additions & 1,831 deletions admin/directory/v1/admin-gen.go

Large diffs are not rendered by default.

80 changes: 36 additions & 44 deletions admin/email_migration/v2/admin-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,39 +131,40 @@ func (s *MailItem) MarshalJSON() ([]byte, error) {
// method id "emailMigration.mail.insert":

type MailInsertCall struct {
s *Service
userKey string
mailitem *MailItem
opt_ map[string]interface{}
media_ io.Reader
resumable_ googleapi.SizeReaderAt
mediaType_ string
protocol_ string
ctx_ context.Context
s *Service
userKey string
mailitem *MailItem
urlParams_ gensupport.URLParams
media_ io.Reader
resumable_ googleapi.SizeReaderAt
mediaType_ string
protocol_ string
progressUpdater_ googleapi.ProgressUpdater
ctx_ context.Context
}

// Insert: Insert Mail into Google's Gmail backends
func (r *MailService) Insert(userKey string, mailitem *MailItem) *MailInsertCall {
c := &MailInsertCall{s: r.s, opt_: make(map[string]interface{})}
c := &MailInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
c.userKey = userKey
c.mailitem = mailitem
return c
}

// Media specifies the media to upload in a single chunk.
// At most one of Media and ResumableMedia may be set.
// Media specifies the media to upload in a single chunk. At most one of
// Media and ResumableMedia may be set.
func (c *MailInsertCall) Media(r io.Reader) *MailInsertCall {
c.media_ = r
c.protocol_ = "multipart"
return c
}

// ResumableMedia specifies the media to upload in chunks and can be canceled with ctx.
// At most one of Media and ResumableMedia may be set.
// mediaType identifies the MIME media type of the upload, such as "image/png".
// If mediaType is "", it will be auto-detected.
// The provided ctx will supersede any context previously provided to
// the Context method.
// ResumableMedia specifies the media to upload in chunks and can be
// canceled with ctx. At most one of Media and ResumableMedia may be
// set. mediaType identifies the MIME media type of the upload, such as
// "image/png". If mediaType is "", it will be auto-detected. The
// provided ctx will supersede any context previously provided to the
// Context method.
func (c *MailInsertCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size int64, mediaType string) *MailInsertCall {
c.ctx_ = ctx
c.resumable_ = io.NewSectionReader(r, 0, size)
Expand All @@ -172,27 +173,28 @@ func (c *MailInsertCall) ResumableMedia(ctx context.Context, r io.ReaderAt, size
return c
}

// ProgressUpdater provides a callback function that will be called after every chunk.
// It should be a low-latency function in order to not slow down the upload operation.
// This should only be called when using ResumableMedia (as opposed to Media).
// ProgressUpdater provides a callback function that will be called
// after every chunk. It should be a low-latency function in order to
// not slow down the upload operation. This should only be called when
// using ResumableMedia (as opposed to Media).
func (c *MailInsertCall) ProgressUpdater(pu googleapi.ProgressUpdater) *MailInsertCall {
c.opt_["progressUpdater"] = pu
c.progressUpdater_ = pu
return c
}

// Fields allows partial responses to be retrieved.
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
// Fields allows partial responses to be retrieved. See
// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
// for more information.
func (c *MailInsertCall) Fields(s ...googleapi.Field) *MailInsertCall {
c.opt_["fields"] = googleapi.CombineFields(s)
c.urlParams_.Set("fields", googleapi.CombineFields(s))
return c
}

// Context sets the context to be used in this call's Do method.
// Any pending HTTP request will be aborted if the provided context
// is canceled.
// This context will supersede any context previously provided to
// the ResumableMedia method.
// Context sets the context to be used in this call's Do method. Any
// pending HTTP request will be aborted if the provided context is
// canceled.
// This context will supersede any context previously provided to the
// ResumableMedia method.
func (c *MailInsertCall) Context(ctx context.Context) *MailInsertCall {
c.ctx_ = ctx
return c
Expand All @@ -205,17 +207,13 @@ func (c *MailInsertCall) doRequest(alt string) (*http.Response, error) {
return nil, err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", alt)
if v, ok := c.opt_["fields"]; ok {
params.Set("fields", fmt.Sprintf("%v", v))
}
c.urlParams_.Set("alt", alt)
urls := googleapi.ResolveRelative(c.s.BasePath, "{userKey}/mail")
if c.media_ != nil || c.resumable_ != nil {
urls = strings.Replace(urls, "https://www.googleapis.com/", "https://www.googleapis.com/upload/", 1)
params.Set("uploadType", c.protocol_)
c.urlParams_.Set("uploadType", c.protocol_)
}
urls += "?" + params.Encode()
urls += "?" + c.urlParams_.Encode()
if c.protocol_ != "resumable" {
var cancel func()
cancel, _ = googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
Expand Down Expand Up @@ -253,12 +251,6 @@ func (c *MailInsertCall) Do() error {
if err := googleapi.CheckResponse(res); err != nil {
return err
}
var progressUpdater_ googleapi.ProgressUpdater
if v, ok := c.opt_["progressUpdater"]; ok {
if pu, ok := v.(googleapi.ProgressUpdater); ok {
progressUpdater_ = pu
}
}
if c.protocol_ == "resumable" {
loc := res.Header.Get("Location")
rx := &googleapi.ResumableUpload{
Expand All @@ -268,7 +260,7 @@ func (c *MailInsertCall) Do() error {
Media: c.resumable_,
MediaType: c.mediaType_,
ContentLength: c.resumable_.Size(),
Callback: progressUpdater_,
Callback: c.progressUpdater_,
}
res, err = rx.Upload(c.ctx_)
if err != nil {
Expand Down

0 comments on commit 4d6c29d

Please sign in to comment.