From e50b6827c8383dcd969ba0f35d413977de92f7d4 Mon Sep 17 00:00:00 2001
From: CrazyFrog <16268065+xnkjj@users.noreply.github.com>
Date: Mon, 21 Aug 2023 23:11:31 +0800
Subject: [PATCH] feat: delete examples
---
README.md | 86 +++++++++++-------
.../get_account_information.go | 37 --------
.../http_get_account_information.go | 41 ---------
.../http_list_accessible_customers.go | 32 -------
.../list_accessible_customers.go | 34 --------
.../get_campaigns_by_label.go | 44 ----------
.../http_get_campaigns_by_label.go | 44 ----------
examples/utils.go | 87 -------------------
8 files changed, 55 insertions(+), 350 deletions(-)
delete mode 100644 examples/account_management/get_account_information.go
delete mode 100644 examples/account_management/http_get_account_information.go
delete mode 100644 examples/account_management/http_list_accessible_customers.go
delete mode 100644 examples/account_management/list_accessible_customers.go
delete mode 100644 examples/campaign_management/get_campaigns_by_label.go
delete mode 100644 examples/campaign_management/http_get_campaigns_by_label.go
delete mode 100644 examples/utils.go
diff --git a/README.md b/README.md
index 0722aa71..f81d2e05 100644
--- a/README.md
+++ b/README.md
@@ -6,29 +6,30 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/shenzhencenter/google-ads-pb)](https://goreportcard.com/report/github.com/shenzhencenter/google-ads-pb)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
-This is a Golang client library for accessing the [Google Ads API](https://developers.google.com/google-ads/api/docs/start). Most of the code is generated from the [googleapis](https://github.com/googleapis/googleapis/tree/master/google/ads/googleads) repository. We only make some modifications and examples. Detailed informations can be found on [workflows/generator](https://github.com/shenzhencenter/google-ads-pb/blob/main/.github/workflows/generator.yml).
+This is a Golang client library for accessing the [Google Ads API](https://developers.google.com/google-ads/api/docs/start). The code is fully generated from the [googleapis](https://github.com/googleapis/googleapis/tree/master/google/ads/googleads) repository. Detailed informations can be found on [workflows/generator](https://github.com/shenzhencenter/google-ads-pb/blob/main/.github/workflows/generator.yml).
Please note that this is not an official project. But we think it is very low risk because it is a very mature project, and we have been using it in production for more than two years. The only thing to note is the [sunset schedule](https://developers.google.com/google-ads/api/docs/sunset-dates) of the Google Ads API.
## Features
- Fully support for Google Ads API.
+- Code is fully generated from the official googleapis repository.
- Support for GRPC calls.
- Support for HTTP calls by using [protojson](https://google.golang.org/protobuf/encoding/protojson).
-- Frequent updates based on [official repository](https://github.com/googleapis/googleapis).
+- Frequent updates based on [official repository](https://github.com/googleapis/googleapis). We are sorry that we will not update it frequently in the future, but we will continue to maintain it. The frequency of updates depends on our needs (abount later than the official release one month).
## Version support
-| google-ads-pb | Google Ads API | Sunset date |
-|---|---|---|
-| v1.5.1 | v14.1 | End of May 2024 |
-| v1.5.0 | v14 | End of May 2024 |
-| v1.4.1 | v13.1 | End of January 2024 |
-| v1.4.0 | v13 | End of January 2024 |
-| v1.3.1 | v12 | End of September 2023 |
-| v1.2.1 | v11.1 | Deprecated |
-| v1.2.0 | v11 | Deprecated |
-| v1.1.1 | v10 | Deprecated |
+| google-ads-pb | Google Ads API | Sunset date |
+| ----------------- | ---------------- | ---------------------------- |
+| v1.5.1 | v14.1 | End of May 2024 |
+| v1.5.0 | v14 | End of May 2024 |
+| v1.4.1 | v13.1 | End of January 2024 |
+| v1.4.0 | v13 | End of January 2024 |
+| v1.3.1 | v12 | End of September 2023 |
+| v1.2.1 | v11.1 | Deprecated |
+| v1.2.0 | v11 | Deprecated |
+| v1.1.1 | v10 | Deprecated |
## Requirements
@@ -66,7 +67,9 @@ ctx = metadata.NewOutgoingContext(ctx, headers)
cred := grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""))
conn, err := grpc.Dial("googleads.googleapis.com:443", cred)
-if err != nil { panic(err) }
+if err != nil {
+ panic(err)
+}
defer conn.Close()
```
@@ -78,27 +81,54 @@ accessibleCustomers, err := customerServiceClient.ListAccessibleCustomers(
ctx,
&services.ListAccessibleCustomersRequest{},
)
-if err != nil { panic(err) }
+if err != nil {
+ panic(err)
+}
for _, customer := range accessibleCustomers.ResourceNames {
fmt.Println("ResourceName: " + customer)
}
```
-4. Make HTTP calls with using [protojson](https://google.golang.org/protobuf/encoding/protojson) is not recommended now. But it is available yet, for more information please refer to the code in examples.
+4. Make HTTP calls with using [protojson](https://google.golang.org/protobuf/encoding/protojson) is not recommended now, but it is available yet.
+```go
+req := services.ListAccessibleCustomersRequest{}
+requestBody, err := protojson.Marshal(&req)
+if err != nil {
+ panic(err)
+}
+request, err := http.NewRequest("GET", "https://googleads.googleapis.com/v14/customers:listAccessibleCustomers", bytes.NewBuffer(requestBody))
+if err != nil {
+ panic(err)
+}
+header := make(http.Header)
+header.Set("content-type", "application/json")
+header.Set("authorization", os.Getenv("ACCESS_TOKEN"))
+header.Set("developer-token", os.Getenv("DEVELOPER_TOKEN"))
+request.Header = header
+client := &http.Client{}
+response, err := client.Do(request)
+if err != nil {
+ panic(err)
+}
+defer response.Body.Close()
+var responseBody []byte
+if responseBody, err = io.ReadAll(response.Body); err != nil {
+ panic(err)
+}
+listAccessibleCustomersResponse := new(services.ListAccessibleCustomersResponse)
+if err := protojson.Unmarshal(response, listAccessibleCustomersResponse); err != nil {
+ panic(err)
+}
+for _, customer := range listAccessibleCustomersResponse.ResourceNames {
+ fmt.Println("ResourceName: " + customer)
+}
+```
## Examples
-
-### Account management
-
-- ListAccessiableCustomer [[GRPC](https://github.com/shenzhencenter/google-ads-pb/blob/main/examples/account_management/list_accessible_customers.go)] [[HTTP](https://github.com/shenzhencenter/google-ads-pb/blob/main/examples/account_management/http_list_accessible_customers.go)]
-- GetAccountInformation [[GRPC](https://github.com/shenzhencenter/google-ads-pb/blob/main/examples/account_management/get_account_information.go)] [[HTTP](https://github.com/shenzhencenter/google-ads-pb/blob/main/examples/account_management/http_get_account_information.go)]
-
-### Campaign management
-
-- GetCampaignsByLabel [[GRPC](https://github.com/shenzhencenter/google-ads-pb/blob/main/examples/campaign_management/get_campaigns_by_label.go)] [[HTTP](https://github.com/shenzhencenter/google-ads-pb/blob/main/examples/campaign_management/http_get_campaigns_by_label.go)]
+See [clients/internal/snippets](https://github.com/shenzhencenter/google-ads-pb/tree/main/clients/internal/snippets).
## Related
@@ -109,10 +139,4 @@ Here are some related projects
## Contributing
-Welcome to contribute more examples and documentations.
-
-### Supporting
-
-If you like this project, please consider buying me a coffee. 😄
-
-
+This project is fully generated by protoc, so we can't accept pull requests. But we are very happy to receive your feedback and suggestions. Please feel free to create an issue.
diff --git a/examples/account_management/get_account_information.go b/examples/account_management/get_account_information.go
deleted file mode 100644
index 51f0f82f..00000000
--- a/examples/account_management/get_account_information.go
+++ /dev/null
@@ -1,37 +0,0 @@
-package account_management
-
-import (
- "context"
- "fmt"
- "os"
-
- "github.com/shenzhencenter/google-ads-pb/examples"
- "github.com/shenzhencenter/google-ads-pb/services"
- "google.golang.org/grpc"
-)
-
-func RunGRPCExample_GetAccountInformation() {
- conn := examples.GetGRPCConnection()
- defer conn.Close()
- ctx := examples.SetContext(context.Background(),
- examples.WithContext("authorization", os.Getenv("ACCESS_TOKEN")),
- examples.WithContext("developer-token", os.Getenv("DEVELOPER_TOKEN")),
- examples.WithContext("login-customer-id", os.Getenv("CUSTOMER_ID")),
- )
- GetAccountInformation(ctx, conn, os.Getenv("CUSTOMER_ID"))
-}
-
-func GetAccountInformation(ctx context.Context, conn *grpc.ClientConn, customerID string) {
- request := services.SearchGoogleAdsRequest{
- CustomerId: customerID,
- Query: "SELECT customer.descriptive_name FROM customer WHERE customer.id = " + customerID,
- }
- search, err := services.NewGoogleAdsServiceClient(conn).Search(ctx, &request)
- if err != nil {
- return
- }
-
- for _, resource := range search.Results {
- fmt.Println(resource.Customer.GetDescriptiveName())
- }
-}
diff --git a/examples/account_management/http_get_account_information.go b/examples/account_management/http_get_account_information.go
deleted file mode 100644
index f4902898..00000000
--- a/examples/account_management/http_get_account_information.go
+++ /dev/null
@@ -1,41 +0,0 @@
-package account_management
-
-import (
- "fmt"
- "os"
-
- "github.com/shenzhencenter/google-ads-pb/examples"
- "github.com/shenzhencenter/google-ads-pb/services"
- "google.golang.org/protobuf/encoding/protojson"
-)
-
-func RunHTTPExample_GetAccountInformation() {
- GetAccountInformation_HTTP(os.Getenv("CUSTOMER_ID"))
-}
-
-func GetAccountInformation_HTTP(customerID string) {
- searchGoogleAdsRequest := services.SearchGoogleAdsRequest{
- CustomerId: customerID,
- Query: "SELECT customer.descriptive_name FROM customer WHERE customer.id = " + customerID,
- }
- request, err := protojson.Marshal(&searchGoogleAdsRequest)
- if err != nil {
- panic(err)
- }
- searchGoogleAdsResponse := new(services.SearchGoogleAdsResponse)
-
- response := examples.HttpRequest(request,
- examples.GoogleAdsSearchMehtod,
- fmt.Sprintf(examples.GoogleAdsSearchPath, customerID),
- examples.WithHeader("authorization", os.Getenv("ACCESS_TOKEN")),
- examples.WithHeader("developer-token", os.Getenv("DEVELOPER_TOKEN")),
- examples.WithHeader("login-customer-id", os.Getenv("CUSTOMER_ID")),
- )
- if err := protojson.Unmarshal(response, searchGoogleAdsResponse); err != nil {
- panic(err)
- }
-
- for _, resource := range searchGoogleAdsResponse.Results {
- fmt.Println(resource.Customer.GetDescriptiveName())
- }
-}
diff --git a/examples/account_management/http_list_accessible_customers.go b/examples/account_management/http_list_accessible_customers.go
deleted file mode 100644
index 3965f239..00000000
--- a/examples/account_management/http_list_accessible_customers.go
+++ /dev/null
@@ -1,32 +0,0 @@
-package account_management
-
-import (
- "fmt"
- "os"
-
- "github.com/shenzhencenter/google-ads-pb/examples"
- "github.com/shenzhencenter/google-ads-pb/services"
- "google.golang.org/protobuf/encoding/protojson"
-)
-
-func RunHTTPExample_ListAccessibleCustomers() {
- ListAccessibleCustomers_HTTP()
-}
-
-func ListAccessibleCustomers_HTTP() {
- listAccessibleCustomersResponse := new(services.ListAccessibleCustomersResponse)
-
- response := examples.HttpRequest(nil,
- examples.ListAccessibleCustomersMehtod,
- examples.ListAccessibleCustomersPath,
- examples.WithHeader("authorization", os.Getenv("ACCESS_TOKEN")),
- examples.WithHeader("developer-token", os.Getenv("DEVELOPER_TOKEN")),
- )
- if err := protojson.Unmarshal(response, listAccessibleCustomersResponse); err != nil {
- panic(err)
- }
-
- for _, customer := range listAccessibleCustomersResponse.ResourceNames {
- fmt.Println("ResourceName: " + customer)
- }
-}
diff --git a/examples/account_management/list_accessible_customers.go b/examples/account_management/list_accessible_customers.go
deleted file mode 100644
index 5628185b..00000000
--- a/examples/account_management/list_accessible_customers.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package account_management
-
-import (
- "context"
- "fmt"
- "os"
-
- "github.com/shenzhencenter/google-ads-pb/examples"
- "github.com/shenzhencenter/google-ads-pb/services"
- "google.golang.org/grpc"
-)
-
-func RunGRPCExample_ListAccessibleCustomers() {
- conn := examples.GetGRPCConnection()
- defer conn.Close()
- ctx := examples.SetContext(context.Background(),
- examples.WithContext("authorization", os.Getenv("ACCESS_TOKEN")),
- examples.WithContext("developer-token", os.Getenv("DEVELOPER_TOKEN")),
- )
- ListAccessibleCustomers(ctx, conn)
-}
-
-func ListAccessibleCustomers(ctx context.Context, conn *grpc.ClientConn) {
- customers, err := services.NewCustomerServiceClient(conn).
- ListAccessibleCustomers(ctx, &services.ListAccessibleCustomersRequest{})
- if err != nil {
- fmt.Printf("%+#v", err.Error())
- return
- }
-
- for _, customer := range customers.ResourceNames {
- fmt.Println("ResourceName: " + customer)
- }
-}
diff --git a/examples/campaign_management/get_campaigns_by_label.go b/examples/campaign_management/get_campaigns_by_label.go
deleted file mode 100644
index b5759a7d..00000000
--- a/examples/campaign_management/get_campaigns_by_label.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package examples
-
-import (
- "context"
- "fmt"
- "os"
-
- "github.com/shenzhencenter/google-ads-pb/examples"
- "github.com/shenzhencenter/google-ads-pb/services"
- "google.golang.org/grpc"
-)
-
-const GAQL_GetCampaignsByLabel = `SELECT campaign.id, campaign.name, label.id, label.name FROM campaign_label WHERE label.id = '%s' ORDER BY campaign.id`
-
-const LabelID = "INSERT_LABEL_ID_HERE"
-
-func RunGRPCExample_GetCampaignsByLabel() {
- conn := examples.GetGRPCConnection()
- defer conn.Close()
- ctx := examples.SetContext(context.Background(),
- examples.WithContext("authorization", os.Getenv("ACCESS_TOKEN")),
- examples.WithContext("developer-token", os.Getenv("DEVELOPER_TOKEN")),
- examples.WithContext("login-customer-id", os.Getenv("CUSTOMER_ID")),
- )
- GetCampaignsByLabel(ctx, conn, os.Getenv("CUSTOMER_ID"), LabelID)
-}
-
-func GetCampaignsByLabel(ctx context.Context, conn *grpc.ClientConn, customerID string, labelID string) {
- request := services.SearchGoogleAdsRequest{
- CustomerId: customerID,
- Query: fmt.Sprintf(GAQL_GetCampaignsByLabel, labelID),
- }
- response, err := services.NewGoogleAdsServiceClient(conn).Search(ctx, &request)
- if err != nil {
- panic(err)
- }
-
- for _, resource := range response.Results {
- fmt.Printf("Campaign ID: %d\n", resource.Campaign.GetId())
- fmt.Printf("Campaign name: %s\n", resource.Campaign.GetName())
- fmt.Printf("Label ID: %d\n", resource.Label.GetId())
- fmt.Printf("Label name: %s\n", resource.Label.GetName())
- }
-}
diff --git a/examples/campaign_management/http_get_campaigns_by_label.go b/examples/campaign_management/http_get_campaigns_by_label.go
deleted file mode 100644
index b26ade58..00000000
--- a/examples/campaign_management/http_get_campaigns_by_label.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package examples
-
-import (
- "fmt"
- "os"
-
- "github.com/shenzhencenter/google-ads-pb/examples"
- "github.com/shenzhencenter/google-ads-pb/services"
- "google.golang.org/protobuf/encoding/protojson"
-)
-
-func RunHTTPExample_GetCampaignsByLabel() {
- GetCampaignsByLabel_HTTP(os.Getenv("CUSTOMER_ID"), LabelID)
-}
-
-func GetCampaignsByLabel_HTTP(customerID string, labelID string) {
- searchGoogleAdsRequest := services.SearchGoogleAdsRequest{
- CustomerId: customerID,
- Query: fmt.Sprintf(GAQL_GetCampaignsByLabel, labelID),
- }
- request, err := protojson.Marshal(&searchGoogleAdsRequest)
- if err != nil {
- panic(err)
- }
- searchGoogleAdsResponse := new(services.SearchGoogleAdsResponse)
-
- response := examples.HttpRequest(request,
- examples.GoogleAdsSearchMehtod,
- fmt.Sprintf(examples.GoogleAdsSearchPath, customerID),
- examples.WithHeader("authorization", os.Getenv("ACCESS_TOKEN")),
- examples.WithHeader("developer-token", os.Getenv("DEVELOPER_TOKEN")),
- examples.WithHeader("login-customer-id", os.Getenv("CUSTOMER_ID")),
- )
- if err := protojson.Unmarshal(response, searchGoogleAdsResponse); err != nil {
- panic(err)
- }
-
- for _, resource := range searchGoogleAdsResponse.Results {
- fmt.Printf("Campaign ID: %d\n", resource.Campaign.GetId())
- fmt.Printf("Campaign name: %s\n", resource.Campaign.GetName())
- fmt.Printf("Label ID: %d\n", resource.Label.GetId())
- fmt.Printf("Label name: %s\n", resource.Label.GetName())
- }
-}
diff --git a/examples/utils.go b/examples/utils.go
deleted file mode 100644
index 6fdb563f..00000000
--- a/examples/utils.go
+++ /dev/null
@@ -1,87 +0,0 @@
-package examples
-
-import (
- "bytes"
- "context"
- "io/ioutil"
- "net/http"
-
- "google.golang.org/grpc"
- "google.golang.org/grpc/credentials"
- "google.golang.org/grpc/metadata"
-)
-
-const (
- EndPoint = "googleads.googleapis.com:443"
- ListAccessibleCustomersMehtod = "GET"
- ListAccessibleCustomersPath = "https://googleads.googleapis.com/v12/customers:listAccessibleCustomers"
- GoogleAdsSearchMehtod = "POST"
- GoogleAdsSearchPath = "https://googleads.googleapis.com/v12/customers/%s/googleAds:search"
-)
-
-type (
- ContextOption func(*context.Context)
- HeaderOption func(header *http.Header)
-)
-
-var conn *grpc.ClientConn
-
-func GetGRPCConnection() *grpc.ClientConn {
- if conn != nil {
- return conn
- }
- cred := grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, ""))
- conn, err := grpc.Dial(EndPoint, cred)
- if err != nil {
- panic(err)
- }
- return conn
-}
-
-func WithContext(k string, v string) ContextOption {
- return func(ctx *context.Context) {
- *ctx = metadata.AppendToOutgoingContext(*ctx, k, v)
- }
-}
-
-func SetContext(ctx context.Context, opts ...ContextOption) context.Context {
- for _, opt := range opts {
- opt(&ctx)
- }
- return ctx
-}
-
-func WithHeader(k string, v string) HeaderOption {
- return func(header *http.Header) {
- header.Set(k, v)
- }
-}
-
-func HttpRequest(body []byte, method string, url string, opts ...HeaderOption) []byte {
- request, err := http.NewRequest(method, url, bytes.NewBuffer(body))
- if err != nil {
- panic(err)
- }
-
- header := make(http.Header)
- header.Set("content-type", "application/json")
- header.Set("accept", "application/json")
- for _, opt := range opts {
- opt(&header)
- }
- request.Header = header
-
- client := &http.Client{}
- response, err := client.Do(request)
- if err != nil {
- panic(err)
- }
- defer response.Body.Close()
-
- // 4.4 Read the response
- var responseBody []byte
- if responseBody, err = ioutil.ReadAll(response.Body); err != nil {
- panic(err)
- }
- return responseBody
-}