...

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

Documentation: google.golang.org/api/androidpublisher/v1.1

     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 androidpublisher provides access to the Google Play Developer API.
     8  //
     9  // For product documentation, see: https://developers.google.com/android-publisher
    10  //
    11  // # Creating a client
    12  //
    13  // Usage example:
    14  //
    15  //	import "google.golang.org/api/androidpublisher/v1.1"
    16  //	...
    17  //	ctx := context.Background()
    18  //	androidpublisherService, err := androidpublisher.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  // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
    27  //
    28  //	androidpublisherService, err := androidpublisher.NewService(ctx, option.WithAPIKey("AIza..."))
    29  //
    30  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
    31  //
    32  //	config := &oauth2.Config{...}
    33  //	// ...
    34  //	token, err := config.Exchange(ctx, ...)
    35  //	androidpublisherService, err := androidpublisher.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    36  //
    37  // See https://godoc.org/google.golang.org/api/option/ for details on options.
    38  package androidpublisher // import "google.golang.org/api/androidpublisher/v1.1"
    39  
    40  import (
    41  	"bytes"
    42  	"context"
    43  	"encoding/json"
    44  	"errors"
    45  	"fmt"
    46  	"io"
    47  	"net/http"
    48  	"net/url"
    49  	"strconv"
    50  	"strings"
    51  
    52  	googleapi "google.golang.org/api/googleapi"
    53  	gensupport "google.golang.org/api/internal/gensupport"
    54  	option "google.golang.org/api/option"
    55  	internaloption "google.golang.org/api/option/internaloption"
    56  	htransport "google.golang.org/api/transport/http"
    57  )
    58  
    59  // Always reference these packages, just in case the auto-generated code
    60  // below doesn't.
    61  var _ = bytes.NewBuffer
    62  var _ = strconv.Itoa
    63  var _ = fmt.Sprintf
    64  var _ = json.NewDecoder
    65  var _ = io.Copy
    66  var _ = url.Parse
    67  var _ = gensupport.MarshalJSON
    68  var _ = googleapi.Version
    69  var _ = errors.New
    70  var _ = strings.Replace
    71  var _ = context.Canceled
    72  var _ = internaloption.WithDefaultEndpoint
    73  
    74  const apiId = "androidpublisher:v1.1"
    75  const apiName = "androidpublisher"
    76  const apiVersion = "v1.1"
    77  const basePath = "https://www.googleapis.com/androidpublisher/v1.1/applications/"
    78  
    79  // OAuth2 scopes used by this API.
    80  const (
    81  	// View and manage your Google Play Developer account
    82  	AndroidpublisherScope = "https://www.googleapis.com/auth/androidpublisher"
    83  )
    84  
    85  // NewService creates a new Service.
    86  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
    87  	scopesOption := option.WithScopes(
    88  		"https://www.googleapis.com/auth/androidpublisher",
    89  	)
    90  	// NOTE: prepend, so we don't override user-specified scopes.
    91  	opts = append([]option.ClientOption{scopesOption}, opts...)
    92  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
    93  	client, endpoint, err := htransport.NewClient(ctx, opts...)
    94  	if err != nil {
    95  		return nil, err
    96  	}
    97  	s, err := New(client)
    98  	if err != nil {
    99  		return nil, err
   100  	}
   101  	if endpoint != "" {
   102  		s.BasePath = endpoint
   103  	}
   104  	return s, nil
   105  }
   106  
   107  // New creates a new Service. It uses the provided http.Client for requests.
   108  //
   109  // Deprecated: please use NewService instead.
   110  // To provide a custom HTTP client, use option.WithHTTPClient.
   111  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   112  func New(client *http.Client) (*Service, error) {
   113  	if client == nil {
   114  		return nil, errors.New("client is nil")
   115  	}
   116  	s := &Service{client: client, BasePath: basePath}
   117  	s.Inapppurchases = NewInapppurchasesService(s)
   118  	return s, nil
   119  }
   120  
   121  type Service struct {
   122  	client    *http.Client
   123  	BasePath  string // API endpoint base URL
   124  	UserAgent string // optional additional User-Agent fragment
   125  
   126  	Inapppurchases *InapppurchasesService
   127  }
   128  
   129  func (s *Service) userAgent() string {
   130  	if s.UserAgent == "" {
   131  		return googleapi.UserAgent
   132  	}
   133  	return googleapi.UserAgent + " " + s.UserAgent
   134  }
   135  
   136  func NewInapppurchasesService(s *Service) *InapppurchasesService {
   137  	rs := &InapppurchasesService{s: s}
   138  	return rs
   139  }
   140  
   141  type InapppurchasesService struct {
   142  	s *Service
   143  }
   144  
   145  // InappPurchase: An InappPurchase resource indicates the status of a
   146  // user's inapp product purchase.
   147  type InappPurchase struct {
   148  	// ConsumptionState: The consumption state of the inapp product.
   149  	// Possible values are:
   150  	// - Yet to be consumed
   151  	// - Consumed
   152  	ConsumptionState int64 `json:"consumptionState,omitempty"`
   153  
   154  	// DeveloperPayload: A developer-specified string that contains
   155  	// supplemental information about an order.
   156  	DeveloperPayload string `json:"developerPayload,omitempty"`
   157  
   158  	// Kind: This kind represents an inappPurchase object in the
   159  	// androidpublisher service.
   160  	Kind string `json:"kind,omitempty"`
   161  
   162  	// OrderId: The order id associated with the purchase of the inapp
   163  	// product.
   164  	OrderId string `json:"orderId,omitempty"`
   165  
   166  	// PurchaseState: The purchase state of the order. Possible values are:
   167  	//
   168  	// - Purchased
   169  	// - Canceled
   170  	// - Pending
   171  	PurchaseState int64 `json:"purchaseState,omitempty"`
   172  
   173  	// PurchaseTime: The time the product was purchased, in milliseconds
   174  	// since the epoch (Jan 1, 1970).
   175  	PurchaseTime int64 `json:"purchaseTime,omitempty,string"`
   176  
   177  	// PurchaseType: The type of purchase of the inapp product. This field
   178  	// is only set if this purchase was not made using the standard in-app
   179  	// billing flow. Possible values are:
   180  	// - Test (i.e. purchased from a license testing account)
   181  	// - Promo (i.e. purchased using a promo code)
   182  	// - Rewarded (i.e. from watching a video ad instead of paying)
   183  	PurchaseType *int64 `json:"purchaseType,omitempty"`
   184  
   185  	// ServerResponse contains the HTTP response code and headers from the
   186  	// server.
   187  	googleapi.ServerResponse `json:"-"`
   188  
   189  	// ForceSendFields is a list of field names (e.g. "ConsumptionState") to
   190  	// unconditionally include in API requests. By default, fields with
   191  	// empty values are omitted from API requests. However, any non-pointer,
   192  	// non-interface field appearing in ForceSendFields will be sent to the
   193  	// server regardless of whether the field is empty or not. This may be
   194  	// used to include empty fields in Patch requests.
   195  	ForceSendFields []string `json:"-"`
   196  
   197  	// NullFields is a list of field names (e.g. "ConsumptionState") to
   198  	// include in API requests with the JSON null value. By default, fields
   199  	// with empty values are omitted from API requests. However, any field
   200  	// with an empty value appearing in NullFields will be sent to the
   201  	// server as null. It is an error if a field in this list has a
   202  	// non-empty value. This may be used to include null fields in Patch
   203  	// requests.
   204  	NullFields []string `json:"-"`
   205  }
   206  
   207  func (s *InappPurchase) MarshalJSON() ([]byte, error) {
   208  	type NoMethod InappPurchase
   209  	raw := NoMethod(*s)
   210  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   211  }
   212  
   213  // method id "androidpublisher.inapppurchases.get":
   214  
   215  type InapppurchasesGetCall struct {
   216  	s            *Service
   217  	packageName  string
   218  	productId    string
   219  	token        string
   220  	urlParams_   gensupport.URLParams
   221  	ifNoneMatch_ string
   222  	ctx_         context.Context
   223  	header_      http.Header
   224  }
   225  
   226  // Get: Checks the purchase and consumption status of an inapp item.
   227  func (r *InapppurchasesService) Get(packageName string, productId string, token string) *InapppurchasesGetCall {
   228  	c := &InapppurchasesGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   229  	c.packageName = packageName
   230  	c.productId = productId
   231  	c.token = token
   232  	return c
   233  }
   234  
   235  // Fields allows partial responses to be retrieved. See
   236  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
   237  // for more information.
   238  func (c *InapppurchasesGetCall) Fields(s ...googleapi.Field) *InapppurchasesGetCall {
   239  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   240  	return c
   241  }
   242  
   243  // IfNoneMatch sets the optional parameter which makes the operation
   244  // fail if the object's ETag matches the given value. This is useful for
   245  // getting updates only after the object has changed since the last
   246  // request. Use googleapi.IsNotModified to check whether the response
   247  // error from Do is the result of In-None-Match.
   248  func (c *InapppurchasesGetCall) IfNoneMatch(entityTag string) *InapppurchasesGetCall {
   249  	c.ifNoneMatch_ = entityTag
   250  	return c
   251  }
   252  
   253  // Context sets the context to be used in this call's Do method. Any
   254  // pending HTTP request will be aborted if the provided context is
   255  // canceled.
   256  func (c *InapppurchasesGetCall) Context(ctx context.Context) *InapppurchasesGetCall {
   257  	c.ctx_ = ctx
   258  	return c
   259  }
   260  
   261  // Header returns an http.Header that can be modified by the caller to
   262  // add HTTP headers to the request.
   263  func (c *InapppurchasesGetCall) Header() http.Header {
   264  	if c.header_ == nil {
   265  		c.header_ = make(http.Header)
   266  	}
   267  	return c.header_
   268  }
   269  
   270  func (c *InapppurchasesGetCall) doRequest(alt string) (*http.Response, error) {
   271  	reqHeaders := make(http.Header)
   272  	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20200627")
   273  	for k, v := range c.header_ {
   274  		reqHeaders[k] = v
   275  	}
   276  	reqHeaders.Set("User-Agent", c.s.userAgent())
   277  	if c.ifNoneMatch_ != "" {
   278  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   279  	}
   280  	var body io.Reader = nil
   281  	c.urlParams_.Set("alt", alt)
   282  	c.urlParams_.Set("prettyPrint", "false")
   283  	urls := googleapi.ResolveRelative(c.s.BasePath, "{packageName}/inapp/{productId}/purchases/{token}")
   284  	urls += "?" + c.urlParams_.Encode()
   285  	req, err := http.NewRequest("GET", urls, body)
   286  	if err != nil {
   287  		return nil, err
   288  	}
   289  	req.Header = reqHeaders
   290  	googleapi.Expand(req.URL, map[string]string{
   291  		"packageName": c.packageName,
   292  		"productId":   c.productId,
   293  		"token":       c.token,
   294  	})
   295  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   296  }
   297  
   298  // Do executes the "androidpublisher.inapppurchases.get" call.
   299  // Exactly one of *InappPurchase or error will be non-nil. Any non-2xx
   300  // status code is an error. Response headers are in either
   301  // *InappPurchase.ServerResponse.Header or (if a response was returned
   302  // at all) in error.(*googleapi.Error).Header. Use
   303  // googleapi.IsNotModified to check whether the returned error was
   304  // because http.StatusNotModified was returned.
   305  func (c *InapppurchasesGetCall) Do(opts ...googleapi.CallOption) (*InappPurchase, error) {
   306  	gensupport.SetOptions(c.urlParams_, opts...)
   307  	res, err := c.doRequest("json")
   308  	if res != nil && res.StatusCode == http.StatusNotModified {
   309  		if res.Body != nil {
   310  			res.Body.Close()
   311  		}
   312  		return nil, &googleapi.Error{
   313  			Code:   res.StatusCode,
   314  			Header: res.Header,
   315  		}
   316  	}
   317  	if err != nil {
   318  		return nil, err
   319  	}
   320  	defer googleapi.CloseBody(res)
   321  	if err := googleapi.CheckResponse(res); err != nil {
   322  		return nil, err
   323  	}
   324  	ret := &InappPurchase{
   325  		ServerResponse: googleapi.ServerResponse{
   326  			Header:         res.Header,
   327  			HTTPStatusCode: res.StatusCode,
   328  		},
   329  	}
   330  	target := &ret
   331  	if err := gensupport.DecodeResponse(target, res); err != nil {
   332  		return nil, err
   333  	}
   334  	return ret, nil
   335  	// {
   336  	//   "description": "Checks the purchase and consumption status of an inapp item.",
   337  	//   "httpMethod": "GET",
   338  	//   "id": "androidpublisher.inapppurchases.get",
   339  	//   "parameterOrder": [
   340  	//     "packageName",
   341  	//     "productId",
   342  	//     "token"
   343  	//   ],
   344  	//   "parameters": {
   345  	//     "packageName": {
   346  	//       "description": "The package name of the application the inapp product was sold in (for example, 'com.some.thing').",
   347  	//       "location": "path",
   348  	//       "required": true,
   349  	//       "type": "string"
   350  	//     },
   351  	//     "productId": {
   352  	//       "description": "The inapp product SKU (for example, 'com.some.thing.inapp1').",
   353  	//       "location": "path",
   354  	//       "required": true,
   355  	//       "type": "string"
   356  	//     },
   357  	//     "token": {
   358  	//       "description": "The token provided to the user's device when the inapp product was purchased.",
   359  	//       "location": "path",
   360  	//       "required": true,
   361  	//       "type": "string"
   362  	//     }
   363  	//   },
   364  	//   "path": "{packageName}/inapp/{productId}/purchases/{token}",
   365  	//   "response": {
   366  	//     "$ref": "InappPurchase"
   367  	//   },
   368  	//   "scopes": [
   369  	//     "https://www.googleapis.com/auth/androidpublisher"
   370  	//   ]
   371  	// }
   372  
   373  }
   374  

View as plain text