api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BaseURL is the base URL for Yandex.Metrika API requests.
	APIBaseURL = "https://api-metrika.yandex.ru"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    int    `json:"code"`    // Code is the error code.
	Message string `json:"message"` // Message is a human-readable error message.
	Reasons []struct {
		ErrorType string `json:"error_type"` // ErrorType specifies the type of error.
		Message   string `json:"message"`    // Message is a more detailed error message.
		Location  string `json:"location"`   // Location specifies where the error occurred.
	} `json:"errors"` // Reasons is a list of error details.
}

APIError API error object. Source: https://yandex.ru/dev/metrika/doc/api2/management/concept/errors.html#errors__resp

func (APIError) Error

func (e APIError) Error() string

Error returns a string representation of the API error.

func (*APIError) LogValue

func (e *APIError) LogValue() slog.Value

LogValue returns a slog.Value representation of the API error.

type Client

type Client struct {
	Goal       *GoalService
	StatTable  *StatTableService
	LogRequest *LogRequestService
	// contains filtered or unexported fields
}

Client is a wrapper around req.Client for interacting with the Yandex.Metrika API. It provides methods for creating and sending API requests, handling errors, and managing authentication.

func NewClient

func NewClient(kind, version, token string, logger *service.Logger) *Client

NewClient creates a new req.Client configured for interacting with the Yandex.Metrika API. It sets the base URL, common error result, retry policy, logging, and authentication.

func (*Client) R

func (c *Client) R() *req.Request

R creates and returns a new req.Request instance. This method is a convenient way to start building a new API request with the pre-configured client settings, such as base URL, authentication, retry policy, and error handling.

type EvalLogRequestResponse

type EvalLogRequestResponse struct {
	Result EvalLogRequestResponseEntry `json:"log_request_evaluation"` // Result contains the evaluation result.
}

EvalLogRequestResponse represents the response for evaluating a log request.

type EvalLogRequestResponseEntry

type EvalLogRequestResponseEntry struct {
	IsPossible bool `json:"possible"`                  // IsPossible indicates whether the log request is possible.
	MaxDays    int  `json:"max_possible_day_quantity"` // MaxDays is the maximum number of days for which logs can be requested.
}

EvalLogRequestResponseEntry represents a log request evaluation entry.

type GoalService

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

func (*GoalService) Get

func (s *GoalService) Get(counter int) (*GoalsResponse, error)

func (*GoalService) GetWithContext

func (s *GoalService) GetWithContext(ctx context.Context, counter int) (*GoalsResponse, error)

type GoalsResponse

type GoalsResponse struct {
	Data []GoalsResponseEntry `json:"goals"` // Data is a list of goal entries.
}

GoalsResponse represents a response containing a list of goals from the Yandex.Metrika API.

func (*GoalsResponse) Batch

func (r *GoalsResponse) Batch() (service.MessageBatch, error)

Batch creates a service.MessageBatch from the GoalsResponse.

type GoalsResponseEntry

type GoalsResponseEntry struct {
	Id         uint64               `json:"id"`                      // Id is the unique identifier of the goal.
	PrevID     uint64               `json:"prev_goal_id,omitempty"`  // PrevID is the ID of the previous goal.
	Name       string               `json:"name"`                    // Name is the name of the goal.
	Type       string               `json:"type"`                    // Type is the type of the goal.
	Source     string               `json:"goal_source"`             // Source is the source of the goal.
	Price      float64              `json:"default_price,omitempty"` // Price is the default price associated with the goal.
	Flag       string               `json:"flag,omitempty"`          // Flag is an optional flag associated with the goal.
	IsFavorite int                  `json:"is_favorite"`             // IsFavorite indicates whether the goal is a favorite.
	IsRetarget int                  `json:"is_retargeting"`          // IsRetarget indicates whether the goal is for retargeting.
	Steps      []GoalsResponseEntry `json:"steps,omitempty"`         // Steps is a list of steps associated with the goal.
	Conditions []map[string]string  `json:"conditions,omitempty"`    // Conditions is a list of conditions associated with the goal.
}

GoalsResponseEntry represents a single goal entry in a GoalsResponse.

type LogRequestQuery

type LogRequestQuery struct {
	Source      string   `json:"source" url:"source"`                               // Source specifies the source of the logs.
	Date1       string   `json:"date1" url:"date1"`                                 // Date1 is the start date for the log request in YYYY-MM-DD format.
	Date2       string   `json:"date2" url:"date2"`                                 // Date2 is the end date for the log request in YYYY-MM-DD format.
	Fields      []string `json:"fields" url:"fields,comma"`                         // Fields is a list of fields to include in the log request.
	Attribution string   `json:"attribution,omitempty" url:"attribution,omitempty"` // Attribution specifies the attribution model.
}

LogRequestQuery represents a query for requesting logs from the Yandex.Metrika API.

type LogRequestResponse

type LogRequestResponse struct {
	Request LogRequestResponseEntry `json:"log_request"` // Request contains the log request details.
}

LogRequestResponse represents the response for creating or retrieving a log request.

type LogRequestResponseEntry

