Skip to content

Commit

Permalink
google-api-go-client: add If-None-Match support
Browse files Browse the repository at this point in the history
Fixes googleapis#86.

Note that examples/storage.go demonstrates the use of the new
If-None-Match support.

Additionally, this change allows the headers of all responses
to be inspected so that "ETag", for example, could be extracted
from the response. This could be especially useful for the
Compute API and other APIs that do not explicitly return ETag
within the body of their responses.

Note also that examples/compute.go now demonstrates the use of the
new googleapi.ServiceResponse and "ETag" extraction from the header.

Change-Id: Ic6fc35c6bdd4aca87ba0ee51b59f94b8de34d5ea
Reviewed-on: https://code-review.googlesource.com/3375
Reviewed-by: Glenn Lewis <[email protected]>
  • Loading branch information
gmlewis committed Oct 2, 2015
1 parent 09c6521 commit 7f3774d
Show file tree
Hide file tree
Showing 143 changed files with 92,203 additions and 2,988 deletions.
229 changes: 222 additions & 7 deletions adexchangebuyer/v1.2/adexchangebuyer-gen.go

Large diffs are not rendered by default.

665 changes: 645 additions & 20 deletions adexchangebuyer/v1.3/adexchangebuyer-gen.go

Large diffs are not rendered by default.

1,426 changes: 1,382 additions & 44 deletions adexchangebuyer/v1.4/adexchangebuyer-gen.go

Large diffs are not rendered by default.

664 changes: 647 additions & 17 deletions adexchangeseller/v1.1/adexchangeseller-gen.go

Large diffs are not rendered by default.

428 changes: 417 additions & 11 deletions adexchangeseller/v1/adexchangeseller-gen.go

Large diffs are not rendered by default.

552 changes: 538 additions & 14 deletions adexchangeseller/v2.0/adexchangeseller-gen.go

Large diffs are not rendered by default.

