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: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BaseURL is the base URL for Yandex.Metrika API requests.
	APIBaseURL = "https://api.appmetrica.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 AppService

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

func (*AppService) Get

func (s *AppService) Get(counter int) (*AppsResponse, error)

func (*AppService) GetWithContext

func (s *AppService) GetWithContext(ctx context.Context, counter int) (*AppsResponse, error)

type AppsResponse

type AppsResponse struct {
	Data []AppsResponseEntry `json:"applications"` // Data is a list of goal entries.
}

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

func (*AppsResponse) Batch

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

Batch creates a service.MessageBatch from the GoalsResponse.

type AppsResponseEntry

type AppsResponseEntry struct {
	Id    uint64 `json:"id"`    // Id is the unique identifier of the goal.
	Name  string `json:"name"`  // Name is the name of the goal.
	Label string `json:"label"` // Label is name of the folder where the application is located in the web interface.
}

GoalsResponseEntry represents a single goal entry in a GoalsResponse.

type Client

type Client struct {
	App       *AppService
	StatTable *StatTableService
	// contains filtered or unexported fields
}

Client is a wrapper around req.Client for interacting with the Yandex.AppMetrika 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 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.
	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.
	Accuracy     string   `json:"accuracy,omitempty" url:"accuracy,omitempty"`                               // Accuracy is a sample size for the report.
	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