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 May 10, 2019
1 parent 147edc7 commit bce4a22
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 @@ -116,6 +116,7 @@ test("brave_unit_tests") {
sources += [
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/helper_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/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 @@ -105,6 +105,8 @@ source_set("ledger") {
"src/bat/ledger/internal/media/helper.cc",
"src/bat/ledger/internal/media/twitch.h",
"src/bat/ledger/internal/media/twitch.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/ledger.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ std::string BatGetMedia::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 @@ -12,6 +12,7 @@

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

Expand Down Expand Up @@ -48,6 +49,7 @@ class BatGetMedia {
bat_ledger::LedgerImpl* ledger_; // NOT OWNED
std::unique_ptr<braveledger_media::MediaYouTube> media_youtube_;
std::unique_ptr<braveledger_media::MediaTwitch> media_twitch_;
std::unique_ptr<braveledger_media::MediaVimeo> media_vimeo_;
};

} // namespace braveledger_bat_get_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 {

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

MediaVimeo::~MediaVimeo() {
}

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

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

}

void MediaVimeo::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 MediaVimeo : public ledger::LedgerCallbackHandler {
public:
explicit MediaVimeo(bat_ledger::LedgerImpl* ledger);

~MediaVimeo() 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 MediaVimeoTest;
};

} // 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=MediaVimeoTest.*

namespace braveledger_media {

class MediaVimeoTest : public testing::Test {
};

TEST(MediaVimeoTest, GetLinkType) {
// TODO(nejczdovc): change me
std::string result = MediaVimeo::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 @@ -63,6 +63,7 @@

#define YOUTUBE_MEDIA_TYPE "youtube"
#define TWITCH_MEDIA_TYPE "twitch"
#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 bce4a22

Please sign in to comment.