|
products_log 1.0.0
C++ client library for the Products REST API (usage statistics)
|
#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_ |
Клиент Products API.
При инициализации не обращается к сети: идентификатор продукта находится/регистрируется лениво, при первой отправке сообщения. Если PRODUCTS_HOST / PRODUCTS_USER / PRODUCTS_PASS не заданы (или переданы пустыми), клиент становится неактивным — все методы возвращают false и логируют предупреждение в stderr.
Definition at line 47 of file products_log.h.
|
explicit |
Конфигурация из переменных окружения PRODUCTS_HOST / PRODUCTS_USER / PRODUCTS_PASS. Версия продукта обычно приходит из PRODUCTS_VERSION.
Definition at line 101 of file products_log.cpp.
| 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() ) |
|
delete |
|
default |
|
staticprivate |
Definition at line 123 of file products_log.cpp.
|
inline |
Активен ли клиент (все credentials заданы).
Definition at line 66 of file products_log.h.
References enabled_.
|
private |
Definition at line 278 of file products_log.cpp.
References base_url_, products_log::HttpResponse::body, products_log::HttpResponse::error, products_log::HttpRequest::method, products_log::HttpResponse::ok, ParseProductId(), password_, product_name_, products_log::HttpResponse::status, transport_, UrlEncode(), and username_.
Referenced by ResolveProductId().
|
staticprivate |
Definition at line 146 of file products_log.cpp.
Referenced by RegisterProduct(), and SendStat().
|
delete |
|
staticprivate |
Definition at line 183 of file products_log.cpp.
Referenced by FindProductId(), and RegisterProduct().
| 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().
| bool products_log::ProductsLog::PostShutdown | ( | ) |
Отправить "Program shutdown".
Definition at line 276 of file products_log.cpp.
References PostMessage().
| bool products_log::ProductsLog::PostStart | ( | ) |
Отправить "Program started".
Definition at line 274 of file products_log.cpp.
References PostMessage().
|
private |
Definition at line 305 of file products_log.cpp.
References base_url_, products_log::HttpResponse::body, products_log::HttpResponse::error, JsonEscape(), products_log::HttpRequest::method, products_log::HttpResponse::ok, ParseProductId(), password_, product_name_, products_log::HttpResponse::status, transport_, and username_.
Referenced by ResolveProductId().
|
private |
Definition at line 217 of file products_log.cpp.
References FindProductId(), product_id_, and RegisterProduct().
Referenced by PostMessage().
|
private |
Definition at line 232 of file products_log.cpp.
References base_url_, products_log::HttpResponse::error, JsonEscape(), products_log::HttpRequest::method, products_log::HttpResponse::ok, password_, product_version_, products_log::HttpResponse::status, transport_, and username_.
Referenced by PostMessage().
|
staticprivate |
Definition at line 130 of file products_log.cpp.
Referenced by FindProductId().
|
private |
Definition at line 88 of file products_log.h.
Referenced by FindProductId(), ProductsLog(), RegisterProduct(), and SendStat().
|
private |
Definition at line 91 of file products_log.h.
Referenced by enabled(), PostMessage(), and ProductsLog().
|
private |
Definition at line 90 of file products_log.h.
Referenced by FindProductId(), ProductsLog(), RegisterProduct(), and SendStat().
|
private |
Definition at line 92 of file products_log.h.
Referenced by PostMessage(), and ResolveProductId().
|
private |
Definition at line 86 of file products_log.h.
Referenced by FindProductId(), and RegisterProduct().
|
private |
Definition at line 87 of file products_log.h.
Referenced by SendStat().
|
private |
Definition at line 93 of file products_log.h.
Referenced by FindProductId(), RegisterProduct(), and SendStat().
|
private |
Definition at line 89 of file products_log.h.
Referenced by FindProductId(), ProductsLog(), RegisterProduct(), and SendStat().