Skip to content
This repository has been archived by the owner on Mar 6, 2019. It is now read-only.

Confirmations #106

Merged
merged 14 commits into from
Jan 18, 2019
3 changes: 3 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ source_set("ads") {
"src/client.cc",
"src/client_state.cc",
"src/math_helper.cc",
"src/error_helper.cc",
"src/locale_helper.cc",
"src/search_providers.cc",
"src/string_helper.cc",
"src/time_helper.cc",
"src/json_helper.cc",
"src/uri_helper.cc",
"src/bat/ads/ad_info.cc",
"src/bat/ads/issuer_info.cc",
"src/bat/ads/issuers_info.cc",
"src/bat/ads/notification_info.cc",
"src/bat/ads/client_info.cc",
"src/bat/ads/url_components.cc",
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ message(STATUS "URI Parser dependency")
FetchContent_Declare(
URIParserProject
GIT_REPOSITORY [email protected]:uriparser/uriparser.git
GIT_TAG master
GIT_TAG uriparser-0.9.0
)

FetchContent_GetProperties(URIParserProject)
Expand Down Expand Up @@ -92,6 +92,8 @@ message(STATUS "BAT Native Ads")
set(SOURCES
"${PROJECT_SOURCE_DIR}/src/bat/ads/ad_info.cc"
"${PROJECT_SOURCE_DIR}/src/bat/ads/client_info.cc"
"${PROJECT_SOURCE_DIR}/src/bat/ads/issuer_info.cc"
"${PROJECT_SOURCE_DIR}/src/bat/ads/issuers_info.cc"
"${PROJECT_SOURCE_DIR}/src/bat/ads/notification_info.cc"
"${PROJECT_SOURCE_DIR}/src/bat/ads/url_components.cc"
"${PROJECT_SOURCE_DIR}/src/ads.cc"
Expand All @@ -105,6 +107,7 @@ set(SOURCES
"${PROJECT_SOURCE_DIR}/src/client_state.cc"
"${PROJECT_SOURCE_DIR}/src/json_helper.cc"
"${PROJECT_SOURCE_DIR}/src/math_helper.cc"
"${PROJECT_SOURCE_DIR}/src/error_helper.cc"
"${PROJECT_SOURCE_DIR}/src/locale_helper.cc"
"${PROJECT_SOURCE_DIR}/src/search_providers.cc"
"${PROJECT_SOURCE_DIR}/src/string_helper.cc"
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ bundle-schema.json

`catalog-schema.json` and `bundle-schema.json` are JSON Schemas which specify the JSON-based format to define the structure of the JSON data for validation, documentation, and interaction control. It provides the contract for the JSON data and how that data can be modified.

## Build

mkdir -p build && cd build
cmake ..
make

## API

### Native
Expand Down Expand Up @@ -68,7 +74,7 @@ void TabUpdated(
const int32_t tab_id,
const std::string& url,
const bool is_active,
const bool is_incognito);
const bool is_incognito)
```

`TabClosed` should be called to record when a browser tab is closed
Expand Down Expand Up @@ -175,11 +181,6 @@ void LoadUserModelForLocale(
const std::string GenerateUUID() const
```

`GetSSID` should return the network SSID or an empty string if not available
```
const std::string GetSSID() const
```

`IsForeground` should return `true` if the browser is in the foreground otherwise returns `false`
```
bool IsForeground() const
Expand All @@ -195,14 +196,19 @@ bool IsNotificationsAvailable() const
void ShowNotification(std::unique_ptr<NotificationInfo> info)
```

`CanShowAd` should return `true` if Confirmations is ready to show the ad otherwise returns `false`
`SetCatalogIssuers` should notify that the catalog issuers have changed
```
bool CanShowAd(const AdInfo& ad_info)
void SetCatalogIssuers(std::unique_ptr<IssuersInfo> info)
```

`IsConfirmationsReadyToShowAds` should return `true` if Confirmations is ready to show ads otherwise returns `false`
```
bool IsConfirmationsReadyToShowAds()
```

`AdSustained` should be called to inform Confirmations that an ad was sustained
```
void AdSustained(const AdInfo& ad_info)
void AdSustained(std::unique_ptr<NotificationInfo> info)
```

`SetTimer` should create a timer to trigger after the time offset specified in seconds. If the timer was created successfully a unique identifier should be returned, otherwise returns `0`
Expand All @@ -215,12 +221,6 @@ uint32_t SetTimer(const uint64_t time_offset)
void KillTimer(uint32_t timer_id)
```

`OnCatalogIssuersChanged` should notify that the catalog issuers have changed
```
void OnCatalogIssuersChanged(
const std::vector<IssuerInfo>& issuers);
```

`URLRequest` should start a URL request
```
void URLRequest(
Expand Down
5 changes: 4 additions & 1 deletion include/bat/ads/ad_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vector>

#include "bat/ads/export.h"
#include "bat/ads/result.h"

namespace ads {

Expand All @@ -18,7 +19,9 @@ struct ADS_EXPORT AdInfo {
~AdInfo();

const std::string ToJson() const;
bool FromJson(const std::string& json);
Result FromJson(
const std::string& json,
std::string* error_description = nullptr);

std::string creative_set_id;
std::string campaign_id;
Expand Down
3 changes: 3 additions & 0 deletions include/bat/ads/ads.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class ADS_EXPORT Ads {
// Should be called to remove all cached history
virtual void RemoveAllHistory() = 0;

// Should be called to get the region, i.e. US
virtual std::string GetRegion() = 0;

// Should be called when the user changes the operating system's locale, i.e.
// en, en_US or en_GB.UTF-8 unless the operating system restarts the app
virtual void ChangeLocale(const std::string& locale) = 0;
Expand Down
19 changes: 7 additions & 12 deletions include/bat/ads/ads_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
#include <functional>

#include "bat/ads/ad_info.h"
#include "bat/ads/issuer_info.h"
#include "bat/ads/issuers_info.h"
#include "bat/ads/bundle_state.h"
#include "bat/ads/client_info.h"
#include "bat/ads/export.h"
#include "bat/ads/notification_info.h"
#include "bat/ads/url_components.h"
#include "bat/ads/result.h"

namespace ads {

Expand All @@ -35,11 +36,6 @@ enum ADS_EXPORT URLRequestMethod {
POST = 2
};

enum ADS_EXPORT Result {
SUCCESS,
FAILED
};

class ADS_EXPORT LogStream {
public:
virtual ~LogStream() = default;
Expand Down Expand Up @@ -110,12 +106,15 @@ class ADS_EXPORT AdsClient {
// Should show a notification
virtual void ShowNotification(std::unique_ptr<NotificationInfo> info) = 0;

// Should notify that the catalog issuers have changed
virtual void SetCatalogIssuers(std::unique_ptr<IssuersInfo> info) = 0;

// Should return true if Confirmations is ready to show ad otherwise returns
// false
virtual bool CanShowAd(const AdInfo& ad_info) = 0;
virtual bool IsConfirmationsReadyToShowAds() = 0;

// Should be called to inform Confirmations that an ad was sustained
virtual void AdSustained(const NotificationInfo& info) = 0;
virtual void AdSustained(std::unique_ptr<NotificationInfo> info) = 0;

// Should create a timer to trigger after the time offset specified in
// seconds. If the timer was created successfully a unique identifier should
Expand All @@ -125,10 +124,6 @@ class ADS_EXPORT AdsClient {
// Should destroy the timer associated with the specified timer identifier
virtual void KillTimer(uint32_t timer_id) = 0;

// Should notify that the catalog issuers have changed
virtual void OnCatalogIssuersChanged(
const std::vector<IssuerInfo>& issuers) = 0;

// Should start a URL request
virtual void URLRequest(
const std::string& url,
Expand Down
5 changes: 4 additions & 1 deletion include/bat/ads/bundle_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ struct BundleState {
~BundleState();

const std::string ToJson() const;
bool FromJson(const std::string& json, const std::string& jsonSchema);
Result FromJson(
const std::string& json,
const std::string& json_schema,
std::string* error_description = nullptr);

std::string catalog_id;
uint64_t catalog_version;
Expand Down
5 changes: 4 additions & 1 deletion include/bat/ads/client_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "bat/ads/export.h"
#include "bat/ads/client_info_platform_type.h"
#include "bat/ads/result.h"

namespace ads {

Expand All @@ -18,7 +19,9 @@ struct ADS_EXPORT ClientInfo {
~ClientInfo();

const std::string ToJson() const;
bool FromJson(const std::string& json);
Result FromJson(
const std::string& json,
std::string* error_description = nullptr);

const std::string GetPlatformName() const;

Expand Down
20 changes: 6 additions & 14 deletions include/bat/ads/issuer_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@

#include <string>

namespace ads {

struct IssuerInfo {
IssuerInfo() :
name(""),
public_key("") {}
#include "bat/ads/export.h"

explicit IssuerInfo(const std::string& public_key) :
name(""),
public_key(public_key) {}

IssuerInfo(const IssuerInfo& info) :
name(info.name),
public_key(info.public_key) {}
namespace ads {

~IssuerInfo() {}
struct ADS_EXPORT IssuerInfo {
IssuerInfo();
IssuerInfo(const IssuerInfo& info);
~IssuerInfo();

std::string name;
std::string public_key;
Expand Down
33 changes: 33 additions & 0 deletions include/bat/ads/issuers_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* 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"
#include "bat/ads/result.h"

namespace ads {

struct ADS_EXPORT IssuersInfo {
IssuersInfo();
IssuersInfo(const IssuersInfo& info);
~IssuersInfo();

const std::string ToJson() const;
Result FromJson(
const std::string& json,
std::string* error_description = nullptr);

std::string public_key;
std::vector<IssuerInfo> issuers;
};

} // namespace ads

#endif // BAT_ADS_ISSUERS_INFO_H_
5 changes: 4 additions & 1 deletion include/bat/ads/notification_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>

#include "bat/ads/export.h"
#include "bat/ads/result.h"

namespace ads {

Expand All @@ -17,7 +18,9 @@ struct ADS_EXPORT NotificationInfo {
~NotificationInfo();

const std::string ToJson() const;
bool FromJson(const std::string& json);
Result FromJson(
const std::string& json,
std::string* error_description = nullptr);

std::string creative_set_id;
std::string category;
Expand Down
19 changes: 19 additions & 0 deletions include/bat/ads/result.h
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/. */

#ifndef BAT_ADS_RESULT_H_
#define BAT_ADS_RESULT_H_

#include "bat/ads/export.h"

namespace ads {

enum ADS_EXPORT Result {
SUCCESS,
FAILED
};

} // namespace ads

#endif // BAT_ADS_RESULT_H_
5 changes: 4 additions & 1 deletion include/bat/ads/url_components.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>

#include "bat/ads/export.h"
#include "bat/ads/result.h"

namespace ads {

Expand All @@ -17,7 +18,9 @@ struct ADS_EXPORT UrlComponents {
~UrlComponents();

const std::string ToJson() const;
bool FromJson(const std::string& json);
Result FromJson(
const std::string& json,
std::string* error_description = nullptr);

std::string url;
std::string scheme;
Expand Down
Loading