Adding yt api

This commit is contained in:
Maxime St-Pierre 2018-02-08 22:34:17 -05:00
parent af29ad39f9
commit 7693b834ca
21 changed files with 236 additions and 64 deletions

View file

@ -121,8 +121,9 @@ class Controller
$router->any('/youtube/thanks', 'AcquisitionActions::executeThanks');
$router->any('/youtube/sub', 'AcquisitionActions::executeYouTubeSub');
$router->any('/youtube/{campaignId:c}?', 'AcquisitionActions::executeYouTube');
$router->any('/yt2', 'AcquisitionActions::executeYT2');
$router->any('/youtube', 'AcquisitionActions::executeYT2');
$router->post('/youtube/token', 'AcquisitionActions::executeYoutubeToken');
$router->any('/youtube/status/{token}', 'AcquisitionActions::executeYoutubeStatus');
$router->get('/verify/{token}', 'AcquisitionActions::executeVerify');
$router->get('/news/category/{category}', 'ContentActions::executePostCategoryFilter');

View file

@ -9,15 +9,13 @@ class AcquisitionActions extends Actions
public static function executeYouTubeSub()
{
if (!Request::isPost())
{
if (!Request::isPost()) {
return Controller::redirect('/youtube');
}
$email = Request::getPostParam('email');
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
Session::setFlash('error', 'Please enter a valid email.');
return Controller::redirect('/youtube');
}
@ -33,8 +31,7 @@ class AcquisitionActions extends Actions
public static function executeYouTube(string $campaignId = '')
{
$template = 'acquisition/youtube' . ($campaignId ? '-' . $campaignId : '');
if (!View::exists($template))
{
if (!View::exists($template)) {
return NavActions::execute404();
}
return [$template];
@ -42,7 +39,7 @@ class AcquisitionActions extends Actions
public static function executeYT2()
{
return ['acquisition/yt2', ['_no_layout' => true]];
return ['acquisition/yt2'];
}
public static function executeVerify(string $token)
@ -50,5 +47,64 @@ class AcquisitionActions extends Actions
return ['acquisition/verify', ['token' => $token]];
}
public static function executeYoutubeToken()
{
return ['acquisition/youtube_token', ['_no_layout' => true]];
}
public static function executeYoutubeStatus(string $token)
{
return ['acquisition/youtube_status', ['token' => $token]];
}
public static function actionYoutubeToken(string $email, string $desired_lbry_channel_name, string $youtube_channel_id)
{
$email_is_valid = static::email_verification($email);
$desired_lbry_channel_name_is_valid = static::lbry_channel_verification($desired_lbry_channel_name);
$youtube_channel_id_is_valid = static::youtube_channel_verification($youtube_channel_id);
if ($email_is_valid && $desired_lbry_channel_name_is_valid && $youtube_channel_id_is_valid) {
$token = LBRY::newYoutube($email, $youtube_channel_id, $desired_lbry_channel_name);
if ($token['error'] === null) {
$url = "/youtube/status/" . $token['data']['status_token'];
Controller::redirect($url);
} else {
$url = "/yt2?error=true&error_message=" . $token['error'];
Controller::redirect($url);
}
} else {
$url = "/yt2?error=true";
Controller::redirect($url);
}
}
protected static function email_verification($email)
{
if (preg_match('/\S+@\S+\.\S+/', $email)) {
return true;
} else {
return false;
}
}
protected static function youtube_channel_verification($youtube_channel_id)
{
if (preg_match('/^UC[A-Za-z0-9_-]{22}$/', $youtube_channel_id)) {
return true;
} else {
return false;
}
}
protected static function lbry_channel_verification($lbry_channel)
{
if (preg_match('/[1-z]+/', $lbry_channel)) {
return true;
} else {
return false;
}
}
}

View file

@ -29,4 +29,20 @@ class LBRY
{
return Curl::post(static::getApiUrl('/list/unsubscribe'), ['email' => $email], ['json_response' => true]);
}
// Register new youtube sync
public static function newYoutube($email, $channel_id, $channel_name)
{
return Curl::post(static::getApiUrl('/yt/new'), ['email' => $email, 'youtube_channel_id' => $channel_id,'desired_lbry_channel_name' => $channel_name], ['json_response' => true]);
}
// Check the sync status
public static function statusYoutube($status_token)
{
return Curl::post(static::getApiUrl('/yt/status'), ['status_token' => $status_token], ['json_response' => true]);
}
public static function youtubeReward(){
return CurlWithCache::post(static::getApiUrl('/yt/rewards'),[], ['cache' => 3600, 'json_response' => true ]);
}
}

