|
1 | 1 | #include <iostream> |
2 | | -#include "netlicensing/context.h" |
3 | | -#include "netlicensing/service.h" |
4 | | -#include "netlicensing/exception.h" |
5 | | -#include "netlicensing/product.h" |
6 | | -#include "json/json.h" |
| 2 | +#include <random> |
| 3 | +#include <ctime> |
| 4 | +#include <sstream> |
| 5 | +#include "netlicensing/netlicensing.h" |
7 | 6 |
|
8 | 7 | int main(int argc, char* argv[]) { |
9 | 8 | using netlicensing::Product; |
10 | 9 | std::string license_number = "I2C3VN7NA-DEMO"; |
11 | 10 | if (argc > 1) { |
12 | 11 | license_number = argv[1]; |
13 | 12 | } |
14 | | - std::cout << "Hello, this is NetLicensing demo client\n"; |
15 | 13 |
|
16 | | - std::cout << "Product endpoint " << netlicensing::endpoint<Product>() << std::endl; |
| 14 | + std::mt19937 gen; |
| 15 | + gen.seed(time(0)); |
| 16 | + std::stringstream ss; |
| 17 | + ss << "P" << gen(); |
| 18 | + std::string productNumber = ss.str(); |
17 | 19 |
|
18 | | - // check context direct call |
19 | | - std::list<std::pair<std::string, std::string> > params; |
20 | | - params.push_back(std::make_pair("licenseeNumber", "1")); |
21 | | - params.push_back(std::make_pair("licenseTemplateNumber", "1")); |
22 | | - params.push_back(std::make_pair("active", "true")); |
23 | | - params.push_back(std::make_pair("number", "1")); |
24 | | - params.push_back(std::make_pair("name", "lic")); |
| 20 | + std::cout << "Hello, this is NetLicensing demo client\n"; |
| 21 | + std::cout << "Product endpoint " << netlicensing::endpoint<Product>() << std::endl; |
| 22 | + std::cout << "Product test number " << productNumber << std::endl; |
25 | 23 |
|
26 | 24 | using netlicensing::Context; |
27 | 25 | try { |
28 | 26 | Context ctx; |
29 | 27 | ctx.set_base_url("https://go.netlicensing.io/core/v2/rest/"); |
30 | 28 | ctx.set_username("demo"); |
31 | | - ctx.set_password("demo"); |
| 29 | + ctx.set_password("demo"); |
32 | 30 |
|
33 | | - // product section |
| 31 | + // product section |
34 | 32 | netlicensing::Product p; |
35 | | - p.name_ = "Test name"; |
36 | | - p.number_ = "Some number 5"; |
37 | | - netlicensing::Product newp = netlicensing::create(ctx, p); |
| 33 | + p.setName("Test name"); |
| 34 | + p.setNumber(productNumber); |
| 35 | + netlicensing::Product newp = netlicensing::ProductService::create(ctx, p); |
38 | 36 |
|
39 | | - newp.name_ = "Updated name"; |
40 | | - netlicensing::Product newp2 = netlicensing::update(ctx, newp.number_, newp); |
| 37 | + newp.setName("Updated name"); |
| 38 | + netlicensing::Product newp2 = netlicensing::ProductService::update(ctx, newp.getNumber(), newp); |
41 | 39 |
|
42 | | - std::list<netlicensing::Product> products = netlicensing::list<netlicensing::Product>(ctx, ""); |
| 40 | + std::list<netlicensing::Product> products = netlicensing::ProductService::list(ctx, ""); |
43 | 41 | std::cout << "before delete products count " << products.size() << std::endl; |
44 | 42 |
|
45 | | - netlicensing::del<netlicensing::Product>(ctx, newp2.number_, false); |
| 43 | + netlicensing::ProductService::del(ctx, newp2.getNumber(), false); |
46 | 44 |
|
47 | | - products = netlicensing::list<netlicensing::Product>(ctx, ""); |
| 45 | + products = netlicensing::ProductService::list(ctx, ""); |
48 | 46 | std::cout << "after delete products count " << products.size() << std::endl; |
49 | 47 |
|
50 | 48 | if (!license_number.empty()) { |
51 | 49 | std::cout << "start validation for " << license_number << std::endl; |
52 | | - std::list<netlicensing::ValidationResult> vres = netlicensing::validate(ctx, license_number); |
| 50 | + std::list<netlicensing::ValidationResult> vres = netlicensing::ValidationService::validate(ctx, license_number); |
53 | 51 | std::cout << "got validation results: " << vres.size() << std::endl; |
54 | 52 | for (auto val_res : vres) { |
55 | 53 | std::cout << val_res.to_string() << std::endl; |
|
0 commit comments