183 changes: 178 additions & 5 deletions admin/datatransfer/v1/admin-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ type Application struct {
// user in this application to be transfered.
TransferParams []*ApplicationTransferParam `json:"transferParams,omitempty"`

// ServerResponse contains the HTTP response code and headers from the
// server.
googleapi.ServerResponse `json:"-"`

// ForceSendFields is a list of field names (e.g. "Etag") to
// unconditionally include in API requests. By default, fields with
// empty values are omitted from API requests. However, any non-pointer,
Expand Down Expand Up @@ -202,6 +206,10 @@ type ApplicationsListResponse struct {
// page in list API.
NextPageToken string `json:"nextPageToken,omitempty"`

// ServerResponse contains the HTTP response code and headers from the
// server.
googleapi.ServerResponse `json:"-"`

// ForceSendFields is a list of field names (e.g. "Applications") to
// unconditionally include in API requests. By default, fields with
// empty values are omitted from API requests. However, any non-pointer,
Expand Down Expand Up @@ -248,6 +256,10 @@ type DataTransfer struct {
// (Read-only).
RequestTime string `json:"requestTime,omitempty"`

// ServerResponse contains the HTTP response code and headers from the
// server.
googleapi.ServerResponse `json:"-"`

// ForceSendFields is a list of field names (e.g.
// "ApplicationDataTransfers") to unconditionally include in API
// requests. By default, fields with empty values are omitted from API
Expand Down Expand Up @@ -281,6 +293,10 @@ type DataTransfersListResponse struct {
// page in list API.
NextPageToken string `json:"nextPageToken,omitempty"`

// ServerResponse contains the HTTP response code and headers from the
// server.
googleapi.ServerResponse `json:"-"`

// ForceSendFields is a list of field names (e.g. "DataTransfers") to
// unconditionally include in API requests. By default, fields with
// empty values are omitted from API requests. However, any non-pointer,
Expand Down Expand Up @@ -321,6 +337,16 @@ func (c *ApplicationsGetCall) Fields(s ...googleapi.Field) *ApplicationsGetCall
return c
}

// IfNoneMatch sets the optional parameter which makes the operation
// fail if the object's ETag matches the given value. This is useful for
// getting updates only after the object has changed since the last
// request. Use googleapi.IsNotModified to check whether the response
// error from Do is the result of In-None-Match.
func (c *ApplicationsGetCall) IfNoneMatch(entityTag string) *ApplicationsGetCall {
c.opt_["ifNoneMatch"] = entityTag
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.
Expand All @@ -343,22 +369,46 @@ func (c *ApplicationsGetCall) doRequest(alt string) (*http.Response, error) {
"applicationId": strconv.FormatInt(c.applicationId, 10),
})
req.Header.Set("User-Agent", c.s.userAgent())
if v, ok := c.opt_["ifNoneMatch"]; ok {
req.Header.Set("If-None-Match", fmt.Sprintf("%v", v))
}
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

// Do executes the "datatransfer.applications.get" call.
// Exactly one of *Application or error will be non-nil. Any non-2xx
// status code is an error. Response headers are in either
// *Application.ServerResponse.Header or (if a response was returned at
// all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
// to check whether the returned error was because
// http.StatusNotModified was returned.
func (c *ApplicationsGetCall) Do() (*Application, error) {
res, err := c.doRequest("json")
if res != nil && res.StatusCode == http.StatusNotModified {
if res.Body != nil {
res.Body.Close()
}
return nil, &googleapi.Error{
Code: res.StatusCode,
Header: res.Header,
}
}
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *Application
ret := &Application{
ServerResponse: googleapi.ServerResponse{
Header: res.Header,
HTTPStatusCode: res.StatusCode,
},
}
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
Expand Down Expand Up @@ -435,6 +485,16 @@ func (c *ApplicationsListCall) Fields(s ...googleapi.Field) *ApplicationsListCal
return c
}

// IfNoneMatch sets the optional parameter which makes the operation
// fail if the object's ETag matches the given value. This is useful for
// getting updates only after the object has changed since the last
// request. Use googleapi.IsNotModified to check whether the response
// error from Do is the result of In-None-Match.
func (c *ApplicationsListCall) IfNoneMatch(entityTag string) *ApplicationsListCall {
c.opt_["ifNoneMatch"] = entityTag
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.
Expand Down Expand Up @@ -464,22 +524,46 @@ func (c *ApplicationsListCall) doRequest(alt string) (*http.Response, error) {
req, _ := http.NewRequest("GET", urls, body)
googleapi.SetOpaque(req.URL)
req.Header.Set("User-Agent", c.s.userAgent())
if v, ok := c.opt_["ifNoneMatch"]; ok {
req.Header.Set("If-None-Match", fmt.Sprintf("%v", v))
}
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

// Do executes the "datatransfer.applications.list" call.
// Exactly one of *ApplicationsListResponse or error will be non-nil.
// Any non-2xx status code is an error. Response headers are in either
// *ApplicationsListResponse.ServerResponse.Header or (if a response was
// returned at all) in error.(*googleapi.Error).Header. Use
// googleapi.IsNotModified to check whether the returned error was
// because http.StatusNotModified was returned.
func (c *ApplicationsListCall) Do() (*ApplicationsListResponse, error) {
res, err := c.doRequest("json")
if res != nil && res.StatusCode == http.StatusNotModified {
if res.Body != nil {
res.Body.Close()
}
return nil, &googleapi.Error{
Code: res.StatusCode,
Header: res.Header,
}
}
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *ApplicationsListResponse
ret := &ApplicationsListResponse{
ServerResponse: googleapi.ServerResponse{
Header: res.Header,
HTTPStatusCode: res.StatusCode,
},
}
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
Expand Down Expand Up @@ -544,6 +628,16 @@ func (c *TransfersGetCall) Fields(s ...googleapi.Field) *TransfersGetCall {
return c
}

// IfNoneMatch sets the optional parameter which makes the operation
// fail if the object's ETag matches the given value. This is useful for
// getting updates only after the object has changed since the last
// request. Use googleapi.IsNotModified to check whether the response
// error from Do is the result of In-None-Match.
func (c *TransfersGetCall) IfNoneMatch(entityTag string) *TransfersGetCall {
c.opt_["ifNoneMatch"] = entityTag
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.
Expand All @@ -566,22 +660,46 @@ func (c *TransfersGetCall) doRequest(alt string) (*http.Response, error) {
"dataTransferId": c.dataTransferId,
})
req.Header.Set("User-Agent", c.s.userAgent())
if v, ok := c.opt_["ifNoneMatch"]; ok {
req.Header.Set("If-None-Match", fmt.Sprintf("%v", v))
}
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

// Do executes the "datatransfer.transfers.get" call.
// Exactly one of *DataTransfer or error will be non-nil. Any non-2xx
// status code is an error. Response headers are in either
// *DataTransfer.ServerResponse.Header or (if a response was returned at
// all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
// to check whether the returned error was because
// http.StatusNotModified was returned.
func (c *TransfersGetCall) Do() (*DataTransfer, error) {
res, err := c.doRequest("json")
if res != nil && res.StatusCode == http.StatusNotModified {
if res.Body != nil {
res.Body.Close()
}
return nil, &googleapi.Error{
Code: res.StatusCode,
Header: res.Header,
}
}
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *DataTransfer
ret := &DataTransfer{
ServerResponse: googleapi.ServerResponse{
Header: res.Header,
HTTPStatusCode: res.StatusCode,
},
}
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
Expand Down Expand Up @@ -669,16 +787,37 @@ func (c *TransfersInsertCall) doRequest(alt string) (*http.Response, error) {
return c.s.client.Do(req)
}

// Do executes the "datatransfer.transfers.insert" call.
// Exactly one of *DataTransfer or error will be non-nil. Any non-2xx
// status code is an error. Response headers are in either
// *DataTransfer.ServerResponse.Header or (if a response was returned at
// all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
// to check whether the returned error was because
// http.StatusNotModified was returned.
func (c *TransfersInsertCall) Do() (*DataTransfer, error) {
res, err := c.doRequest("json")
if res != nil && res.StatusCode == http.StatusNotModified {
if res.Body != nil {
res.Body.Close()
}
return nil, &googleapi.Error{
Code: res.StatusCode,
Header: res.Header,
}
}
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *DataTransfer
ret := &DataTransfer{
ServerResponse: googleapi.ServerResponse{
Header: res.Header,
HTTPStatusCode: res.StatusCode,
},
}
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
Expand Down Expand Up @@ -765,6 +904,16 @@ func (c *TransfersListCall) Fields(s ...googleapi.Field) *TransfersListCall {
return c
}

// IfNoneMatch sets the optional parameter which makes the operation
// fail if the object's ETag matches the given value. This is useful for
// getting updates only after the object has changed since the last
// request. Use googleapi.IsNotModified to check whether the response
// error from Do is the result of In-None-Match.
func (c *TransfersListCall) IfNoneMatch(entityTag string) *TransfersListCall {
c.opt_["ifNoneMatch"] = entityTag
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.
Expand Down Expand Up @@ -803,22 +952,46 @@ func (c *TransfersListCall) doRequest(alt string) (*http.Response, error) {
req, _ := http.NewRequest("GET", urls, body)
googleapi.SetOpaque(req.URL)
req.Header.Set("User-Agent", c.s.userAgent())
if v, ok := c.opt_["ifNoneMatch"]; ok {
req.Header.Set("If-None-Match", fmt.Sprintf("%v", v))
}
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

// Do executes the "datatransfer.transfers.list" call.
// Exactly one of *DataTransfersListResponse or error will be non-nil.
// Any non-2xx status code is an error. Response headers are in either
// *DataTransfersListResponse.ServerResponse.Header or (if a response
// was returned at all) in error.(*googleapi.Error).Header. Use
// googleapi.IsNotModified to check whether the returned error was
// because http.StatusNotModified was returned.
func (c *TransfersListCall) Do() (*DataTransfersListResponse, error) {
res, err := c.doRequest("json")
if res != nil && res.StatusCode == http.StatusNotModified {
if res.Body != nil {
res.Body.Close()
}
return nil, &googleapi.Error{
Code: res.StatusCode,
Header: res.Header,
}
}
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *DataTransfersListResponse
ret := &DataTransfersListResponse{
ServerResponse: googleapi.ServerResponse{
Header: res.Header,
HTTPStatusCode: res.StatusCode,
},
}
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 7f3774d

Please sign in to comment.