Skip to content

Commit da4bf7e

Browse files
sleepdefic1tfaustbrian
authored andcommitted
refactor: improve API query usage (#114)
1 parent 9af5968 commit da4bf7e

File tree

26 files changed

+245
-338
lines changed

26 files changed

+245
-338
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313

1414
### Changed
1515

16+
- improved API query usage to accept strings ([#114])
1617
- improved class members and test coverage ([#93])
1718
- improved formatting and maintainability ([#92])
1819
- dropped Hunter Package Manager in favor of git submodules in OS builds. ([#90])
@@ -65,3 +66,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6566
[#67]: https://github.com/ArkEcosystem/cpp-client/pull/67
6667
[#63]: https://github.com/ArkEcosystem/cpp-client/pull/63
6768
[#65]: https://github.com/ArkEcosystem/cpp-client/pull/65
69+
[#114]: https://github.com/ArkEcosystem/cpp-client/pull/114

docs/cpp.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ Ark::Client::Host dummyHost("0.0.0.0:4003");
7373
std::string blockchainGetPath = Ark::Client::API::Paths::Blockschain::get(dummyHost);
7474
// blockchainGetPath will be the string "0.0.0.0:4003/api/blockchain"
7575

76-
std::string blocksAllPath = Ark::Client::API::Paths::Blocks::all(dummyHost, 5 /* limit */, 1 /* page */);
77-
// blocksAllPath will be the string "0.0.0.0:4003/api/blocks?limit=5&page=1"
76+
std::string blocksAllPath = Ark::Client::API::Paths::Blocks::all(dummyHost, "?page=1&limit=5");
77+
// blocksAllPath will be the string "0.0.0.0:4003/api/blocks?page=1&limit=5"
7878

7979
std::string delegatesGetPath = Ark::Client::API::Paths::Delegates::get(dummyHost, "genesis_1");
8080
// delegatesGetPath will be the string "0.0.0.0:4003/api/delegates/genesis_1"
8181

8282
std::string nodeConfigurationPath = Ark::Client::API::Paths::Node::configuration(dummyHost);
8383
// nodeConfigurationPath will be the string "0.0.0.0:4003/api/node/configuration"
8484

85-
std::string peersAllPath = Ark::Client::API::Paths::Peers::all(dummyHost, 5 /* limit */, 1 /* page */);
86-
// peersAllPath will be the string "0.0.0.0:4003/api/peers?limit=5&page=1"
85+
std::string peersAllPath = Ark::Client::API::Paths::Peers::all(dummyHost, "?page=1&limit=5");
86+
// peersAllPath will be the string "0.0.0.0:4003/api/peers?page=1&limit=5"
8787

8888
std::string transactionsTypesPath = Ark::Client::API::Paths::Transactions::types(dummyHost);
8989
// transactionsTypesPath will be the string "0.0.0.0:4003/api/transactions/types"
@@ -96,8 +96,8 @@ const std::map<std::string, std::string> searchBody = {
9696
{"username", "genesis_1"}
9797
};
9898

99-
std::pair<std::string, std::string> walletsSearchPath = Ark::Client::API::Paths::Wallets::search(testHost, searchBody, 5, 1);
100-
// walletsSearchPath.first will be the string "0.0.0.0:4003/api/wallets/search?limit=5&page=1"
99+
std::pair<std::string, std::string> walletsSearchPath = Ark::Client::API::Paths::Wallets::search(testHost, searchBody, "?page=1&limit=5");
100+
// walletsSearchPath.first will be the string "0.0.0.0:4003/api/wallets/search?page=1&limit=5"
101101
// walletsSearchPath.second will be the string "username=genesis_1"
102102
```
103103

examples/arduino/ESP32/ESP32.ino

+7-7
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void checkAPI() {
139139
// }
140140
// ]
141141
// }
142-
const auto blocksResponse = connection.api.blocks.all(1, 1);
142+
const auto blocksResponse = connection.api.blocks.all("?limit=1&page=1");
143143
Serial.print("\nBlocks Response: ");
144144
// The response is a 'std::string'; to 'Print' on Arduino, we need the c_string type.
145145
Serial.println(blocksResponse.c_str());
@@ -209,7 +209,7 @@ void checkAPI() {
209209

210210
// The following method can be used to get a list of 'All' 'Peers' on the network.
211211
//
212-
// This is equivalent to calling 'https://dexplorer.ark.io/api/peers?limit=2&page=1'
212+
// This is equivalent to calling 'https://dexplorer.ark.io/api/peers?limit=1&page=1'
213213
//
214214
// {
215215
// "meta": {
@@ -233,7 +233,7 @@ void checkAPI() {
233233
// }
234234
// ]
235235
// }
236-
const auto allPeers = connection.api.peers.all(1, 1);
236+
const auto allPeers = connection.api.peers.all("?limit=1&page=1");
237237
Serial.print("\nAll Peers: ");
238238
Serial.println(allPeers.c_str());
239239

@@ -264,7 +264,7 @@ void checkAPI() {
264264

265265
// This method can be used to get a list of 'Vote' Transactions.
266266
//
267-
// This is equivalent to calling 'https://dexplorer.ark.io/api/votes?limit=2&page=1'
267+
// This is equivalent to calling 'https://dexplorer.ark.io/api/votes?limit=1&page=1'
268268
//
269269
// {
270270
// "meta": {
@@ -304,15 +304,15 @@ void checkAPI() {
304304
// }
305305
// ]
306306
// }
307-
const auto allVotes = connection.api.votes.all(1, 1);
307+
const auto allVotes = connection.api.votes.all("?limit=1&page=1");
308308
Serial.print("\nAll Votes: ");
309309
Serial.println(allVotes.c_str());
310310

311311
/********************/
312312

313313
// This method can be used to get a list of 'Top' 'Wallets' (Wallets with the most ARK).
314314
//
315-
// This is equivalent to calling 'https://dexplorer.ark.io/api/wallets/top?limit=2&page=1'
315+
// This is equivalent to calling 'https://dexplorer.ark.io/api/wallets/top?limit=1&page=1'
316316
//
317317
// The response should be a json-formatted object
318318
// The "pretty print" version would look something like this:
@@ -337,7 +337,7 @@ void checkAPI() {
337337
// }
338338
// ]
339339
// }
340-
const auto topWallets = connection.api.wallets.top(1, 1);
340+
const auto topWallets = connection.api.wallets.top("limit=1&page=1");
341341
Serial.print("\nTop Wallets: ");
342342
Serial.println(topWallets.c_str());
343343
};

examples/arduino/ESP8266/ESP8266.ino

+7-7
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void checkAPI() {
139139
// }
140140
// ]
141141
// }
142-
const auto blocksResponse = connection.api.blocks.all(1, 1);
142+
const auto blocksResponse = connection.api.blocks.all("?limit=1&page=1");
143143
Serial.print("\nBlocks Response: ");
144144
// The response is a 'std::string'; to 'Print' on Arduino, we need the c_string type.
145145
Serial.println(blocksResponse.c_str());
@@ -209,7 +209,7 @@ void checkAPI() {
209209

210210
// The following method can be used to get a list of 'All' 'Peers' on the network.
211211
//
212-
// This is equivalent to calling 'https://dexplorer.ark.io/api/peers?limit=2&page=1'
212+
// This is equivalent to calling 'https://dexplorer.ark.io/api/peers?limit=1&page=1'
213213
//
214214
// {
215215
// "meta": {
@@ -233,7 +233,7 @@ void checkAPI() {
233233
// }
234234
// ]
235235
// }
236-
const auto allPeers = connection.api.peers.all(1, 1);
236+
const auto allPeers = connection.api.peers.all("?limit=1&page=1");
237237
Serial.print("\nAll Peers: ");
238238
Serial.println(allPeers.c_str());
239239

@@ -264,7 +264,7 @@ void checkAPI() {
264264

265265
// This method can be used to get a list of 'Vote' Transactions.
266266
//
267-
// This is equivalent to calling 'https://dexplorer.ark.io/api/votes?limit=2&page=1'
267+
// This is equivalent to calling 'https://dexplorer.ark.io/api/votes?limit=1&page=1'
268268
//
269269
// {
270270
// "meta": {
@@ -304,15 +304,15 @@ void checkAPI() {
304304
// }
305305
// ]
306306
// }
307-
const auto allVotes = connection.api.votes.all(1, 1);
307+
const auto allVotes = connection.api.votes.all("?limit=1&page=1");
308308
Serial.print("\nAll Votes: ");
309309
Serial.println(allVotes.c_str());
310310

311311
/********************/
312312

313313
// This method can be used to get a list of 'Top' 'Wallets' (Wallets with the most ARK).
314314
//
315-
// This is equivalent to calling 'https://dexplorer.ark.io/api/wallets/top?limit=2&page=1'
315+
// This is equivalent to calling 'https://dexplorer.ark.io/api/wallets/top?limit=1&page=1'
316316
//
317317
// The response should be a json-formatted object
318318
// The "pretty print" version would look something like this:
@@ -337,7 +337,7 @@ void checkAPI() {
337337
// }
338338
// ]
339339
// }
340-
const auto topWallets = connection.api.wallets.top(1, 1);
340+
const auto topWallets = connection.api.wallets.top("?limit=1&page=1");
341341
Serial.print("\nTop Wallets: ");
342342
Serial.println(topWallets.c_str());
343343
};

src/api/blocks/blocks.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ std::string Ark::Client::API::Blocks::get(
1010

1111
/**/
1212

13-
std::string Ark::Client::API::Blocks::all(
14-
int limit /* = 5 */,
15-
int page /* = 1 */) {
13+
std::string Ark::Client::API::Blocks::all(const char* const query) {
1614
return http_->get(Ark::Client::API::Paths::Blocks::all(
1715
this->host_,
18-
limit, page).c_str());
16+
query).c_str());
1917
}
2018

2119
/**/
@@ -31,11 +29,10 @@ std::string Ark::Client::API::Blocks::transactions(
3129

3230
std::string Ark::Client::API::Blocks::search(
3331
const std::map<std::string, std::string> &bodyParameters,
34-
int limit /* = 5 */,
35-
int page /* = 1 */) {
32+
const char* const query) {
3633
const auto searchPathPair = Ark::Client::API::Paths::Blocks::search(
3734
this->host_,
3835
bodyParameters,
39-
limit, page);
36+
query);
4037
return http_->post(searchPathPair.first.c_str(), searchPathPair.second.c_str());
4138
}

src/api/delegates/delegates.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,30 @@ std::string Ark::Client::API::Delegates::get(
1010

1111
/**/
1212

13-
std::string Ark::Client::API::Delegates::all(
14-
int limit /* = 5 */,
15-
int page /* = 1 */) {
13+
std::string Ark::Client::API::Delegates::all(const char* const query) {
1614
return http_->get(Ark::Client::API::Paths::Delegates::all(
1715
this->host_,
18-
limit, page).c_str());
16+
query).c_str());
1917
}
2018

2119
/**/
2220

2321
std::string Ark::Client::API::Delegates::blocks(
2422
const char *const identifier,
25-
int limit /* = 5 */,
26-
int page /* = 1 */) {
23+
const char* const query) {
2724
return http_->get(Ark::Client::API::Paths::Delegates::blocks(
2825
this->host_,
2926
identifier,
30-
limit, page).c_str());
27+
query).c_str());
3128
}
3229

3330
/**/
3431

3532
std::string Ark::Client::API::Delegates::voters(
3633
const char *const identifier,
37-
int limit /* = 5 */,
38-
int page /* = 1 */) {
34+
const char* const query) {
3935
return http_->get(Ark::Client::API::Paths::Delegates::voters(
4036
this->host_,
4137
identifier,
42-
limit, page).c_str());
38+
query).c_str());
4339
}

0 commit comments

Comments
 (0)