products_log 1.0.0
C++ client library for the Products REST API (usage statistics)
Loading...
Searching...
No Matches
products_log::ProductsLog Class Reference

#include <products_log.h>

Public Member Functions

 ProductsLog (std::string product_name, std::string product_version, Transport transport=DefaultTransport())
 
 ProductsLog (std::string product_name, std::string product_version, std::string base_url, std::string username, std::string password, Transport transport=DefaultTransport())
 
 ProductsLog (const ProductsLog &)=delete
 
ProductsLog & operator= (const ProductsLog &)=delete
 
 ~ProductsLog ()=default
 
bool enabled () const
 Активен ли клиент (все credentials заданы).
 
bool PostMessage (const std::string &comment)
 Отправить запись статистики. Возвращает false при любой ошибке.
 
bool PostStart ()
 Отправить "Program started".
 
bool PostShutdown ()
 Отправить "Program shutdown".
 

Private Member Functions

bool ResolveProductId ()
 
bool SendStat (int64_t product_id, const std::string &comment)
 
std::optional< int64_t > FindProductId ()
 
std::optional< int64_t > RegisterProduct ()
 

Static Private Member Functions

static Transport DefaultTransport ()
 
static std::string UrlEncode (const std::string &s)
 
static std::string JsonEscape (const std::string &s)
 
static std::optional< int64_t > ParseProductId (const std::string &body)
 

Private Attributes

std::string product_name_
 
std::string product_version_
 
std::string base_url_
 
std::string username_
 
std::string password_
 
bool enabled_ = false
 
std::optional< int64_t > product_id_
 
Transport transport_
 

Detailed Description

Клиент Products API.

При инициализации не обращается к сети: идентификатор продукта находится/регистрируется лениво, при первой отправке сообщения. Если PRODUCTS_HOST / PRODUCTS_USER / PRODUCTS_PASS не заданы (или переданы пустыми), клиент становится неактивным — все методы возвращают false и логируют предупреждение в stderr.

Definition at line 47 of file products_log.h.

Constructor & Destructor Documentation

◆ ProductsLog() [1/3]

products_log::ProductsLog::ProductsLog ( std::string product_name,
std::string product_version,
Transport transport = DefaultTransport() )
explicit

Конфигурация из переменных окружения PRODUCTS_HOST / PRODUCTS_USER / PRODUCTS_PASS. Версия продукта обычно приходит из PRODUCTS_VERSION.

Definition at line 101 of file products_log.cpp.

◆ ProductsLog() [2/3]

products_log::ProductsLog::ProductsLog ( std::string product_name,
std::string product_version,
std::string base_url,
std::string username,
std::string password,
Transport transport = DefaultTransport() )

Явная конфигурация (не зависит от окружения; используется в тестах). version и baseUrl могут быть пустыми — тогда включается запасной вариант: version="UNKNOWN", base_url из окружения.

Definition at line 107 of file products_log.cpp.

References base_url_, enabled_, password_, and username_.

◆ ProductsLog() [3/3]

products_log::ProductsLog::ProductsLog ( const ProductsLog & )
delete

◆ ~ProductsLog()

products_log::ProductsLog::~ProductsLog ( )
default

Member Function Documentation

◆ DefaultTransport()

Transport products_log::ProductsLog::DefaultTransport ( )
staticprivate

Definition at line 123 of file products_log.cpp.

◆ enabled()

bool products_log::ProductsLog::enabled ( ) const
inline

Активен ли клиент (все credentials заданы).

Definition at line 66 of file products_log.h.

References enabled_.

◆ FindProductId()

◆ JsonEscape()

std::string products_log::ProductsLog::JsonEscape ( const std::string & s)
staticprivate

Definition at line 146 of file products_log.cpp.

Referenced by RegisterProduct(), and SendStat().

◆ operator=()

ProductsLog & products_log::ProductsLog::operator= ( const ProductsLog & )
delete

◆ ParseProductId()

std::optional< int64_t > products_log::ProductsLog::ParseProductId ( const std::string & body)
staticprivate

Definition at line 183 of file products_log.cpp.

Referenced by FindProductId(), and RegisterProduct().

◆ PostMessage()

bool products_log::ProductsLog::PostMessage ( const std::string & comment)

Отправить запись статистики. Возвращает false при любой ошибке.

Definition at line 268 of file products_log.cpp.

References enabled_, product_id_, ResolveProductId(), and SendStat().

Referenced by PostShutdown(), and PostStart().

◆ PostShutdown()

bool products_log::ProductsLog::PostShutdown ( )

Отправить "Program shutdown".

Definition at line 276 of file products_log.cpp.

References PostMessage().

◆ PostStart()

bool products_log::ProductsLog::PostStart ( )

Отправить "Program started".

Definition at line 274 of file products_log.cpp.

References PostMessage().

◆ RegisterProduct()

◆ ResolveProductId()

bool products_log::ProductsLog::ResolveProductId ( )
private

Definition at line 217 of file products_log.cpp.

References FindProductId(), product_id_, and RegisterProduct().

Referenced by PostMessage().

◆ SendStat()

bool products_log::ProductsLog::SendStat ( int64_t product_id,
const std::string & comment )
private

◆ UrlEncode()

std::string products_log::ProductsLog::UrlEncode ( const std::string & s)
staticprivate

Definition at line 130 of file products_log.cpp.

Referenced by FindProductId().

Member Data Documentation

◆ base_url_

std::string products_log::ProductsLog::base_url_
private

Definition at line 88 of file products_log.h.

Referenced by FindProductId(), ProductsLog(), RegisterProduct(), and SendStat().

◆ enabled_

bool products_log::ProductsLog::enabled_ = false
private

Definition at line 91 of file products_log.h.

Referenced by enabled(), PostMessage(), and ProductsLog().

◆ password_

std::string products_log::ProductsLog::password_
private

Definition at line 90 of file products_log.h.

Referenced by FindProductId(), ProductsLog(), RegisterProduct(), and SendStat().

◆ product_id_

std::optional<int64_t> products_log::ProductsLog::product_id_
private

Definition at line 92 of file products_log.h.

Referenced by PostMessage(), and ResolveProductId().

◆ product_name_

std::string products_log::ProductsLog::product_name_
private

Definition at line 86 of file products_log.h.

Referenced by FindProductId(), and RegisterProduct().

◆ product_version_

std::string products_log::ProductsLog::product_version_
private

Definition at line 87 of file products_log.h.

Referenced by SendStat().

◆ transport_

Transport products_log::ProductsLog::transport_
private

Definition at line 93 of file products_log.h.

Referenced by FindProductId(), RegisterProduct(), and SendStat().

◆ username_

std::string products_log::ProductsLog::username_
private

Definition at line 89 of file products_log.h.

Referenced by FindProductId(), ProductsLog(), RegisterProduct(), and SendStat().


The documentation for this class was generated from the following files: