Skip to content

Commit

Permalink
Add golang.org/x/net/context support.
Browse files Browse the repository at this point in the history
Add a Context method to every call object which associates a context
with the call's Do (and Download) method. Make sure all HTTP calls
are made context-aware when a context is available.

Change-Id: I493cce4d43411810eb30b6c02dc151ef970a6254
Reviewed-on: https://code-review.googlesource.com/3472
Reviewed-by: Michael McGreevy <[email protected]>
  • Loading branch information
okdave authored and mcgreevy committed Sep 28, 2015
1 parent b82cbee commit 77b0a8c
Show file tree
Hide file tree
Showing 151 changed files with 40,010 additions and 248 deletions.
86 changes: 85 additions & 1 deletion adexchangebuyer/v1.2/adexchangebuyer-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"errors"
"fmt"
"golang.org/x/net/context"
"golang.org/x/net/context/ctxhttp"
"google.golang.org/api/googleapi"
"io"
"net/http"
Expand All @@ -34,7 +35,6 @@ var _ = url.Parse
var _ = googleapi.Version
var _ = errors.New
var _ = strings.Replace
var _ = context.Background

const apiId = "adexchangebuyer:v1.2"
const apiName = "adexchangebuyer"
Expand Down Expand Up @@ -310,6 +310,7 @@ type AccountsGetCall struct {
s *Service
id int64
opt_ map[string]interface{}
ctx_ context.Context
}

// Get: Gets one account by ID.
Expand All @@ -327,6 +328,14 @@ func (c *AccountsGetCall) Fields(s ...googleapi.Field) *AccountsGetCall {
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.
func (c *AccountsGetCall) Context(ctx context.Context) *AccountsGetCall {
c.ctx_ = ctx
return c
}

func (c *AccountsGetCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
params := make(url.Values)
Expand All @@ -341,6 +350,9 @@ func (c *AccountsGetCall) doRequest(alt string) (*http.Response, error) {
"id": strconv.FormatInt(c.id, 10),
})
req.Header.Set("User-Agent", c.s.userAgent())
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

Expand Down Expand Up @@ -390,6 +402,7 @@ func (c *AccountsGetCall) Do() (*Account, error) {
type AccountsListCall struct {
s *Service
opt_ map[string]interface{}
ctx_ context.Context
}

// List: Retrieves the authenticated user's list of accounts.
Expand All @@ -406,6 +419,14 @@ func (c *AccountsListCall) Fields(s ...googleapi.Field) *AccountsListCall {
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.
func (c *AccountsListCall) Context(ctx context.Context) *AccountsListCall {
c.ctx_ = ctx
return c
}

func (c *AccountsListCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
params := make(url.Values)
Expand All @@ -418,6 +439,9 @@ func (c *AccountsListCall) 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 c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

Expand Down Expand Up @@ -457,6 +481,7 @@ type AccountsPatchCall struct {
id int64
account *Account
opt_ map[string]interface{}
ctx_ context.Context
}

// Patch: Updates an existing account. This method supports patch
Expand All @@ -476,6 +501,14 @@ func (c *AccountsPatchCall) Fields(s ...googleapi.Field) *AccountsPatchCall {
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.
func (c *AccountsPatchCall) Context(ctx context.Context) *AccountsPatchCall {
c.ctx_ = ctx
return c
}

func (c *AccountsPatchCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.account)
Expand All @@ -496,6 +529,9 @@ func (c *AccountsPatchCall) doRequest(alt string) (*http.Response, error) {
})
req.Header.Set("Content-Type", ctype)
req.Header.Set("User-Agent", c.s.userAgent())
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

Expand Down Expand Up @@ -550,6 +586,7 @@ type AccountsUpdateCall struct {
id int64
account *Account
opt_ map[string]interface{}
ctx_ context.Context
}

// Update: Updates an existing account.
Expand All @@ -568,6 +605,14 @@ func (c *AccountsUpdateCall) Fields(s ...googleapi.Field) *AccountsUpdateCall {
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.
func (c *AccountsUpdateCall) Context(ctx context.Context) *AccountsUpdateCall {
c.ctx_ = ctx
return c
}

func (c *AccountsUpdateCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.account)
Expand All @@ -588,6 +633,9 @@ func (c *AccountsUpdateCall) doRequest(alt string) (*http.Response, error) {
})
req.Header.Set("Content-Type", ctype)
req.Header.Set("User-Agent", c.s.userAgent())
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

Expand Down Expand Up @@ -642,6 +690,7 @@ type CreativesGetCall struct {
accountId int64
buyerCreativeId string
opt_ map[string]interface{}
ctx_ context.Context
}

// Get: Gets the status for a single creative. A creative will be
Expand All @@ -661,6 +710,14 @@ func (c *CreativesGetCall) Fields(s ...googleapi.Field) *CreativesGetCall {
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.
func (c *CreativesGetCall) Context(ctx context.Context) *CreativesGetCall {
c.ctx_ = ctx
return c
}

func (c *CreativesGetCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
params := make(url.Values)
Expand All @@ -676,6 +733,9 @@ func (c *CreativesGetCall) doRequest(alt string) (*http.Response, error) {
"buyerCreativeId": c.buyerCreativeId,
})
req.Header.Set("User-Agent", c.s.userAgent())
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

Expand Down Expand Up @@ -733,6 +793,7 @@ type CreativesInsertCall struct {
s *Service
creative *Creative
opt_ map[string]interface{}
ctx_ context.Context
}

// Insert: Submit a new creative.
Expand All @@ -750,6 +811,14 @@ func (c *CreativesInsertCall) Fields(s ...googleapi.Field) *CreativesInsertCall
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.
func (c *CreativesInsertCall) Context(ctx context.Context) *CreativesInsertCall {
c.ctx_ = ctx
return c
}

func (c *CreativesInsertCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.creative)
Expand All @@ -768,6 +837,9 @@ func (c *CreativesInsertCall) doRequest(alt string) (*http.Response, error) {
googleapi.SetOpaque(req.URL)
req.Header.Set("Content-Type", ctype)
req.Header.Set("User-Agent", c.s.userAgent())
if c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

Expand Down Expand Up @@ -808,6 +880,7 @@ func (c *CreativesInsertCall) Do() (*Creative, error) {
type CreativesListCall struct {
s *Service
opt_ map[string]interface{}
ctx_ context.Context
}

// List: Retrieves a list of the authenticated user's active creatives.
Expand Down Expand Up @@ -854,6 +927,14 @@ func (c *CreativesListCall) Fields(s ...googleapi.Field) *CreativesListCall {
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.
func (c *CreativesListCall) Context(ctx context.Context) *CreativesListCall {
c.ctx_ = ctx
return c
}

func (c *CreativesListCall) doRequest(alt string) (*http.Response, error) {
var body io.Reader = nil
params := make(url.Values)
Expand All @@ -875,6 +956,9 @@ func (c *CreativesListCall) 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 c.ctx_ != nil {
return ctxhttp.Do(c.ctx_, c.s.client, req)
}
return c.s.client.Do(req)
}

Expand Down
Loading

0 comments on commit 77b0a8c

Please sign in to comment.