This repository has been archived by the owner on Mar 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
180 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BAT_ADS_ISSUERS_INFO_H_ | ||
#define BAT_ADS_ISSUERS_INFO_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "bat/ads/export.h" | ||
#include "bat/ads/issuer_info.h" | ||
|
||
namespace ads { | ||
|
||
struct ADS_EXPORT IssuersInfo { | ||
IssuersInfo(); | ||
IssuersInfo(const IssuersInfo& info); | ||
~IssuersInfo(); | ||
|
||
const std::string ToJson() const; | ||
bool FromJson(const std::string& json); | ||
|
||
std::vector<IssuerInfo> issuers; | ||
}; | ||
|
||
} // namespace ads | ||
|
||
#endif // BAT_ADS_ISSUERS_INFO_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ads/issuer_info.h" | ||
|
||
namespace ads { | ||
|
||
IssuerInfo::IssuerInfo() : | ||
name(""), | ||
public_key("") {} | ||
|
||
IssuerInfo::IssuerInfo(const IssuerInfo& info) : | ||
name(info.name), | ||
public_key(info.public_key) {} | ||
|
||
IssuerInfo::~IssuerInfo() = default; | ||
|
||
} // namespace ads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ads/issuers_info.h" | ||
|
||
#include "json_helper.h" | ||
|
||
namespace ads { | ||
|
||
IssuersInfo::IssuersInfo() : | ||
issuers({}) {} | ||
|
||
IssuersInfo::IssuersInfo(const IssuersInfo& info) : | ||
issuers(info.issuers) {} | ||
|
||
IssuersInfo::~IssuersInfo() = default; | ||
|
||
const std::string IssuersInfo::ToJson() const { | ||
std::string json; | ||
SaveToJson(*this, &json); | ||
return json; | ||
} | ||
|
||
bool IssuersInfo::FromJson(const std::string& json) { | ||
rapidjson::Document document; | ||
document.Parse(json.c_str()); | ||
|
||
if (document.HasParseError()) { | ||
return false; | ||
} | ||
|
||
std::vector<IssuerInfo> issuers = {}; | ||
if (document.HasMember("issuers")) { | ||
for (const auto& issuer : document["issuers"].GetArray()) { | ||
IssuerInfo info; | ||
info.name = issuer["name"].GetString(); | ||
info.public_key = issuer["public_key"].GetString(); | ||
|
||
issuers.push_back(info); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void SaveToJson(JsonWriter* writer, const IssuersInfo& info) { | ||
writer->StartObject(); | ||
|
||
writer->String("issuers"); | ||
writer->StartArray(); | ||
for (const auto& issuer : info.issuers) { | ||
writer->StartObject(); | ||
|
||
writer->String("name"); | ||
writer->String(issuer.name.c_str()); | ||
|
||
writer->String("public_key"); | ||
writer->String(issuer.public_key.c_str()); | ||
|
||
writer->EndObject(); | ||
} | ||
writer->EndArray(); | ||
|
||
writer->EndObject(); | ||
} | ||
|
||
} // namespace ads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.