type LogRequestResponseEntry struct {
	LogRequestQuery
	RequestID uint64 `json:"request_id"` // RequestID is the ID of the log request.
	CounterID uint64 `json:"counter_id"` // CounterID is the ID of the counter associated with the log request.
	Status    string `json:"status"`     // Status is the status of the log request.
	Size      uint64 `json:"size"`       // Size is the size of the log request.
	Parts     []struct {
		Number int    `json:"part_number"` // Num is the part number.
		Size   uint64 `json:"size"`        // Size is the size of the part.
	} // Parts is a list of parts of the log request.
}

LogRequestResponseEntry represents a log request entry.

type LogRequestService

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

func (*LogRequestService) Cancel

func (s *LogRequestService) Cancel(counter int, request uint64) (*LogRequestResponse, error)

func (*LogRequestService) CancelWithContext

func (s *LogRequestService) CancelWithContext(ctx context.Context, counter int, request uint64) (*LogRequestResponse, error)

func (*LogRequestService) Clean

func (s *LogRequestService) Clean(counter int, request uint64) (*LogRequestResponse, error)

func (*LogRequestService) CleanWithContext

func (s *LogRequestService) CleanWithContext(ctx context.Context, counter int, request uint64) (*LogRequestResponse, error)

func (*LogRequestService) Create

func (s *LogRequestService) Create(counter int, q *LogRequestQuery) (*LogRequestResponse, error)

func (*LogRequestService) CreateWithContext

func (s *LogRequestService) CreateWithContext(ctx context.Context, counter int, q *LogRequestQuery) (*LogRequestResponse, error)

func (*LogRequestService) Download

func (s *LogRequestService) Download(counter int, request uint64, part int) (io.ReadCloser, error)

func (*LogRequestService) DownloadWithContext

func (s *LogRequestService) DownloadWithContext(ctx context.Context, counter int, request uint64, part int) (io.ReadCloser, error)

func (*LogRequestService) Eval

func (*LogRequestService) EvalWithContext

func (s *LogRequestService) EvalWithContext(ctx context.Context, counter int, q *LogRequestQuery) (*EvalLogRequestResponse, error)

func (*LogRequestService) Get

func (s *LogRequestService) Get(counter int, request uint64) (*LogRequestResponse, error)

func (*LogRequestService) GetWithContext

func (s *LogRequestService) GetWithContext(ctx context.Context, counter int, request uint64) (*LogRequestResponse, error)

type StatTableQuery

type StatTableQuery struct {
	IDs          []int    `json:"ids" url:"ids,comma"`                                                       // IDs is a list of counter IDs.
	Date1        string   `json:"date1,omitempty" url:"date1,omitempty"`                                     // Date1 is the start date of the data range.
	Date2        string   `json:"date2,omitempty" url:"date2,omitempty"`                                     // Date2 is the end date of the data range.
	Dimensions   []string `json:"dimensions,omitempty" url:"dimensions,comma,omitempty"`                     // Dimensions is a list of dimensions for data breakdown.
	Metrics      []string `json:"metrics,omitempty" url:"metrics,comma,omitempty"`                           // Metrics is a list of metrics to be fetched.
	Sort         []string `json:"sort,omitempty" url:"sort,comma,omitempty"`                                 // Sort is a list of fields to sort the data by.
	Accuracy     string   `json:"accuracy,omitempty" url:"accuracy,omitempty"`                               // Accuracy is a sample size for the report.
	Limit        int      `json:"limit,omitempty" url:"limit,omitempty"`                                     // Limit is the maximum number of rows to return.
	Offset       int      `json:"offset,omitempty" url:"offset,omitempty"`                                   // Offset is the offset of the first row to return.
	Filters      string   `json:"filters,omitempty" url:"filters,omitempty"`                                 // Filters is a filter string to apply to the data.
	Lang         string   `json:"lang,omitempty" url:"lang,omitempty"`                                       // Lang is the language for the response.
	Preset       string   `json:"preset,omitempty" url:"preset,omitempty"`                                   // Preset is the preset used for the query.
	Timezone     string   `json:"timezone,omitempty" url:"timezone,omitempty"`                               // Timezone is the timezone to use for the data.
	DirectLogins []string `json:"direct_client_logins,omitempty" url:"direct_client_logins,comma,omitempty"` // DirectLogins is a list of direct client logins.
}

StatTableQuery represents a query for fetching data from Yandex.Metrika API stat tables.

type StatTableResponse

type StatTableResponse struct {
	Query     *StatTableQuery          `json:"query"`      // Query contains the query parameters used to fetch this data.
	Data      []StatTableResponseEntry `json:"data"`       // Data contains the actual data returned by the query.
	TotalRows int                      `json:"total_rows"` // TotalRows is the total number of rows matching the query.
}

StatTableResponse represents the response from a stat table query.

func (*StatTableResponse) Batch

Batch creates a service.MessageBatch from the StatTableResponse.

type StatTableResponseEntry

type StatTableResponseEntry struct {
	Dimensions []struct {
		Name string `json:"name"`         // Name is the name of the dimension.
		Id   string `json:"id,omitempty"` // Id is the optional ID of the dimension.
	} `json:"dimensions"` // Dimensions is a list of dimensions for this row.
	Metrics []float64 `json:"metrics"` // Metrics is a list of metrics for this row.
}

StatTableResponseEntry represents a single row in the stat table data.

type StatTableService

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

func (*StatTableService) Get

func (*StatTableService) GetWithContext

func (s *StatTableService) GetWithContext(ctx context.Context, q *StatTableQuery) (*StatTableResponse, error)

Jump to

Keyboard shortcuts

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