Skip to content

Commit b945014

Browse files
authored
Merge pull request #7453 from /issues/13213
GetState should call ads-serve endpoint
2 parents 89ed47d + ad1331b commit b945014

File tree

7 files changed

+122
-4
lines changed

7 files changed

+122
-4
lines changed

components/brave_ads/test/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ source_set("brave_ads_unit_tests") {
8080
"//brave/vendor/bat-native-ads/src/bat/ads/internal/privacy/unblinded_tokens/unblinded_tokens_unittest_util.h",
8181
"//brave/vendor/bat-native-ads/src/bat/ads/internal/rpill/rpill_unittest.cc",
8282
"//brave/vendor/bat-native-ads/src/bat/ads/internal/security/security_util_unittest.cc",
83+
"//brave/vendor/bat-native-ads/src/bat/ads/internal/server/ads_serve_server_util_unittest.cc",
8384
"//brave/vendor/bat-native-ads/src/bat/ads/internal/server/ads_server_util_unittest.cc",
8485
"//brave/vendor/bat-native-ads/src/bat/ads/internal/server/confirmations_server_util_unittest.cc",
8586
"//brave/vendor/bat-native-ads/src/bat/ads/internal/server/rewards_server_util_unittest.cc",

vendor/bat-native-ads/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ source_set("ads") {
439439
"src/bat/ads/internal/search_engine/search_providers.h",
440440
"src/bat/ads/internal/security/security_util.cc",
441441
"src/bat/ads/internal/security/security_util.h",
442+
"src/bat/ads/internal/server/ads_serve_server_util.cc",
443+
"src/bat/ads/internal/server/ads_serve_server_util.h",
442444
"src/bat/ads/internal/server/ads_server_util.cc",
443445
"src/bat/ads/internal/server/ads_server_util.h",
444446
"src/bat/ads/internal/server/confirmations_server_util.cc",

vendor/bat-native-ads/src/bat/ads/internal/ad_targeting/geographic/subdivision/get_subdivision_url_request_builder.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "bat/ads/internal/ad_targeting/geographic/subdivision/get_subdivision_url_request_builder.h"
77

88
#include "base/strings/stringprintf.h"
9-
#include "bat/ads/internal/server/ads_server_util.h"
9+
#include "bat/ads/internal/server/ads_serve_server_util.h"
1010

1111
namespace ads {
1212
namespace ad_targeting {
@@ -16,7 +16,7 @@ GetSubdivisionUrlRequestBuilder::GetSubdivisionUrlRequestBuilder() = default;
1616

1717
GetSubdivisionUrlRequestBuilder::~GetSubdivisionUrlRequestBuilder() = default;
1818

19-
// GET /v5/getstate
19+
// GET /v1/getstate
2020

2121
UrlRequestPtr GetSubdivisionUrlRequestBuilder::Build() {
2222
UrlRequestPtr url_request = UrlRequest::New();
@@ -29,7 +29,7 @@ UrlRequestPtr GetSubdivisionUrlRequestBuilder::Build() {
2929
///////////////////////////////////////////////////////////////////////////////
3030

3131
std::string GetSubdivisionUrlRequestBuilder::BuildUrl() const {
32-
return base::StringPrintf("%s/v5/getstate", server::GetHost().c_str());
32+
return base::StringPrintf("%s/v1/getstate", serve::server::GetHost().c_str());
3333
}
3434

3535
} // namespace geographic

vendor/bat-native-ads/src/bat/ads/internal/ad_targeting/geographic/subdivision/subdivision_targeting.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool SubdivisionTargeting::ShouldAutoDetect() const {
166166

167167
void SubdivisionTargeting::Fetch() {
168168
BLOG(1, "Fetch subdivision target");
169-
BLOG(2, "GET /v5/getstate");
169+
BLOG(2, "GET /v1/getstate");
170170

171171
GetSubdivisionUrlRequestBuilder url_request_builder;
172172
UrlRequestPtr url_request = url_request_builder.Build();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "bat/ads/internal/server/ads_serve_server_util.h"
7+
8+
#include "bat/ads/ads.h"
9+
10+
namespace ads {
11+
namespace serve {
12+
namespace server {
13+
14+
namespace {
15+
16+
const char kProductionHost[] = "https://ads-serve.brave.com";
17+
const char kStagingHost[] = "https://ads-serve.bravesoftware.com";
18+
const char kDevelopmentHost[] = "https://ads-serve.brave.software";
19+
20+
} // namespace
21+
22+
std::string GetHost() {
23+
switch (g_environment) {
24+
case Environment::PRODUCTION: {
25+
return kProductionHost;
26+
}
27+
28+
case Environment::STAGING: {
29+
return kStagingHost;
30+
}
31+
32+
case Environment::DEVELOPMENT: {
33+
return kDevelopmentHost;
34+
}
35+
}
36+
}
37+
38+
} // namespace server
39+
} // namespace serve
40+
} // namespace ads
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#ifndef BAT_ADS_INTERNAL_SERVER_ADS_SERVE_SERVER_UTIL_H_
7+
#define BAT_ADS_INTERNAL_SERVER_ADS_SERVE_SERVER_UTIL_H_
8+
9+
#include <string>
10+
11+
namespace ads {
12+
namespace serve {
13+
namespace server {
14+
15+
std::string GetHost();
16+
17+
} // namespace server
18+
} // namespace serve
19+
} // namespace ads
20+
21+
#endif // BAT_ADS_INTERNAL_SERVER_ADS_SERVE_SERVER_UTIL_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "bat/ads/internal/server/ads_serve_server_util.h"
7+
8+
#include "testing/gtest/include/gtest/gtest.h"
9+
#include "bat/ads/internal/unittest_util.h"
10+
11+
// npm run test -- brave_unit_tests --filter=BatAds*
12+
13+
namespace ads {
14+
15+
TEST(BatAdsServeServerUtilTest,
16+
Production) {
17+
// Arrange
18+
SetEnvironment(Environment::PRODUCTION);
19+
20+
// Act
21+
const std::string host = serve::server::GetHost();
22+
23+
// Assert
24+
const std::string expected_host = "https://ads-serve.brave.com";
25+
EXPECT_EQ(expected_host, host);
26+
}
27+
28+
TEST(BatAdsServeServerUtilTest,
29+
Staging) {
30+
// Arrange
31+
SetEnvironment(Environment::STAGING);
32+
33+
// Act
34+
const std::string host = serve::server::GetHost();
35+
36+
// Assert
37+
const std::string expected_host = "https://ads-serve.bravesoftware.com";
38+
EXPECT_EQ(expected_host, host);
39+
}
40+
41+
TEST(BatAdsServeServerUtilTest,
42+
Development) {
43+
// Arrange
44+
SetEnvironment(Environment::DEVELOPMENT);
45+
46+
// Act
47+
const std::string host = serve::server::GetHost();
48+
49+
// Assert
50+
const std::string expected_host = "https://ads-serve.brave.software";
51+
EXPECT_EQ(expected_host, host);
52+
}
53+
54+
} // namespace ads

0 commit comments

Comments
 (0)