Skip to content

chore: improve API query usage. #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed

- improved API query usage to accept strings ([#114])
- improved class members and test coverage ([#93])
- improved formatting and maintainability ([#92])
- dropped Hunter Package Manager in favor of git submodules in OS builds. ([#90])
Expand Down Expand Up @@ -65,3 +66,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
[#67]: https://github.com/ArkEcosystem/cpp-client/pull/67
[#63]: https://github.com/ArkEcosystem/cpp-client/pull/63
[#65]: https://github.com/ArkEcosystem/cpp-client/pull/65
[#114]: https://github.com/ArkEcosystem/cpp-client/pull/114
12 changes: 6 additions & 6 deletions docs/cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ Ark::Client::Host dummyHost("0.0.0.0:4003");
std::string blockchainGetPath = Ark::Client::API::Paths::Blockschain::get(dummyHost);
// blockchainGetPath will be the string "0.0.0.0:4003/api/blockchain"

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

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

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

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

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

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

Expand Down
14 changes: 7 additions & 7 deletions examples/arduino/ESP32/ESP32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void checkAPI() {
// }
// ]
// }
const auto blocksResponse = connection.api.blocks.all(1, 1);
const auto blocksResponse = connection.api.blocks.all("?limit=1&page=1");
Serial.print("\nBlocks Response: ");
// The response is a 'std::string'; to 'Print' on Arduino, we need the c_string type.
Serial.println(blocksResponse.c_str());
Expand Down Expand Up @@ -209,7 +209,7 @@ void checkAPI() {

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

Expand Down Expand Up @@ -264,7 +264,7 @@ void checkAPI() {

// This method can be used to get a list of 'Vote' Transactions.
//
// This is equivalent to calling 'https://dexplorer.ark.io/api/votes?limit=2&page=1'
// This is equivalent to calling 'https://dexplorer.ark.io/api/votes?limit=1&page=1'
//
// {
// "meta": {
Expand Down Expand Up @@ -304,15 +304,15 @@ void checkAPI() {
// }
// ]
// }
const auto allVotes = connection.api.votes.all(1, 1);
const auto allVotes = connection.api.votes.all("?limit=1&page=1");
Serial.print("\nAll Votes: ");
Serial.println(allVotes.c_str());

/********************/

// This method can be used to get a list of 'Top' 'Wallets' (Wallets with the most ARK).
//
// This is equivalent to calling 'https://dexplorer.ark.io/api/wallets/top?limit=2&page=1'
// This is equivalent to calling 'https://dexplorer.ark.io/api/wallets/top?limit=1&page=1'
//
// The response should be a json-formatted object
// The "pretty print" version would look something like this:
Expand All @@ -337,7 +337,7 @@ void checkAPI() {
// }
// ]
// }
const auto topWallets = connection.api.wallets.top(1, 1);
const auto topWallets = connection.api.wallets.top("limit=1&page=1");
Serial.print("\nTop Wallets: ");
Serial.println(topWallets.c_str());
};
Expand Down
14 changes: 7 additions & 7 deletions examples/arduino/ESP8266/ESP8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void checkAPI() {
// }
// ]
// }
const auto blocksResponse = connection.api.blocks.all(1, 1);
const auto blocksResponse = connection.api.blocks.all("?limit=1&page=1");
Serial.print("\nBlocks Response: ");
// The response is a 'std::string'; to 'Print' on Arduino, we need the c_string type.
Serial.println(blocksResponse.c_str());
Expand Down Expand Up @@ -209,7 +209,7 @@ void checkAPI() {

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

Expand Down Expand Up @@ -264,7 +264,7 @@ void checkAPI() {

// This method can be used to get a list of 'Vote' Transactions.
//
// This is equivalent to calling 'https://dexplorer.ark.io/api/votes?limit=2&page=1'
// This is equivalent to calling 'https://dexplorer.ark.io/api/votes?limit=1&page=1'
//
// {
// "meta": {
Expand Down Expand Up @@ -304,15 +304,15 @@ void checkAPI() {
// }
// ]
// }
const auto allVotes = connection.api.votes.all(1, 1);
const auto allVotes = connection.api.votes.all("?limit=1&page=1");
Serial.print("\nAll Votes: ");
Serial.println(allVotes.c_str());

/********************/

// This method can be used to get a list of 'Top' 'Wallets' (Wallets with the most ARK).
//
// This is equivalent to calling 'https://dexplorer.ark.io/api/wallets/top?limit=2&page=1'
// This is equivalent to calling 'https://dexplorer.ark.io/api/wallets/top?limit=1&page=1'
//
// The response should be a json-formatted object
// The "pretty print" version would look something like this:
Expand All @@ -337,7 +337,7 @@ void checkAPI() {
// }
// ]
// }
const auto topWallets = connection.api.wallets.top(1, 1);
const auto topWallets = connection.api.wallets.top("?limit=1&page=1");
Serial.print("\nTop Wallets: ");
Serial.println(topWallets.c_str());
};
Expand Down
11 changes: 4 additions & 7 deletions src/api/blocks/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ std::string Ark::Client::API::Blocks::get(

/**/

std::string Ark::Client::API::Blocks::all(
int limit /* = 5 */,
int page /* = 1 */) {
std::string Ark::Client::API::Blocks::all(const char* const query) {
return http_->get(Ark::Client::API::Paths::Blocks::all(
this->host_,
limit, page).c_str());
query).c_str());
}

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

std::string Ark::Client::API::Blocks::search(
const std::map<std::string, std::string> &bodyParameters,
int limit /* = 5 */,
int page /* = 1 */) {
const char* const query) {
const auto searchPathPair = Ark::Client::API::Paths::Blocks::search(
this->host_,
bodyParameters,
limit, page);
query);
return http_->post(searchPathPair.first.c_str(), searchPathPair.second.c_str());
}
16 changes: 6 additions & 10 deletions src/api/delegates/delegates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,30 @@ std::string Ark::Client::API::Delegates::get(

/**/

std::string Ark::Client::API::Delegates::all(
int limit /* = 5 */,
int page /* = 1 */) {
std::string Ark::Client::API::Delegates::all(const char* const query) {
return http_->get(Ark::Client::API::Paths::Delegates::all(
this->host_,
limit, page).c_str());
query).c_str());
}

/**/

std::string Ark::Client::API::Delegates::blocks(
const char *const identifier,
int limit /* = 5 */,
int page /* = 1 */) {
const char* const query) {
return http_->get(Ark::Client::API::Paths::Delegates::blocks(
this->host_,
identifier,
limit, page).c_str());
query).c_str());
}

/**/

std::string Ark::Client::API::Delegates::voters(
const char *const identifier,
int limit /* = 5 */,
int page /* = 1 */) {
const char* const query) {
return http_->get(Ark::Client::API::Paths::Delegates::voters(
this->host_,
identifier,
limit, page).c_str());
query).c_str());
}
Loading