|
6 | 6 | #include "netlicensing/constants.h" |
7 | 7 |
|
8 | 8 | int main(int argc, char* argv[]) { |
9 | | - using namespace netlicensing; |
10 | | - |
11 | | - std::string licensee_number = "IR2Q7A5P3"; |
12 | | - if (argc > 1) { |
13 | | - licensee_number = argv[1]; |
14 | | - } |
15 | | - |
16 | | - std::mt19937 gen; |
17 | | - gen.seed(time(0)); |
18 | | - std::stringstream ss; |
19 | | - ss << "P" << gen(); |
20 | | - std::string productNumber = ss.str(); |
21 | | - |
22 | | - std::cout << "Hello, this is NetLicensing demo client\n"; |
23 | | - std::cout << "Product endpoint " << endpoint<Product>() << std::endl; |
24 | | - std::cout << "Product test number " << productNumber << std::endl; |
25 | | - |
26 | | - try { |
27 | | - Context ctx; |
28 | | - ctx.set_base_url("https://go.netlicensing.io/core/v2/rest/"); |
29 | | - ctx.set_username("demo"); |
30 | | - ctx.set_password("demo"); |
31 | | - |
32 | | - // product section |
33 | | - Product p; |
34 | | - p.setName("Test name"); |
35 | | - p.setNumber(productNumber); |
36 | | - Product newp = ProductService::create(ctx, p); |
37 | | - |
38 | | - newp.setName("Updated name"); |
39 | | - Product newp2 = ProductService::update(ctx, newp.getNumber(), newp); |
40 | | - |
41 | | - std::list<Product> products = ProductService::list(ctx, ""); |
42 | | - std::cout << "before delete products count " << products.size() << std::endl; |
43 | | - |
44 | | - ProductService::del(ctx, newp2.getNumber(), false); |
45 | | - |
46 | | - products = ProductService::list(ctx, ""); |
47 | | - std::cout << "after delete products count " << products.size() << std::endl; |
48 | | - |
49 | | - if (!licensee_number.empty()) { |
50 | | - std::cout << "start validation for " << licensee_number << std::endl; |
51 | | - ValidationResult vres = LicenseeService::validate(ctx, licensee_number); |
52 | | - std::cout << "got validation results:\n" << vres.toString() << std::endl; |
53 | | - } |
54 | | - } |
55 | | - catch (const RestException& e) { |
56 | | - std::cerr << e.what() << " code " << e.http_code() << std::endl; |
57 | | - for (auto det : e.get_details()) { |
58 | | - std::cerr << det.to_string() << std::endl; |
59 | | - } |
60 | | - return 2; |
61 | | - } |
62 | | - catch (const std::runtime_error& err) { |
63 | | - std::cerr << err.what() << std::endl; |
64 | | - return 1; |
65 | | - } |
66 | | - |
67 | | - return 0; |
| 9 | + using namespace netlicensing; |
| 10 | + |
| 11 | + std::string licensee_number = "IR2Q7A5P3"; |
| 12 | + if (argc > 1) { |
| 13 | + licensee_number = argv[1]; |
| 14 | + } |
| 15 | + |
| 16 | + std::mt19937 gen; |
| 17 | + gen.seed(time(0)); |
| 18 | + std::stringstream ss; |
| 19 | + ss << "P" << gen(); |
| 20 | + std::string productNumber = ss.str(); |
| 21 | + |
| 22 | + std::cout << "Hello, this is NetLicensing demo client\n"; |
| 23 | + std::cout << "Product endpoint " << endpoint<Product>() << std::endl; |
| 24 | + std::cout << "Product test number " << productNumber << std::endl; |
| 25 | + |
| 26 | + try { |
| 27 | + Context ctx; |
| 28 | + ctx.set_base_url("https://go.netlicensing.io/core/v2/rest/"); |
| 29 | + ctx.set_username("demo"); |
| 30 | + ctx.set_password("demo"); |
| 31 | + |
| 32 | + // product section |
| 33 | + Product p; |
| 34 | + p.setName("Test name"); |
| 35 | + p.setNumber(productNumber); |
| 36 | + |
| 37 | + std::list<ProductDiscount> discounts; |
| 38 | + ProductDiscount discount; |
| 39 | + ProductDiscount discount2; |
| 40 | + |
| 41 | + discount.setTotalPrice("20"); |
| 42 | + discount.setCurrency("EUR"); |
| 43 | + discount.setAmountFix("10"); |
| 44 | + |
| 45 | + discount2.setTotalPrice("25"); |
| 46 | + discount2.setCurrency("EUR"); |
| 47 | + discount2.setAmountPercent("10"); |
| 48 | + |
| 49 | + discounts.push_back(discount); |
| 50 | + discounts.push_back(discount2); |
| 51 | + |
| 52 | + p.setProductsDiscounts(discounts); |
| 53 | + |
| 54 | + Product newp = ProductService::create(ctx, p); |
| 55 | + |
| 56 | + std::list<ProductDiscount> newpDiscounts = newp.getDiscounts(); |
| 57 | + |
| 58 | + std::cout << "product disounts size: " << newpDiscounts.size() << std::endl; |
| 59 | + |
| 60 | + int i = 0; |
| 61 | + for (ProductDiscount newpDiscount : newpDiscounts) { |
| 62 | + std::string newpDiscountStr = newpDiscount.toString(); |
| 63 | + std::cout << "product disount #" << i << ":" << newpDiscountStr << std::endl; |
| 64 | + i++; |
| 65 | + } |
| 66 | + |
| 67 | + newp.setName("Updated name"); |
| 68 | + |
| 69 | + std::list<ProductDiscount> discountsEmpty; |
| 70 | + newp.setProductsDiscounts(discountsEmpty); |
| 71 | + std::cin.ignore(); |
| 72 | + Product newp2 = ProductService::update(ctx, newp.getNumber(), newp); |
| 73 | + |
| 74 | + std::list<ProductDiscount> newp2Discounts = newp2.getDiscounts(); |
| 75 | + |
| 76 | + std::cout << "product disounts size " << newp2Discounts.size() << std::endl; |
| 77 | + std::cin.ignore(); |
| 78 | + std::list<Product> products = ProductService::list(ctx, ""); |
| 79 | + std::cout << "before delete products count " << products.size() << std::endl; |
| 80 | + |
| 81 | + ProductService::del(ctx, newp2.getNumber(), false); |
| 82 | + |
| 83 | + products = ProductService::list(ctx, ""); |
| 84 | + std::cout << "after delete products count " << products.size() << std::endl; |
| 85 | + |
| 86 | + if (!licensee_number.empty()) { |
| 87 | + std::cout << "start validation for " << licensee_number << std::endl; |
| 88 | + ValidationResult vres = LicenseeService::validate(ctx, licensee_number); |
| 89 | + std::cout << "got validation results:\n" << vres.toString() << std::endl; |
| 90 | + } |
| 91 | + } |
| 92 | + catch (const RestException& e) { |
| 93 | + std::cerr << e.what() << " code " << e.http_code() << std::endl; |
| 94 | + for (auto det : e.get_details()) { |
| 95 | + std::cerr << det.to_string() << std::endl; |
| 96 | + } |
| 97 | + return 2; |
| 98 | + } |
| 99 | + catch (const std::runtime_error& err) { |
| 100 | + std::cerr << err.what() << std::endl; |
| 101 | + std::cin.ignore(); |
| 102 | + return 1; |
| 103 | + } |
| 104 | + |
| 105 | + return 0; |
68 | 106 | } |
0 commit comments