Skip to content

Commit

Permalink
Adds support for Vimeo
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jun 25, 2019
1 parent 4ba742c commit a7d7204
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ test("brave_unit_tests") {
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/reddit_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/twitch_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/twitter_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/vimeo_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/youtube_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper_unittest.h",
Expand Down
2 changes: 2 additions & 0 deletions vendor/bat-native-ledger/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ source_set("ledger") {
"src/bat/ledger/internal/media/twitch.cc",
"src/bat/ledger/internal/media/twitter.h",
"src/bat/ledger/internal/media/twitter.cc",
"src/bat/ledger/internal/media/vimeo.h",
"src/bat/ledger/internal/media/vimeo.cc",
"src/bat/ledger/internal/media/youtube.h",
"src/bat/ledger/internal/media/youtube.cc",
"src/bat/ledger/internal/wallet/balance.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ std::string Media::GetLinkType(const std::string& url,
first_party_url,
referrer);
}
if (type.empty()) {
type = braveledger_media::MediaVimeo::GetLinkType(url);
}

return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "bat/ledger/internal/media/reddit.h"
#include "bat/ledger/internal/media/twitch.h"
#include "bat/ledger/internal/media/twitter.h"
#include "bat/ledger/internal/media/vimeo.h"
#include "bat/ledger/internal/media/youtube.h"
#include "bat/ledger/ledger.h"

Expand Down Expand Up @@ -60,6 +61,7 @@ class Media {
std::unique_ptr<braveledger_media::Twitch> media_twitch_;
std::unique_ptr<braveledger_media::Twitter> media_twitter_;
std::unique_ptr<braveledger_media::Reddit> media_reddit_;
std::unique_ptr<braveledger_media::Vimeo> media_vimeo_;
};

} // namespace braveledger_media
Expand Down
38 changes: 38 additions & 0 deletions vendor/bat-native-ledger/src/bat/ledger/internal/media/vimeo.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright (c) 2019 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/. */

#include "bat/ledger/internal/bat_helper.h"
#include "bat/ledger/internal/ledger_impl.h"
#include "bat/ledger/internal/media/vimeo.h"

using std::placeholders::_1;
using std::placeholders::_2;

namespace braveledger_media {

Vimeo::Vimeo(bat_ledger::LedgerImpl* ledger):
ledger_(ledger) {
}

Vimeo::~Vimeo() {
}

// static
std::string Vimeo::GetLinkType(const std::string& url) {
std::string type = VIMEO_MEDIA_TYPE;
return type;
}

void Vimeo::ProcessMedia(const std::map<std::string, std::string>& parts,
const ledger::VisitData& visit_data) {

}

void Vimeo::ProcessActivityFromUrl(uint64_t window_id,
const ledger::VisitData& visit_data) {

}

} // namespace braveledger_media
46 changes: 46 additions & 0 deletions vendor/bat-native-ledger/src/bat/ledger/internal/media/vimeo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Copyright (c) 2019 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 BRAVELEDGER_MEDIA_VIMEO_H_
#define BRAVELEDGER_MEDIA_VIMEO_H_

#include <map>
#include <string>

#include "base/gtest_prod_util.h"
#include "bat/ledger/ledger.h"
#include "bat/ledger/internal/media/helper.h"

namespace bat_ledger {
class LedgerImpl;
}

namespace braveledger_media {

class Vimeo : public ledger::LedgerCallbackHandler {
public:
explicit Vimeo(bat_ledger::LedgerImpl* ledger);

~Vimeo() override;

void ProcessMedia(const std::map<std::string, std::string>& parts,
const ledger::VisitData& visit_data);

static std::string GetLinkType(const std::string& url);

void ProcessActivityFromUrl(uint64_t window_id,
const ledger::VisitData& visit_data);

private:

bat_ledger::LedgerImpl* ledger_; // NOT OWNED

// For testing purposes
friend class VimeoTest;
};

} // namespace braveledger_media

#endif // BRAVELEDGER_MEDIA_VIMEO_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2019 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/. */

#include "bat/ledger/internal/media/vimeo.h"
#include "bat/ledger/ledger.h"
#include "testing/gtest/include/gtest/gtest.h"

// npm run test -- brave_unit_tests --filter=VimeoTest.*

namespace braveledger_media {

class VimeoTest : public testing::Test {
};

TEST(VimeoTest, GetLinkType) {
// TODO(nejczdovc): change me
std::string result = Vimeo::GetLinkType("https://vimeo.com/video/32342");
ASSERT_EQ(result, "vimeo");
}

} // namespace braveledger_media
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define TWITCH_MEDIA_TYPE "twitch"
#define TWITTER_MEDIA_TYPE "twitter"
#define REDDIT_MEDIA_TYPE "reddit"
#define VIMEO_MEDIA_TYPE "vimeo"
#define YOUTUBE_PROVIDER_URL "https://www.youtube.com/oembed"
#define TWITCH_PROVIDER_URL "https://api.twitch.tv/v5/oembed"
#define YOUTUBE_TLD "youtube.com"
Expand Down

0 comments on commit a7d7204

Please sign in to comment.