Skip to content
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ include(FetchContent)

# Download and build libcpr
FetchContent_Declare(
cpr
cpr
GIT_REPOSITORY https://github.com/libcpr/cpr.git
GIT_TAG 1.10.2
)
# Download and build nlohmann_json
FetchContent_Declare(
nlohmann_json
nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
)
# Download and build googletest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Be aware that the library may require some .dll files (found in the `build` dire
Include the library in your file:
```cpp
#include <ZeroBounce/ZeroBounce.h>
```
```

Initialize the wrapper with your api key:
```cpp
Expand Down
2 changes: 1 addition & 1 deletion documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Be aware that the library may require some .dll files (found in the `build` dire
Include the library in your file:
```cpp
###include <ZeroBounce/ZeroBounce.h>
```
```

Initialize the wrapper with your api key:
```cpp
Expand Down
2 changes: 1 addition & 1 deletion documentation_es.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Ten en cuenta que es posible que la biblioteca requiera algunos archivos .dll (q
Incluye la biblioteca en tu archivo:
```cpp
###include <ZeroBounce/ZeroBounce.h>
```
```

Inicializa el envoltorio con tu clave de API:
```cpp
Expand Down
4 changes: 2 additions & 2 deletions include/ZeroBounce/ZBErrorResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
/**
* The model used for when a request throws an error. This model was introduced in order to provide
* a standardized way of handling the error responses that a request can return.
*
*
* If the error JSON received from the server includes the words "error" or "message", then the
* values of those keys will be added to the [errors] array. If the error is not a JSON dictionary,
* then JSON String will be added to the [errors] array.
*
*
* If any type of messages are received, then they will be added according to the same rule above
* after the errors found above.
*/
Expand Down
50 changes: 50 additions & 0 deletions include/ZeroBounce/ZBFindEmailResponse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef ZB_FIND_EMAIL_RESPONSE_H
#define ZB_FIND_EMAIL_RESPONSE_H

#include <string>
#include <vector>

#include <nlohmann/json.hpp>

using json = nlohmann::json;

/**
* @brief highlights how a domain can format its emails and how confident is
* the API about it
*/
class ZBDomainFormat {

public:
std::string format;
std::string confidence;

static ZBDomainFormat from_json(const json& json_obj);

bool operator==(const ZBDomainFormat& other) const;
};

/**
* @brief The class associated with the GET /guessformat request.
*
*/
class ZBFindEmailResponse {

public:
std::string email;
std::string domain;
std::string format;
std::string status;
std::string subStatus;
std::string confidence;
std::string didYouMean;
std::string failureReason;
std::vector<ZBDomainFormat> otherDomainFormats;

static ZBFindEmailResponse from_json(const json& json_obj);

bool operator==(const ZBFindEmailResponse& other) const;
};



#endif
2 changes: 1 addition & 1 deletion include/ZeroBounce/ZBValidateBatchResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ZBEmailToValidate {
std::string emailAddress;
std::string ipAddress;

ZBEmailToValidate(const std::string& email, const std::string& ip = "")
ZBEmailToValidate(const std::string& email, const std::string& ip = "")
: emailAddress(email), ipAddress(ip) {}
};

Expand Down
45 changes: 42 additions & 3 deletions include/ZeroBounce/ZeroBounce.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ZeroBounce/ZBGetFileResponse.h"
#include "ZeroBounce/ZBDeleteFileResponse.h"
#include "ZeroBounce/ZBActivityDataResponse.h"
#include "ZeroBounce/ZBFindEmailResponse.h"

#include <cpr/cpr.h>

Expand Down Expand Up @@ -181,15 +182,15 @@ class ZeroBounce {
OnSuccessCallback<ZBDeleteFileResponse> successCallback,
OnErrorCallback errorCallback
);

public:
ZeroBounce();
ZeroBounce(const ZeroBounce& obj) = delete;

/**
* Get pointer to ZeroBounce instance.
*
* @return ZeroBounce*
*
* @return ZeroBounce*
*/
static ZeroBounce* getInstance();

Expand Down Expand Up @@ -384,6 +385,44 @@ class ZeroBounce {
OnSuccessCallback<ZBActivityDataResponse> successCallback,
OnErrorCallback errorCallback
);

/**
* @brief Email Address Search - Identifies and validates a person’s primary email address
*
* @param zb ZeroBounce pointer
* @param domain The email domain for which to find the email format
* @param first_name The first name of the person whose email format is being searched
* @param middle_name The middle name of the person whose email format is being searched
* @param last_name The last name of the person whose email format is being searched
* @param success_callback success callback
* @param error_callback error callback
*/
void findEmail(
std::string domain,
std::string first_name,
std::string middle_name,
std::string last_name,
OnSuccessCallback<ZBFindEmailResponse> successCallback,
OnErrorCallback errorCallback
);

/**
* @brief Email Address Search - Identifies and validates a person’s primary email address
*
* @param zb ZeroBounce pointer
* @param domain The email domain for which to find the email format
* @param first_name The first name of the person whose email format is being searched
* @param last_name The last name of the person whose email format is being searched
* @param success_callback success callback
* @param error_callback error callback
*/
void findEmail(
std::string domain,
std::string first_name,
std::string last_name,
OnSuccessCallback<ZBFindEmailResponse> successCallback,
OnErrorCallback errorCallback
);
};

#endif
2 changes: 1 addition & 1 deletion include/ZeroBounce/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using json = nlohmann::json;
/**
* Function used to get the value of a given key in a json.
* If the key doesn't exist or it's null, a default value is returned.
*
*
* @tparam T type of the returned value
* @param j json object
* @param key name of the field
Expand Down
2 changes: 1 addition & 1 deletion src/ZBActivityDataResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ std::string ZBActivityDataResponse::toString()
", activeInDays='" << activeInDays << '\'' <<
", error='" << error << '\'' <<
'}';

return stringStream.str();
}

Expand Down
2 changes: 1 addition & 1 deletion src/ZBCreditsResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ std::string ZBCreditsResponse::toString()
stringStream << "ZBCreditsResponse{" <<
"credits='" << credits << '\'' <<
'}';

return stringStream.str();
}

Expand Down
4 changes: 2 additions & 2 deletions src/ZBDeleteFileResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ std::string ZBDeleteFileResponse::toString()
", fileName='" << fileName << '\'' <<
", fileId='" << fileId << '\'' <<
'}';

return stringStream.str();
}

Expand All @@ -23,7 +23,7 @@ ZBDeleteFileResponse ZBDeleteFileResponse::from_json(const json& j) {
r.message = getOrDefault<std::string>(j, "message", "");
r.fileName = getOrDefault<std::string>(j, "file_name", "");
r.fileId = getOrDefault<std::string>(j, "file_id", "");

return r;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ZBErrorResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ std::string ZBErrorResponse::toString()
stringStream << ", ";
}
}

stringStream << "]}";

return stringStream.str();
}

Expand Down
4 changes: 2 additions & 2 deletions src/ZBFileStatusResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ std::string ZBFileStatusResponse::toString()
", returnUrl='" << returnUrl << '\'' <<
", errorReason='" << errorReason << '\'' <<
'}';

return stringStream.str();
}

Expand All @@ -33,7 +33,7 @@ ZBFileStatusResponse ZBFileStatusResponse::from_json(const json& j) {
r.fileStatus = getOrDefault<std::string>(j, "file_status", "");
r.completePercentage = getOrDefault<std::string>(j, "complete_percentage", "");
r.returnUrl = getOrDefault<std::string>(j, "return_url", "");

return r;
}

Expand Down
60 changes: 60 additions & 0 deletions src/ZBFindEmailResponse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "ZeroBounce/utils.h"
#include "ZeroBounce/ZBFindEmailResponse.h"

ZBDomainFormat ZBDomainFormat::from_json(const json& json_obj) {
ZBDomainFormat response;
response.format = getOrDefault<std::string>(json_obj, "format", "");
response.confidence = getOrDefault<std::string>(json_obj, "confidence", "");
return response;
}

bool ZBDomainFormat::operator==(const ZBDomainFormat& other) const {
return this->confidence == other.confidence && this->format == other.format;
}


ZBFindEmailResponse ZBFindEmailResponse::from_json(const json& json_obj) {
ZBFindEmailResponse response;
response.email = getOrDefault<std::string>(json_obj, "email", "");
response.domain = getOrDefault<std::string>(json_obj, "domain", "");
response.format = getOrDefault<std::string>(json_obj, "format", "");
response.status = getOrDefault<std::string>(json_obj, "status", "");
response.subStatus = getOrDefault<std::string>(json_obj, "sub_status", "");
response.confidence = getOrDefault<std::string>(json_obj, "confidence", "");
response.didYouMean = getOrDefault<std::string>(json_obj, "did_you_mean", "");
response.failureReason = getOrDefault<std::string>(json_obj, "failure_reason", "");

response.otherDomainFormats = std::vector<ZBDomainFormat>();
const json domainFormats = json_obj["other_domain_formats"];
if (domainFormats.is_array()) {
for (int index = 0; index < domainFormats.size(); index ++) {
response.otherDomainFormats.push_back(
ZBDomainFormat::from_json(domainFormats.at(index))
);
}
}
return response;
}

bool ZBFindEmailResponse::operator==(const ZBFindEmailResponse& other) const {
bool fieldsAreEqual = this->email == other.email
&& this->domain == other.domain
&& this->format == other.format
&& this->status == other.status
&& this->subStatus == other.subStatus
&& this->confidence == other.confidence
&& this->didYouMean == other.didYouMean
&& this->failureReason == other.failureReason;
if (!fieldsAreEqual) {
return false;
}
if (this->otherDomainFormats.size() != other.otherDomainFormats.size()) {
return false;
}
for (int index = 0; index < this->otherDomainFormats.size(); index ++) {
if (this->otherDomainFormats[index] != other.otherDomainFormats[index]) {
return false;
}
}
return true;
}
4 changes: 2 additions & 2 deletions src/ZBGetApiUsageResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::string ZBGetApiUsageResponse::toString()
", endDate='" << endDate << '\'' <<
", error='" << error << '\'' <<
'}';

return stringStream.str();
}

Expand Down Expand Up @@ -85,7 +85,7 @@ ZBGetApiUsageResponse ZBGetApiUsageResponse::from_json(const json& j) {
r.startDate = getOrDefault<std::string>(j, "start_date", "");
r.endDate = getOrDefault<std::string>(j, "end_date", "");
r.error = getOrDefault<std::string>(j, "error", "");

return r;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ZBGetFileResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ std::string ZBGetFileResponse::toString()
", message='" << message << '\'' <<
", localFilePath='" << localFilePath << '\'' <<
'}';

return stringStream.str();
}

Expand All @@ -20,7 +20,7 @@ ZBGetFileResponse ZBGetFileResponse::from_json(const json& j) {

r.success = getOrDefault<bool>(j, "success", false);
r.message = getOrDefault<std::string>(j, "message", "");

return r;
}

Expand Down
6 changes: 3 additions & 3 deletions src/ZBSendFileResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ std::string ZBSendFileResponse::toString()
stringStream << ", ";
}
}

stringStream << '\'' <<
", fileName='" << fileName << '\'' <<
", fileId='" << fileId << '\'' << '}';

return stringStream.str();
}

Expand All @@ -38,7 +38,7 @@ ZBSendFileResponse ZBSendFileResponse::from_json(const json& j) {

r.fileName = j.value("file_name", "");
r.fileId = j.value("file_id", "");

return r;
}

Expand Down
Loading