View file

@ -24,7 +24,7 @@ class Response
'/js/jquery-2.1.3.min.js',
'/js/global.js'
],
'css' => []
'css' => ['/css/all.css']
],
$headers = [],
$headersSent = false,
@ -106,11 +106,24 @@ class Response
static::$assets['js'][$src] = $src;
}
public static function addCssAsset($src)
{
static::$assets['css'][$src] = $src;
}
public static function getJsAssets()
{
return static::$assets['js'];
}
public static function getCssAssets()
{
return static::$assets['css'];
}
public static function setCssAssets(array $assets = []){
static::$assets['css'] = $assets;
}
public static function setGzipResponseContent($gzip = true)
{
static::$gzipResponseContent = $gzip;

View file

@ -0,0 +1,18 @@
<?php Response::setMetaDescription('YouTuber? Take back control! LBRY allows publication on your terms. It\'s open-source, decentralized, and gives you 100% of the profit.') ?>
<?php Response::setMetaTitle(__('YouTubers! Take back control.')) ?>
<?php echo View::render('nav/_header', ['isDark' => false]) ?>
<main>
<?php $status = LBRY::statusYoutube($token);
?>
<center>
LBRY channel name: <?php echo $status['data']['lbry_channel_name'];?>
</center>
<center>
Youtube Sync status: <?php echo $status['data']['status'];?>
</center>
<center>
Expected Reward: <?php echo $status['data']['expected_reward'];?>
</center>
<main/>

View file

@ -0,0 +1,3 @@
<?php
AcquisitionActions::actionYoutubeToken($_POST['email_address'], $_POST['desired_lbry_channel_name'], $_POST['youtube_channel_url']);
?>

View file

@ -1,26 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>LBRY for YouTubers</title>
<meta name="description" content="">
<meta property="og:type" content="website">
<meta property="og:locale" content="en">
<meta property="og:site_name" content="LBRY">
<meta property="og:title" content="LBRY for YouTubers">
<meta property="og:description" content="">
<meta property="og:url" content="https://lbry.io/youtube">
<meta property="og:image" content="">
<meta property="og:image:width" content="">
<meta property="og:image:height" content="">
<link href="/css/yt2.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="images/favicon.ico">
</head>
<body>
<?php
Response::setCssAssets(['/css/yt2.css']);
Response::addJsAsset('/js/yt2/TweenMax.min.js');
Response::addJsAsset('/js/yt2/ScrollToPlugin.min.js');
Response::addJsAsset('/js/yt2/app.js');
Response::addJsAsset('/js/yt2/FormValidation.js');
$reward = LBRY::youtubeReward();
?>
<main>
<header class="header">
<div class="inner">
<div class="left">
@ -66,20 +52,32 @@
</section>
<section class="claim section">
<div class="inner">
<div class="content">
<?php
if (isset($_GET['error'])): echo "<div>" . "The following error occurred: ". $_GET['error_message'] . " For support please send an email to hello@lbry.io" . "</div>";
endif;?>
<div class="zigzag"></div>
<h1>Own your identity. For real this time.</h1>
<form>
<div class="form-inner">
<form id="youtube_claim" method="post" action="/youtube/token">
<div class="form-inner" >
<div class="block" hidden id="lbry_error">LBRY channel name is not valid or blank</div>
<div class="block">
<input type="text" placeholder="yourchannel" />
<label>@</label>
<input id="lbry_channel_name" type="text" name="desired_lbry_channel_name" placeholder="Desired LBRY channel name" />
</div>
<div class="block">
<input type="submit" value="Claim now" />
</div>
</div>
<div class="block" hidden id="email_error">Email is not valid or blank</div>
<div class="block">
<input hidden id="email" type="text" name="email_address" placeholder="Your Email" />
</div>
<div class="block" hidden id="youtube_url_error">Youtube id is not valid or blank</div>
<div class="block">
<input hidden id="youtube_url" type="text" name="youtube_channel_url" placeholder="Your Channel ID" />
</div>
</form>
<div class="block">
<input type="submit" value="Claim now" onClick="return submitDetailsForm()"/>
</div>
</div>
</div>
</section>
@ -171,22 +169,22 @@
</div>
<div class="line">
<p>1,000</p>
<p>250 <span></span></p>
<p><?php echo $reward['data']['1000']; ?><span></span></p>
<p></p>
</div>
<div class="line">
<p>10,000</p>
<p>1,000 <span></span></p>
<p><?php echo $reward['data']['10000']; ?><span></span></p>
<p></p>
</div>
<div class="line">
<p>100,000</p>
<p>2,500 <span></span></p>
<p><?php echo $reward['data']['100000']; ?> <span></span></p>
<p></p>
</div>
<div class="line">
<p>1,000,000</p>
<p>7,000 <span></span></p>
<p><?php echo $reward['data']['1000000']; ?> <span></span></p>
<p></p>
</div>
</div>
@ -210,8 +208,4 @@
</div>
</section>
<div class="to-top"><span>to top</span></div>
<script type="text/javascript" src="/js/yt2/TweenMax.min.js"></script>
<script type="text/javascript" src="/js/yt2/ScrollToPlugin.min.js"></script>
<script type="text/javascript" src="/js/yt2/app.js"></script>
</body>
</html>
</main>

View file

@ -15,4 +15,4 @@
</div>
</section>
</main>
<?php echo View::render('nav/_footer') ?>
<?php echo View::render('nav/_footer') ?>

View file

@ -17,4 +17,4 @@
</div>
</section>
</main>
<?php echo View::render('nav/_footer') ?>
<?php echo View::render('nav/_footer') ?>

View file

@ -17,7 +17,7 @@
<?php js_start() ?>
$('#faq-filter-form').change(function() { $(this).submit(); });
<?php js_end() ?>
<?php foreach($postGroups as $category => $posts): ?>
<?php if (count($posts)): ?>
<h2><?php echo $categories[$category] ?></h2>

View file

@ -17,7 +17,7 @@
</div>
</div>
</header>
<section class="post-content">
<div class="content">
<?php echo $post->getContentHtml() ?>

View file

@ -9,4 +9,4 @@
</div>
</section>
</main>
<?php echo View::render('nav/_footer', ['showLearnFooter' => true]) ?>
<?php echo View::render('nav/_footer', ['showLearnFooter' => true]) ?>

View file

@ -50,4 +50,4 @@
</div>
</div>
</main>
<?php echo View::render('nav/_footer') ?>
<?php echo View::render('nav/_footer') ?>

View file

@ -13,7 +13,9 @@
<title><?php echo $title ?></title>
<link href='https://fonts.googleapis.com/css?family=Raleway:500,500italic,700' rel='stylesheet' type='text/css'>
<link href="/css/all.css" rel="stylesheet" type="text/css" />
<?php foreach(Response::getCssAssets() as $src): ?>
<link rel="stylesheet" type="text/css" href="<?php echo $src?>">
<?php endforeach ?>
<link rel="apple-touch-icon" sizes="60x60" href="/img/fav/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="114x114" href="/img/fav/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/img/fav/apple-touch-icon-120x120.png">

View file

@ -5,4 +5,4 @@
<p><?php echo $error ?? __('page.badrequest_details') ?></p>
<?php echo View::render('nav/_errorFooter') ?>
</div>
</main>
</main>

View file

@ -5,4 +5,4 @@
<p>{{page.badmethod_details}}</p>
<?php echo View::render('nav/_errorFooter') ?>
</div>
</main>
</main>

View file

@ -176,7 +176,7 @@
Interested in contributing but not ready for commitment? We have a <a href="/faq/contributing">guide for contributors</a> to help you find other ways to get
involved. If none of that suits your fancy, join our <a href="https://chat.lbry.io">Discord chat</a> and we'll help you find something you'll love.
</p>
</div>
</section>
</main>

View file

@ -96,7 +96,7 @@
<p>Here is a sample key-value entry in the LBRY blockchain. Here, wonderfullife is the key, and the rest of the description is the value.</p>
<code class="code-bash"><span class="code-bash__prompt">$</span>lbrynet-cli resolve_name name=wonderfullife
<span class="code-bash__kw">wonderfullife</span> : {
<span class="code-bash__kw">title</span>: "Its a Wonderful Life",
<span class="code-bash__kw">description</span>: "An angel helps a compassionate but despairingly frustrated businessman by showing what life would have been like if he never existed.",
@ -311,7 +311,7 @@
<h4>Content Distribution</h4>
<p>Digital content distributors with server-client models are subject to the whims of internet service providers and hostile foreign governments. Traffic from the host servers can be throttled or halted altogether if the owners of cables and routers so choose. However, in case of the LBRY protocol content comes from anywhere and everywhere, and is therefore not so easily stifled. </p>
<p>Additionally, the market mechanisms of LBRY create a strong incentive for efficient distribution, which will save the costs of producers and ISPs alike. These properties, along with LBRYs infringement
<p>Additionally, the market mechanisms of LBRY create a strong incentive for efficient distribution, which will save the costs of producers and ISPs alike. These properties, along with LBRYs infringement
disincentivizing properties, make LBRY an appealing technology for large existing data or content distributors.</p>
<h4>Transaction Settlement</h4>
<p>While payments can be issued directly on the LBRY blockchain, the LBRY protocol encourages a volume of transactions that will not scale without usage of off-chain settlement.</p>

View file

@ -56,4 +56,4 @@
</div>
</main>
<?php echo View::render('nav/_footer', ['showLearnFooter' => $learnFooter ?? false]) ?>
<?php echo View::render('nav/_footer', ['showLearnFooter' => $learnFooter ?? false]) ?>

View file

@ -315,6 +315,8 @@ header .right a.github {
.claim .block {
position: relative;
float: left;
margin-top: 10px;
}
.claim input {
float: left;
@ -344,6 +346,11 @@ header .right a.github {
-moz-box-shadow: 0 0 10px 0 rgba(0,0,0,0.15);
box-shadow: 0 0 10px 0 rgba(0,0,0,0.15);
}
.error_form{
-webkit-box-shadow:inset 0px 0px 0px 2px red;
-moz-box-shadow:inset 0px 0px 0px 2px red;
box-shadow:inset 0px 0px 0px 2px red;
}
.claim label {
position: absolute;
top: 0;
@ -1116,4 +1123,4 @@ header .right a.github {
.how .step.three .text {
width: 90%;
}
}
}

View file

@ -0,0 +1,62 @@
function submitDetailsForm() {
$("#youtube_claim").submit(function (event) {
// get value from id
var lbry_channel_name = $.trim($('#lbry_channel_name').val());
var email = $.trim($('#email').val());
var youtube_url = $.trim($('#youtube_url').val());
// Make sure that the error message are hidden before trying to validate value
$('#lbry_error').hide();
$('#email_error').hide();
$('#youtube_url_error').hide();
// If the lbry name is invalid or blank stop the post request
if(!validateLBRYName(lbry_channel_name) || lbry_channel_name === '') {
$('#lbry_channel_name').addClass('error_form');
$('#lbry_error').show();
event.preventDefault();
}
// Show the other field if the LBRY channel name field is validated once
else{
// Check only if the two fields
if ($('#email').is(":visible") && $('#youtube_url').is(":visible")) {
// If the email is invalid or blank stop the post request
if (!validateEmail(email) || email === '') {
$('#email').addClass('error_form');
$('#email_error').show();
event.preventDefault();
}
// If the youtube url is invalid or blank stop the post request
if (!validateYoutubeChannelUrl(youtube_url) || youtube_url === '') {
$('#youtube_url').addClass('error_form');
$('#youtube_url_error').show();
event.preventDefault();
}
}
else{
event.preventDefault();
}
$('#youtube_url').show();
$('#email').show();
}
});
}
function validateEmail(email) {
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
function validateLBRYName(lbry_channel_name){
var re = /[1-z]+/;
return re.test(lbry_channel_name);
}
function validateYoutubeChannelUrl(youtube_channel_url){
var re = /^UC[A-Za-z0-9_-]{22}$/;
return re.test(youtube_channel_url)
}