Skip to content

Commit

Permalink
refactor: internet module (#738)
Browse files Browse the repository at this point in the history
* refactor: internet module

- internet module migration from class to functions within internet namespace

- modified reference to functions from internet module in all dependent modules

Signed-off-by: Guru Mehar Rachaputi <gurumeharrachaputi@gmail.com>

* modified internet module reference in example

Signed-off-by: Guru Mehar Rachaputi <gurumeharrachaputi@gmail.com>

---------

Signed-off-by: Guru Mehar Rachaputi <gurumeharrachaputi@gmail.com>
  • Loading branch information
00thirdeye00 committed Jun 25, 2024
1 parent 859d59f commit e329131
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 187 deletions.
4 changes: 2 additions & 2 deletions examples/basic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
int main()
{
const auto id = faker::String::uuid();
const auto email = faker::Internet::email();
const auto password = faker::Internet::password();
const auto email = faker::internet::email();
const auto password = faker::internet::password();
const auto city = faker::location::city();
const auto streetAddress = faker::location::streetAddress();

Expand Down
118 changes: 57 additions & 61 deletions include/faker-cxx/Internet.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "types/Country.h"

namespace faker
namespace faker::internet
{
enum class HttpResponseType
{
Expand Down Expand Up @@ -39,9 +39,6 @@ struct PasswordOptions
bool symbols = true;
};

class Internet
{
public:
/**
* @brief Generates a username using the given person's name as base.
*
Expand All @@ -51,13 +48,13 @@ class Internet
* @returns Username including neither, one or both of the provided names.
*
* @code
* Internet::username() // "Richardson.Jeffrey1997"
* Internet::username("Michael") // "Michael_Allen29"
* Internet::username(std::nullopt, "Cieslar") // "Phillip_Cieslar20"
* Internet::username("Andrew", "Cieslar") // "Andrew.Cieslar"
* internet::username() // "Richardson.Jeffrey1997"
* internet::username("Michael") // "Michael_Allen29"
* internet::username(std::nullopt, "Cieslar") // "Phillip_Cieslar20"
* internet::username("Andrew", "Cieslar") // "Andrew.Cieslar"
* @endcode
*/
static std::string username(std::optional<std::string> firstName = std::nullopt,
std::string username(std::optional<std::string> firstName = std::nullopt,
std::optional<std::string> lastName = std::nullopt, Country country = Country::Usa);

/**
Expand All @@ -70,14 +67,14 @@ class Internet
* @returns Email including neither, one or both of the provided names, with random/provided email host.
*
* @code
* Internet::email() // "Jimenez.Clyde@gmail.com"
* Internet::email("Tom") // "TomRichardson79@outlook.com"
* Internet::email(std::nullopt, "Howard") // "FreddieHoward@hotmail.com"
* Internet::email("Cindy", "Young") // "Young_Cindy@gmail.com"
* Internet::email(std::nullopt, std::nullopt, "example.com") // "Wright.Edna1973@code.com"
* internet::email() // "Jimenez.Clyde@gmail.com"
* internet::email("Tom") // "TomRichardson79@outlook.com"
* internet::email(std::nullopt, "Howard") // "FreddieHoward@hotmail.com"
* internet::email("Cindy", "Young") // "Young_Cindy@gmail.com"
* internet::email(std::nullopt, std::nullopt, "example.com") // "Wright.Edna1973@code.com"
* @endcode
*/
static std::string email(std::optional<std::string> firstName = std::nullopt,
std::string email(std::optional<std::string> firstName = std::nullopt,
std::optional<std::string> lastName = std::nullopt,
std::optional<std::string> emailHost = std::nullopt);

Expand All @@ -90,10 +87,10 @@ class Internet
* @returns Email including neither, one or both of the provided names, with example email host.
*
* @code
* Internet::exampleEmail() // "Jimenez.Clyde@example.com"
* internet::exampleEmail() // "Jimenez.Clyde@example.com"
* @endcode
*/
static std::string exampleEmail(std::optional<std::string> firstName = std::nullopt,
std::string exampleEmail(std::optional<std::string> firstName = std::nullopt,
std::optional<std::string> lastName = std::nullopt);

/**
Expand All @@ -105,11 +102,11 @@ class Internet
* @returns Random password-like string.
*
* @code
* Internet::password() // "gXGpe9pKfFcKy9R"
* Internet::password(25) // "xv8vDu*wM!Rg0$zd0kH%8p!WY"
* internet::password() // "gXGpe9pKfFcKy9R"
* internet::password(25) // "xv8vDu*wM!Rg0$zd0kH%8p!WY"
* @endcode
*/
static std::string password(int length = 15, const PasswordOptions& options = {});
std::string password(int length = 15, const PasswordOptions& options = {});

enum class EmojiType
{
Expand All @@ -133,11 +130,11 @@ class Internet
* @returns Emoji.
*
* @code
* Internet::emoji() // "👑"
* Internet::emoji(EmojiType::Food) // "🍕"
* internet::emoji() // "👑"
* internet::emoji(EmojiType::Food) // "🍕"
* @endcode
*/
static std::string_view emoji(std::optional<EmojiType> type = std::nullopt);
std::string_view emoji(std::optional<EmojiType> type = std::nullopt);

/**
* @brief Verify that a given emoji is valid.
Expand All @@ -147,32 +144,32 @@ class Internet
* @returns true if emojiToCheck is found in one of the vectors, false otherwise.
*
* @code
* Internet::checkIfEmojiIsValid("👑") // true
* internet::checkIfEmojiIsValid("👑") // true
* @endcode
*/
static bool checkIfEmojiIsValid(const std::string& emojiToCheck);
bool checkIfEmojiIsValid(const std::string& emojiToCheck);

/**
* @brief Returns a random web protocol. Either `http` or `https`.
*
* @returns Web protocol.
*
* @code
* Internet::protocol() // "https"
* internet::protocol() // "https"
* @endcode
*/
static std::string_view protocol();
std::string_view protocol();

/**
* @brief Generates a random http method name.
*
* @returns Http method name.
*
* @code
* Internet::httpMethod() // "POST"
* internet::httpMethod() // "POST"
* @endcode
*/
static std::string_view httpMethod();
std::string_view httpMethod();

/**
* @brief Returns a random http status code.
Expand All @@ -182,44 +179,44 @@ class Internet
* @returns Http status code.
*
* @code
* Internet::httpStatusCode() // 500
* Internet::httpStatusCode(HttpStatusCodeType::success) // 201
* internet::httpStatusCode() // 500
* internet::httpStatusCode(HttpStatusCodeType::success) // 201
* @endcode
*/
static unsigned httpStatusCode(std::optional<HttpResponseType> responseType = std::nullopt);
unsigned httpStatusCode(std::optional<HttpResponseType> responseType = std::nullopt);

/**
* @brief Generates a random http request header.
*
* @returns Http request header.
*
* @code
* Internet::httpRequestHeader() // "Authorization"
* internet::httpRequestHeader() // "Authorization"
* @endcode
*/
static std::string_view httpRequestHeader();
std::string_view httpRequestHeader();

/**
* @brief Generates a random http response header.
*
* @returns Http response header.
*
* @code
* Internet::httpResponseHeader() // "Location"
* internet::httpResponseHeader() // "Location"
* @endcode
*/
static std::string_view httpResponseHeader();
std::string_view httpResponseHeader();

/**
* @brief Generates a random http media type.
*
* @returns Http media type.
*
* @code
* Internet::httpMediaType() // "application/json"
* internet::httpMediaType() // "application/json"
* @endcode
*/
static std::string_view httpMediaType();
std::string_view httpMediaType();

/**
* @brief Returns a string containing randomized ipv4 address of the given class.
Expand All @@ -229,11 +226,11 @@ class Internet
* @return String representation of the ipv4 address.
*
* @code
* Internet::ipv4() // "192.168.0.1"
* Internet::ipv4(IPv4Class::classA) // "10.0.0.1"
* internet::ipv4() // "192.168.0.1"
* internet::ipv4(IPv4Class::classA) // "10.0.0.1"
* @endcode
*/
static std::string ipv4(const IPv4Class& ipv4class = IPv4Class::C);
std::string ipv4(const IPv4Class& ipv4class = IPv4Class::C);

/**
* @brief Returns a string containing randomized ipv4 address based on given base address and mask.
Expand All @@ -248,11 +245,11 @@ class Internet
* @return std::string representation of the ipv4 address.
*
* @code
* Internet::ipv4({255.0.0.0}, {10.100.100.100}) // "10.128.17.1"
* Internet::ipv4({255.255.128.0}, {129.168.255.0}) // "192.168.128.10"
* internet::ipv4({255.0.0.0}, {10.100.100.100}) // "10.128.17.1"
* internet::ipv4({255.255.128.0}, {129.168.255.0}) // "192.168.128.10"
* @endcode
*/
static std::string ipv4(const std::array<unsigned int, 4>& baseIpv4Address,
std::string ipv4(const std::array<unsigned int, 4>& baseIpv4Address,
const std::array<unsigned int, 4>& generationMask);

/**
Expand All @@ -261,10 +258,10 @@ class Internet
* @return String representation of the ipv6 address.
*
* @code
* Internet::ipv6() // "269f:1230:73e3:318d:842b:daab:326d:897b"
* internet::ipv6() // "269f:1230:73e3:318d:842b:daab:326d:897b"
* @endcode
*/
static std::string ipv6();
std::string ipv6();

/**
* @brief Returns a generated random mac address.
Expand All @@ -274,21 +271,21 @@ class Internet
* @return A generated random mac address.
*
* @code
* Internet::mac() // "2d:10:34:2f:ac:ac"
* internet::mac() // "2d:10:34:2f:ac:ac"
* @endcode
*/
static std::string mac(const std::string& sep = ":");
std::string mac(const std::string& sep = ":");

/**
* @brief Generates a random port.
*
* @return Port.
*
* @code
* Internet::port() // 5432
* internet::port() // 5432
* @endcode
*/
static unsigned port();
unsigned port();

/**
* @brief Generates a random url.
Expand All @@ -298,43 +295,43 @@ class Internet
* @return Http(s) url.
*
* @code
* Internet::url() // "https://slow-timer.info"
* internet::url() // "https://slow-timer.info"
* @endcode
*/
static std::string url(const WebProtocol& webProtocol = WebProtocol::Https);
std::string url(const WebProtocol& webProtocol = WebProtocol::Https);

/**
* @brief Generates a random domain name.
*
* @return Domain name.
*
* @code
* Internet::domainName() // "slow-timer.info"
* internet::domainName() // "slow-timer.info"
* @endcode
*/
static std::string domainName();
std::string domainName();

/**
* @brief Generates a random domain word.
*
* @return Domain word.
*
* @code
* Internet::domainWord() // "close-reality"
* internet::domainWord() // "close-reality"
* @endcode
*/
static std::string domainWord();
std::string domainWord();

/**
* @brief Generates a random domain suffix.
*
* @return Domain suffix.
*
* @code
* Internet::domainSuffix() // "com"
* internet::domainSuffix() // "com"
* @endcode
*/
static std::string_view domainSuffix();
std::string_view domainSuffix();

/**
* @brief Generates a random username.
Expand All @@ -344,9 +341,8 @@ class Internet
* @return Username.
*
* @code
* Internet::anonymousUsername() // "profusebrother", "richad", "powerfuldifferential"
* internet::anonymousUsername() // "profusebrother", "richad", "powerfuldifferential"
* @endcode
*/
static std::string anonymousUsername(unsigned maxLength);
};
std::string anonymousUsername(unsigned maxLength);
}
2 changes: 1 addition & 1 deletion src/modules/git/Git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ std::string commitEntry(std::optional<unsigned> dateYears, std::optional<unsigne
const auto firstName = static_cast<std::string>(Person::firstName(country));
const auto lastName = static_cast<std::string>(Person::lastName(country));

entry += "\nAuthor: " + firstName + " " + lastName + " " + Internet::email(firstName, lastName) + "\nDate: ";
entry += "\nAuthor: " + firstName + " " + lastName + " " + internet::email(firstName, lastName) + "\nDate: ";

if (dateYears)
{
Expand Down
Loading

0 comments on commit e329131

Please sign in to comment.