awql

package module
v0.0.0-...-bbec30a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2017 License: MIT Imports: 10 Imported by: 0

README

go-awql

Build Status GoDoc

A simple package to fetch AWQL query results. Currently only support querying against Adwords report, support for services will come later.

Usage

Import the package.

import github.com/habibrosyad/go-awql

Fill the authentication details.

auth := &awql.Auth{
	ClientId:       "your-client-id.apps.googleusercontent.com",
	ClientSecret:   "your-client-secret",
	RefreshToken:   "your-refresh-token",
	AccessToken:    "your-access-token",
	CustomerId:     "your-customer-id",
	DeveloperToken: "your-developer-token",
}

Create a new client.

client := awql.NewClient(auth)

Begin querying. This sample is for querying Adwords report.

rows, err := client.Query("SELECT Date, ActiveViewCtr FROM ACCOUNT_PERFORMANCE_REPORT DURING TODAY");
if err != nil {
	panic(err) // Can not continue, do error handling.
}

defer rows.Close()

for rows.Next() {
	row, err := rows.Scan()
	if err != nil {
		// Do error handling.
	}
	// Do anthing with the returned row.
	// Result is automatically mapped to its respective field in the AWQL definition.
	// E.g. to access the previous result you can use row["Date"] and row["ActiveViewCtr"].
}

The returned result from rows.Scan() is map[string]interface{}. To map the result into a struct you might want to use mapstructure. Key of the map is the same as the field used in the AWQL definition. For example, in the previous sample you can access the result as row["Date"] and row["ActiveViewCtr"].

Documentation

Overview

A simple package to fetch AWQL query results. Currently only support querying against Adwords report, support for services will come later.

Usage

Fill the authentication details.

auth := &awql.Auth{
	ClientId:       "your-client-id.apps.googleusercontent.com",
	ClientSecret:   "your-client-secret",
	RefreshToken:   "your-refresh-token",
	AccessToken:    "your-access-token",
	CustomerId:     "your-customer-id",
	DeveloperToken: "your-developer-token",
}

Create a new client.

client := awql.NewClient(auth)

Begin querying. This sample is for querying Adwords report.

rows, err := client.Query("SELECT Date, ActiveViewCtr FROM ACCOUNT_PERFORMANCE_REPORT DURING TODAY");
if err != nil {
	panic(err) // Can not continue, do error handling.
}

defer rows.Close()

for rows.Next() {
	row, err := rows.Scan()
	if err != nil {
		// Do error handling.
	}
	// Do anthing with the returned row.
	// Result is automatically mapped to its respective field in the AWQL definition.
	// E.g. to access the previous result you can use row["Date"] and row["ActiveViewCtr"].
}

Index

Constants

View Source
const (

	// Service types.
	AdGroupAdService                = "AdGroupAdService"
	AdGroupBidModifierService       = "AdGroupBidModifierService"
	AdGroupCriterionService         = "AdGroupCriterionService"
	AdGroupExtensionSettingService  = "AdGroupExtensionSettingService"
	AdGroupFeedService              = "AdGroupFeedService"
	AdGroupService                  = "AdGroupService"
	AdwordsUserListService          = "AdwordsUserListService"
	BatchJobService                 = "BatchJobService"
	BiddingStrategyService          = "BiddingStrategyService"
	BudgetService                   = "BudgetService"
	CampaignCriterionService        = "CampaignCriterionService"
	CampaignExtensionSettingService = "CampaignExtensionSettingService"
	CampaignFeedService             = "CampaignFeedService"
	CampaignService                 = "CampaignService"
	CampaignSharedSetService        = "CampaignSharedSetService"
	ConversionTrackerService        = "ConversionTrackerService"
	CustomerExtensionSettingService = "CustomerExtensionSettingService"
	CustomerFeedService             = "CustomerFeedService"
	DataService                     = "DataService"
	DraftAsyncErrorService          = "DraftAsyncErrorService"
	DraftService                    = "DraftService"
	FeedItemService                 = "FeedItemService"
	FeedMappingService              = "FeedMappingService"
	FeedService                     = "FeedService"
	LabelService                    = "LabelService"
	LocationCriterionService        = "LocationCriterionService"
	MediaService                    = "MediaService"
	SharedCriterionService          = "SharedCriterionService"
	SharedSetService                = "SharedSetService"
	TrialAsyncErrorService          = "TrialAsyncErrorService"
	TrialService                    = "TrialService"
)

Variables

View Source
var (
	ErrNoRows = errors.New("no more rows")
)

Functions

This section is empty.

Types

type Auth

type Auth struct {
	ClientId       string
	ClientSecret   string
	RefreshToken   string
	AccessToken    string
	CustomerId     string
	DeveloperToken string
}

Adwords auth configuration.

type Client

type Client struct {
	// contains filtered or unexported fields
}

HTTP client to post and get AWQL query.

func NewClient

func NewClient(auth *Auth) *Client

Create a new client based on the provided auth configuration.

func (*Client) Query

func (c *Client) Query(q string) (Rows, error)

Execute an AWQL query for a report.

func (*Client) QueryService

func (c *Client) QueryService(q, s string) (Rows, error)

Execute an AWQL query for a service.

type Rows

type Rows interface {
	Next() bool
	Scan() (map[string]interface{}, error)
	Close()
}

Iterator for query results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL