Skip to content

Commit

Permalink
Merge pull request #8244 from /issues/14687
Browse files Browse the repository at this point in the history
Refactor hardcoded catalog version to use a const
  • Loading branch information
tmancey authored Mar 16, 2021
2 parents 697587f + 667c87e commit 27d8468
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions vendor/bat-native-ads/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ source_set("ads") {
"src/bat/ads/internal/catalog/catalog_type_info.h",
"src/bat/ads/internal/catalog/catalog_util.cc",
"src/bat/ads/internal/catalog/catalog_util.h",
"src/bat/ads/internal/catalog/catalog_version.h",
"src/bat/ads/internal/client/client.cc",
"src/bat/ads/internal/client/client.h",
"src/bat/ads/internal/client/client_info.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "bat/ads/internal/bundle/bundle.h"
#include "bat/ads/internal/catalog/catalog.h"
#include "bat/ads/internal/catalog/catalog_issuers_info.h"
#include "bat/ads/internal/catalog/catalog_version.h"
#include "bat/ads/internal/logging.h"
#include "bat/ads/internal/server/ads_server_util.h"
#include "bat/ads/internal/time_formatting_util.h"
Expand Down Expand Up @@ -61,7 +62,7 @@ void AdServer::Fetch() {
DCHECK(!is_processing_);

BLOG(1, "Get catalog");
BLOG(2, "GET /v7/catalog");
BLOG(2, "GET /v" << kCurrentCatalogVersion << "/catalog");

is_processing_ = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "bat/ads/internal/ad_server/get_catalog_url_request_builder.h"

#include "base/strings/stringprintf.h"
#include "bat/ads/internal/catalog/catalog.h"
#include "bat/ads/internal/catalog/catalog_version.h"
#include "bat/ads/internal/server/ads_server_util.h"

namespace ads {
Expand All @@ -14,7 +16,7 @@ GetCatalogUrlRequestBuilder::GetCatalogUrlRequestBuilder() = default;

GetCatalogUrlRequestBuilder::~GetCatalogUrlRequestBuilder() = default;

// GET /v7/catalog
// GET /v#/catalog

UrlRequestPtr GetCatalogUrlRequestBuilder::Build() {
UrlRequestPtr url_request = UrlRequest::New();
Expand All @@ -27,7 +29,8 @@ UrlRequestPtr GetCatalogUrlRequestBuilder::Build() {
///////////////////////////////////////////////////////////////////////////////

std::string GetCatalogUrlRequestBuilder::BuildUrl() const {
return base::StringPrintf("%s/v7/catalog", server::GetHost().c_str());
return base::StringPrintf("%s/v%d/catalog", server::GetHost().c_str(),
kCurrentCatalogVersion);
}

} // namespace ads
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "bat/ads/internal/catalog/catalog_state.h"

#include "base/time/time.h"
#include "bat/ads/internal/catalog/catalog_version.h"
#include "bat/ads/internal/json_helper.h"
#include "bat/ads/internal/logging.h"
#include "url/gurl.h"
Expand Down Expand Up @@ -42,7 +43,7 @@ Result CatalogState::FromJson(const std::string& json,
new_catalog_id = document["catalogId"].GetString();

new_version = document["version"].GetInt();
if (new_version != 7) {
if (new_version != kCurrentCatalogVersion) {
return FAILED;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* 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_INTERNAL_CATALOG_CATALOG_VERSION_H_
#define BAT_ADS_INTERNAL_CATALOG_CATALOG_VERSION_H_

namespace ads {

const int kCurrentCatalogVersion = 7;

} // namespace ads

#endif // BAT_ADS_INTERNAL_CATALOG_CATALOG_VERSION_H_

0 comments on commit 27d8468

Please sign in to comment.