From eab1c672383bbc9105904ac23c4420f766437105 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Mon, 20 Feb 2017 21:06:01 -0500 Subject: [PATCH 01/12] intermediate progress --- controller/Controller.class.php | 7 +- .../action/AcquisitionActions.class.php | 143 ----------- controller/action/DeveloperActions.class.php | 228 ++++++++++++++++++ lib/tools/Curl.class.php | 4 +- .../developer/_formCreditsPublish.php | 25 ++ view/template/developer/_formNew.php | 20 ++ view/template/developer/_quickstartApi.php | 35 +++ .../template/developer/_quickstartCredits.php | 35 +++ view/template/developer/_quickstartHome.php | 21 ++ .../template/developer/_quickstartInstall.php | 33 +++ .../developer-program.php | 2 +- view/template/developer/quickstart.php | 52 ++++ view/template/layout/basic.php | 2 +- view/template/page/quickstart.php | 135 ----------- view/template/page/quickstart_old.php | 63 +++++ view/template/page/what.php | 1 + web/scss/_blog.scss | 62 ++--- web/scss/_code.scss | 6 +- web/scss/_content.scss | 5 - web/scss/_global.scss | 1 + web/scss/_quickstart.scss | 98 ++++++++ web/scss/all.scss | 1 + 22 files changed, 660 insertions(+), 319 deletions(-) create mode 100644 controller/action/DeveloperActions.class.php create mode 100644 view/template/developer/_formCreditsPublish.php create mode 100644 view/template/developer/_formNew.php create mode 100644 view/template/developer/_quickstartApi.php create mode 100644 view/template/developer/_quickstartCredits.php create mode 100644 view/template/developer/_quickstartHome.php create mode 100644 view/template/developer/_quickstartInstall.php rename view/template/{acquisition => developer}/developer-program.php (94%) create mode 100644 view/template/developer/quickstart.php delete mode 100644 view/template/page/quickstart.php create mode 100644 view/template/page/quickstart_old.php create mode 100644 web/scss/_quickstart.scss diff --git a/controller/Controller.class.php b/controller/Controller.class.php index 7f42aead..d63841cd 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -89,9 +89,10 @@ class Controller $router->get(['/ios', 'get-ios'], 'DownloadActions::executeGet'); $router->get('/roadmap', 'ContentActions::executeRoadmap'); - $router->get('/developer-program', 'AcquisitionActions::executeDeveloperProgram'); - $router->post('/developer-program/post', 'AcquisitionActions::executeDeveloperProgramPost'); - $router->get('/developer-program/callback', 'AcquisitionActions::executeDeveloperProgramGithubCallback'); + $router->get('/quickstart/{step}?', 'DeveloperActions::executeQuickstart'); + $router->get('/developer-program', 'DeveloperActions::executeDeveloperProgram'); + $router->post('/developer-program/post', 'DeveloperActions::executeDeveloperProgramPost'); + $router->get('/developer-program/callback', 'DeveloperActions::executeDeveloperProgramGithubCallback'); $router->get(['/press-kit.zip', 'press-kit'], 'ContentActions::executePressKit'); diff --git a/controller/action/AcquisitionActions.class.php b/controller/action/AcquisitionActions.class.php index 114bdb0f..99ff45e5 100644 --- a/controller/action/AcquisitionActions.class.php +++ b/controller/action/AcquisitionActions.class.php @@ -2,8 +2,6 @@ class AcquisitionActions extends Actions { - const DEVELOPER_REWARD = 250; - public static function executeThanks() { return ['acquisition/thanks']; @@ -41,145 +39,4 @@ class AcquisitionActions extends Actions } return [$template]; } - - public static function executeDeveloperProgram() - { - return ['acquisition/developer-program', [ - 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), - 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), - 'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS) - ]]; - } - - public static function executeDeveloperProgramPost() - { - $walletAddress = trim(Request::getPostParam('wallet')); - Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress); - - if (!$walletAddress) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Please provide a wallet address.'); - } - elseif (!preg_match('/^b[1-9A-HJ-NP-Za-km-z]{33}$/', $walletAddress)) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid wallet address.'); - } - else - { - if (!Config::get('github_developer_credits_client_id')) - { - throw new Exception('no github client id'); - } - - $githubParams = [ - 'client_id' => Config::get('github_developer_credits_client_id'), - 'redirect_uri' => Request::getHostAndProto() . '/developer-program/callback', - 'scope' => 'user:email', - 'allow_signup' => false - ]; - return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($githubParams)); - } - return Controller::redirect('/developer-program'); - } - - public static function executeDeveloperProgramGithubCallback() - { - $code = Request::getParam('code'); - $walletAddress = Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS); - - if (!$walletAddress) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.'); - } - elseif (!$code) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.'); - } - else - { - $authResponseData = Curl::post('https://github.com/login/oauth/access_token', [ - 'code' => $code, - 'client_id' => Config::get('github_developer_credits_client_id'), - 'client_secret' => Config::get('github_developer_credits_client_secret') - ], [ - 'headers' => ['Accept: application/json'], - 'json_response' => true - ]); - - if (!$authResponseData || !isset($authResponseData['access_token'])) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.'); - } - elseif (isset($authResponseData['error_description'])) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']); - } - else - { - $accessToken = $authResponseData['access_token']; - $userResponseData = Curl::get('https://api.github.com/user', [], [ - 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio'], - 'json_response' => true - ]); - - if (date('Y-m-d', strtotime($userResponseData['created_at'])) > '2017-01-30') - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This GitHub account is too recent.'); - } - else - { - $lockName = 'github_dev_credits_write'; - $dataFile = ROOT_DIR . '/data/writeable/github_developer_credits'; - - $lock = Lock::getLock($lockName, true); // EXCLUSIVE LOCK. IF SENDING CREDITS IS SLOW, THIS COULD BLOCK USERS - - $existing = is_file($dataFile) ? json_decode(file_get_contents($dataFile), true) : []; - - if (isset($existing[$userResponseData['login']]) || isset($existing[$userResponseData['id']])) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'You already received credits.'); - } - else - { - $response = - Curl::post('http://localhost:5279/lbryapi', [ - 'method' => 'send_amount_to_address', - 'params' => [['amount' => 250, 'address' => $walletAddress]], - ], [ - 'json_data' => true, - 'json_response' => true, - ]); - - if ($response === [true]) - { - $existing[$userResponseData['id']] = [$userResponseData['email'], $walletAddress, date('Y-m-d H:i:s'), $userResponseData['login']]; - file_put_contents($dataFile, json_encode($existing)); - - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS, - 'Credits on their way to address ' . $walletAddress . ' for GitHub user ' . $userResponseData['login'] . '. It may take up to a minute for them to arrive.'); - } - else - { - if (isset($response['faultString']) && stripos($response['faultString'], 'InsufficientFundsError') !== false) - { - Slack::sendErrorIfProd('Github dev credits need a refill'); - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, - 'Our wallet is running low on funds. Please ping jeremy@lbry.io so he can refill it, then try again.'); - } - else - { - Slack::sendErrorIfProd('Error claiming github dev credits: ' . var_export($response, true)); - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, - 'Failed to send credits. This is an error on our side. Please email jeremy@lbry.io if it persists.'); - } - } - } - - Lock::freeLock($lock); - $lock = null; - } - } - } - return Controller::redirect('/developer-program'); - } } diff --git a/controller/action/DeveloperActions.class.php b/controller/action/DeveloperActions.class.php new file mode 100644 index 00000000..4d68de08 --- /dev/null +++ b/controller/action/DeveloperActions.class.php @@ -0,0 +1,228 @@ + 'Home', + 'install' => 'Installation', + 'api' => 'The API', + 'credits' => 'Credits' + ]; + $allSteps = array_keys($stepLabels); + $currentStep = $step ?: $allSteps[0]; + + $viewParams = [ + 'currentStep' => $currentStep, + 'stepLabels' => $stepLabels + ]; + + if ($currentStep !== 'all') + { + if (!isset($stepLabels[$currentStep])) + { + Controller::redirect('/quickstart'); + } + + $stepNum = array_flip($allSteps)[$currentStep]; + + $viewParams += [ + 'stepNum' => $stepNum, + 'prevStep' => $stepNum === 0 ? null : $allSteps[$stepNum - 1], + 'nextStep' => $stepNum + 1 >= count($allSteps) ? null : $allSteps[$stepNum + 1], + ]; + } + + return ['developer/quickstart', $viewParams]; + } + + public static function prepareQuickstartOnePartial(array $vars) + { + return $vars + [ + 'version' => '0.8.4' + ]; + } + + public static function executeDeveloperProgram() + { + return ['developer/developer-program', [ + 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), + 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), + 'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS) + ]]; + } + + public static function prepareFormNewPartial(array $vars) + { + return $vars + [ + 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), + 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), + 'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS) + ]; + } + + public static function prepareFormCreditsPublishPartial(array $vars) + { + return $vars + [ + 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), + 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), + 'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS) + ]; + } + + public static function executeDeveloperProgramPost() + { + $walletAddress = trim(Request::getPostParam('wallet')); + Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress); + + if (!$walletAddress) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Please provide a wallet address.'); + } + elseif (!preg_match('/^b[1-9A-HJ-NP-Za-km-z]{33}$/', $walletAddress)) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid wallet address.'); + } + else + { + if (!Config::get('github_developer_credits_client_id')) + { + throw new Exception('no github client id'); + } + + $githubParams = [ + 'client_id' => Config::get('github_developer_credits_client_id'), + 'redirect_uri' => Request::getHostAndProto() . '/developer-program/callback', + 'scope' => 'user:email public_repo', + 'allow_signup' => false + ]; + return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($githubParams)); + } + return Controller::redirect('/developer-program'); + } + + public static function executeDeveloperProgramGithubCallback() + { + $code = Request::getParam('code'); + $walletAddress = Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS); + + if (!$walletAddress) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.'); + } + elseif (!$code) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.'); + } + else + { + $authResponseData = Curl::post('https://github.com/login/oauth/access_token', [ + 'code' => $code, + 'client_id' => Config::get('github_developer_credits_client_id'), + 'client_secret' => Config::get('github_developer_credits_client_secret') + ], [ + 'headers' => ['Accept: application/json'], + 'json_response' => true + ]); + + if (!$authResponseData || !isset($authResponseData['access_token'])) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.'); + } + elseif (isset($authResponseData['error_description'])) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']); + } + else + { + $accessToken = $authResponseData['access_token']; + + $starResponseData = Curl::put('https://api.github.com/user/starred/lbryio/lbry', [], [ + 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio', 'Content-Length: 0'], + 'json_response' => true + ]); + + $userResponseData = Curl::get('https://api.github.com/user', [], [ + 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio'], + 'json_response' => true + ]); + + if (!$userResponseData || !$userResponseData['created_at'] || $starResponseData !== []) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Received unexpected response from GitHub. Perhaps authorization was revoked?'); + } + elseif(date('Y-m-d', strtotime($userResponseData['created_at'])) > '2017-01-30') + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This GitHub account is too recent.'); + } + else + { + $lockName = 'github_dev_credits_write'; + $dataFile = ROOT_DIR . '/data/writeable/github_developer_credits'; + + $lock = Lock::getLock($lockName, true); // EXCLUSIVE LOCK. IF SENDING CREDITS IS SLOW, THIS COULD BLOCK USERS + + $existing = is_file($dataFile) ? json_decode(file_get_contents($dataFile), true) : []; + + if (isset($existing[$userResponseData['login']]) || isset($existing[$userResponseData['id']])) + { + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'You (' . $userResponseData['login'] . ') already received credits.'); + } + else + { + try + { + $response = + Curl::post('http://localhost:5279/lbryapi', [ + 'method' => 'send_amount_to_address', + 'params' => [['amount' => 250, 'address' => $walletAddress]], + ], [ + 'json_data' => true, + 'json_response' => true, + ]); + } + catch (Exception $e) + { + $response = null; + } + + $response = [true]; + + if ($response === [true]) + { + $existing[$userResponseData['id']] = [$userResponseData['email'], $walletAddress, date('Y-m-d H:i:s'), $userResponseData['login']]; + file_put_contents($dataFile, json_encode($existing)); + + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS, + 'Credits on their way to address ' . $walletAddress . ' for GitHub user ' . $userResponseData['login'] . '. It may take up to a minute for them to arrive.'); + } + elseif (is_array($response) && (isset($response['faultString']) && stripos($response['faultString'], 'InsufficientFundsError') !== false)) + { + Slack::sendErrorIfProd('Github dev credits need a refill'); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, + 'Our wallet is running low on funds. Please ping jeremy@lbry.io so he can refill it, then try again.'); + } + else + { + Slack::sendErrorIfProd($response === null ? + 'Error connecting to LBRY API via cURL' : + 'Error of unknown origin in sending Github dev credits' . var_export($response, true) + ); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Failed to send credits. This is an error on our side. Please email jeremy@lbry.io if it persists.'); + Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, + 'Failed to send credits. This is an error on our side. Please email jeremy@lbry.io if it persists.'); + } + } + + Lock::freeLock($lock); + $lock = null; + } + } + } + return Controller::redirect('/developer-program'); + } +} diff --git a/lib/tools/Curl.class.php b/lib/tools/Curl.class.php index 8602a1b9..95efef12 100644 --- a/lib/tools/Curl.class.php +++ b/lib/tools/Curl.class.php @@ -69,8 +69,8 @@ class Curl $ch = curl_init(); -// curl_setopt($ch, CURLOPT_VERBOSE, true); -// curl_setopt($ch, CURLOPT_STDERR, fopen(sys_get_temp_dir().'/curl-debug-'.date('Ymd-His'), 'w+')); + curl_setopt($ch, CURLOPT_VERBOSE, true); + curl_setopt($ch, CURLOPT_STDERR, fopen(sys_get_temp_dir().'/curl-debug-'.date('Ymd-His'), 'w+')); if ($ch === false || $ch === null) { diff --git a/view/template/developer/_formCreditsPublish.php b/view/template/developer/_formCreditsPublish.php new file mode 100644 index 00000000..b632b655 --- /dev/null +++ b/view/template/developer/_formCreditsPublish.php @@ -0,0 +1,25 @@ +
+

Receive Credits

+ +
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
\ No newline at end of file diff --git a/view/template/developer/_formNew.php b/view/template/developer/_formNew.php new file mode 100644 index 00000000..d7b72721 --- /dev/null +++ b/view/template/developer/_formNew.php @@ -0,0 +1,20 @@ +
+

Receive Credits

+ +
+ +
+ +
+ +
+ +
+
+
+ +
+
We require a GitHub account to prevent abuse. This will record your email (no spam) and mark you as interested in the lbry repo. + No GitHub account? No problem! Join our Slack channel and post an introduction in #tech.
+
\ No newline at end of file diff --git a/view/template/developer/_quickstartApi.php b/view/template/developer/_quickstartApi.php new file mode 100644 index 00000000..385df56b --- /dev/null +++ b/view/template/developer/_quickstartApi.php @@ -0,0 +1,35 @@ +

The API

+

+ When running, the LBRY daemon provides a JSON-RPC server running at https://localhost:5279/lbryapi. +

+

+ It can be accessed via cURL or any other utility capable of making HTTPS GET and POST requests. So, basically anything, including possibly your toaster. +

+

+ To verify the LBRY daemon is running correctly, let's try looking up a name: +

+$curl 'http://localhost:5279/lbryapi' --data '{"method":"resolve_name","params":[{"name":"what"}]}' +[ + { + "ver": "0.0.3", + "description": "What is LBRY? An introduction with Alex Tabarrok", + "license": "LBRY inc", + "title": "What is LBRY?", + "author": "Samuel Bryan", + "language": "en", + "sources": { + "lbry_sd_hash": "d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b" + }, + "content_type": "video\/mp4", + "nsfw": false, + "thumbnail": "https:\/\/s3.amazonaws.com\/files.lbry.io\/logo.png" + } +] +

Above, we called the method resolve_name for the URL lbry://what. This returned the metadata associated with the URL.

+

Now let's download it. This time we're going to call the method get with the same parameters.

+$curl 'http://localhost:5279/lbryapi' --data '{"method":"get","params":[{"name":"what"}]}' +["d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"] +

The LBRY API consists about 50 calls, all related to discovering, distributing, and purchasing content. View the full API documentation.

+

You can also list all of the commands available by calling the help command.

+$curl 'http://localhost:5279/lbryapi' --data '{"method":"help"}' + \ No newline at end of file diff --git a/view/template/developer/_quickstartCredits.php b/view/template/developer/_quickstartCredits.php new file mode 100644 index 00000000..e9279b9a --- /dev/null +++ b/view/template/developer/_quickstartCredits.php @@ -0,0 +1,35 @@ +

Credits

+

So far, everything we've done with LBRY has been free. However, some actions, such as reserving a name or purchasing paid content, require credits.

+

To receive credits, first generate a wallet address:

+$curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_new_address","params":[]}' +["bbFxRyWCFRkA9YcuuZD8nE7XTLUxYnddTs"] +

Enter this address in the form below and we'll send you 50 credits.

+
+ +
+

Next, confirm you've received your credits by calling wallet_balance:

+$curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_balance"}' +[50.00000000] +

Publishing

+

Publishing to LBRY is just as easy as everything else! If you publish something, we'll send you an additional 200 LBC for further use.

+

Not sure what to publish? We recommend your favorite picture or home video. Or just grab something from here.

+$curl 'http://localhost:5279/lbryapi' --data '{"method":"publish", "params": [{ + "name": "electricsheep", + "file_path": "\\home\kauffj\\Desktop\\electric-sheep.mp4", + "bid": 1, + "metadata": {"what goes here": "who knows if you do not work for LBRY, certainly you will not be able to figure it out from response messages or API docs" +}]}' +[whatever this response looks like] +
+ +
+

You Did It! What's Next?

+

+ Start building something awesome! LBRY works as a discovery and distribution backend for everything from films to CAD files. +

+

+ Join our Slack Channel to interact with LBRY developers and other community members. Please visit the #dev room (note: this is not a default channel). +

+

+ Visit our GitHub page to view the source code or report issues. +

\ No newline at end of file diff --git a/view/template/developer/_quickstartHome.php b/view/template/developer/_quickstartHome.php new file mode 100644 index 00000000..c44f04a5 --- /dev/null +++ b/view/template/developer/_quickstartHome.php @@ -0,0 +1,21 @@ +
Quickstart Home
+

+ LBRY is an open-source "fat" protocol, providing + decentralized content discovery and distribution.

+

+ In just a few minutes, you will have: +

+ +

+ Begin the Guide +

+
Not a guide lover? Here it is all on one page.
\ No newline at end of file diff --git a/view/template/developer/_quickstartInstall.php b/view/template/developer/_quickstartInstall.php new file mode 100644 index 00000000..2fc7f4e9 --- /dev/null +++ b/view/template/developer/_quickstartInstall.php @@ -0,0 +1,33 @@ +

Download

+ + + + + + + + + + + + + + + +
macOS Linux Windows
Download .dmgDownload .debDownload .msi
+

+ If you prefer to compile from source or are not on one of the above operating systems, follow + this guide. +

+

Run

+

+ Launch the deamon to run as a background process: +

+

+ $lbrynet-daemon +

+

While running, the daemon will provide a JSON-RPC interface on localhost. We'll learn how to interact with that next.

+macOS and Windows do not currently bundle the daemon separately. Just launch the full app and the API will still be available. This will be resolved in v0.9. + */ ?> +
The first time you run the daemon, it must catch-up with most recent blockheaders. This can take a few minutes.
\ No newline at end of file diff --git a/view/template/acquisition/developer-program.php b/view/template/developer/developer-program.php similarity index 94% rename from view/template/acquisition/developer-program.php rename to view/template/developer/developer-program.php index 621396a6..116e809f 100644 --- a/view/template/acquisition/developer-program.php +++ b/view/template/developer/developer-program.php @@ -5,7 +5,7 @@

Developer Program

-

All developers with a GitHub account prior to January 31st, 2017 are eligible for free credits.

+

All developers with a GitHub account prior to January 31st, 2017 are eligible for free credits.

To claim your credits, enter a wallet address in the form below and authenticate with GitHub.

We will store your GitHub username and email address, but nothing else. diff --git a/view/template/developer/quickstart.php b/view/template/developer/quickstart.php new file mode 100644 index 00000000..a3356c3f --- /dev/null +++ b/view/template/developer/quickstart.php @@ -0,0 +1,52 @@ + + + + false, 'isAbsolute' => false]) ?> +

+
+
+ +
+ +

Quickstart

+
+ +
+
+ +
+
+ + 0): ?> +
+

Quickstart:

+
+
    + + $stepLabel): ?> +
  1. + +
  2. + +
+
+
+ +
+ +
+ Next: » +
+ +
+ +
+ array_keys($stepLabels)[1] + ]) ?> +
+ +
+
+
+ \ No newline at end of file diff --git a/view/template/layout/basic.php b/view/template/layout/basic.php index 6a6f254d..26064251 100644 --- a/view/template/layout/basic.php +++ b/view/template/layout/basic.php @@ -12,7 +12,7 @@ 'LBRY' ?> <?php echo $title ?> - + diff --git a/view/template/page/quickstart.php b/view/template/page/quickstart.php deleted file mode 100644 index db368513..00000000 --- a/view/template/page/quickstart.php +++ /dev/null @@ -1,135 +0,0 @@ - - - - false, 'isAbsolute' => false]) ?> -
-

Quickstart

-

This step-by-step guide will have you running LBRY and interacting with the API in just a few minutes.

-

This guide is for programmers and other technical users. For consumer usage of LBRY, please go here.

-

What's Covered

-
    -
  1. Installation
  2. -
  3. Running LBRY
  4. -
  5. The API
  6. -
  7. Credits
  8. -
  9. Community & Issues
  10. -
-
-

1. Installation

-

The easiest way to install LBRY is to use a pre-packaged binary. We provide binaries for Windows, macOS, and Debian-based Linux.

- - - - - - - - - - - - - - - -
macOS Linux Windows
Download DMGDownload DEBDownload MSI
-

- If you prefer to compile from source or are not on one of the above operating systems, follow - this guide. -

-
-
-

2. Running LBRY

-

- Launch the deamon to run as a background process: -

-

- $lbrynet-daemon -

-

The first time you run the daemon, it must catch-up with most recent blockheaders. This can take several minutes.

-
macOS and Windows do not currently bundle the daemon separately. Just launch the full app and the API will still be available. This will be resolved in v0.9.
-
-
-

3. The API

-

- When running, the LBRY daemon provides a JSON-RPC server running at https://localhost:5279/lbryapi. -

-

- It can be accessed via cURL or any other utility capable of making HTTPS GET and POST requests. -

-

- To verify the LBRY daemon is running correctly and responding to requests, run: -

- $curl 'http://localhost:5279/lbryapi' --data '{"method":"status","params":[]}' -[ - { - "connection_status": { - "message": "No connection problems detected", - "code": "connected" - }, - "is_first_run": false, - "is_running": true, - "blocks_behind": 0, - "startup_status": { - "message": "Started lbrynet", - "code": "started" - } - } -] -

This makes it easy to interact with the LBRY API in the programming language of your choice. Here's another example:

- $curl 'http://localhost:5279/lbryapi' --data '{"method":"resolve_name","params":[{"name":"what"}]}' -[ - { - "ver": "0.0.3", - "description": "What is LBRY? An introduction with Alex Tabarrok", - "license": "LBRY inc", - "title": "What is LBRY?", - "author": "Samuel Bryan", - "language": "en", - "sources": { - "lbry_sd_hash": "d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b" - }, - "content_type": "video\/mp4", - "nsfw": false, - "thumbnail": "https:\/\/s3.amazonaws.com\/files.lbry.io\/logo.png" - } -] -

LBRY can be used to build everything from a censorship-proof image host, to a store for 3D printing files, to distribute large files or datasets, or use cases even we can't imagine!

-

View Full API Documentation

-
-
-

4. Getting Credits

-

Many actions, such as reserving a name or purchasing paid content, require credits.

-

To receive credits, first generate a wallet address:

- $curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_new_address","params":[]}' -["bbFxRyWCFRkA9YcuuZD8nE7XTLUxYnddTs"] -

Use this address to get credits in one of two ways:

-
-
-

4a) Receive Free Credits

-

- All developers with a valid GitHub account are eligible to receive free credits. -

- Claim Your Free Credits -
-
-

4b) Purchase Credits

-

- Credits can be bought on a variety of exchanges. - After purchasing, send them to the address generated above. -

-
-
-
-
-

5. Community & Issues

-

- Join our Slack Channel to interact with LBRY developers and other community members. Please visit the #dev room (note: this is not a default channel). -

-

- Visit our GitHub page to view the source code or report issues. -

-
-
-
- diff --git a/view/template/page/quickstart_old.php b/view/template/page/quickstart_old.php new file mode 100644 index 00000000..efb4fa1c --- /dev/null +++ b/view/template/page/quickstart_old.php @@ -0,0 +1,63 @@ + + + + false, 'isAbsolute' => false]) ?> +
+
+
+

Set Up

+

This step-by-step guide will have you running LBRY and interacting with the API in just a few minutes.

+

This guide is for programmers and other technical users. For consumer usage of LBRY, please go here.

+

What's Covered

+
    +
  1. Installation
  2. +
  3. Running LBRY
  4. +
  5. The API
  6. +
  7. Credits
  8. +
  9. Community & Issues
  10. +
+
+

1. Installation

+

The easiest way to install LBRY is to use a pre-packaged binary. We provide binaries for Windows, macOS, and Debian-based Linux.

+ + + + + + + + + + + + + + + +
macOS Linux Windows
Download DMGDownload DEBDownload MSI
+

+ If you prefer to compile from source or are not on one of the above operating systems, follow + this guide. +

+
+
+

2. Running LBRY

+

+ Launch the deamon to run as a background process: +

+

+ $lbrynet-daemon +

+

The first time you run the daemon, it must catch-up with most recent blockheaders. This can take several minutes.

+
macOS and Windows do not currently bundle the daemon separately. Just launch the full app and the API will still be available. This will be resolved in v0.9.
+
+
+ +
+ + +
+
+ +
+ diff --git a/view/template/page/what.php b/view/template/page/what.php index c707f4e8..9c9831cd 100644 --- a/view/template/page/what.php +++ b/view/template/page/what.php @@ -96,6 +96,7 @@

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.

$lbrynet-cli resolve_name name=wonderfullife + wonderfullife : { title: "It’s a Wonderful Life", description: "An angel helps a compassionate but despairingly frustrated businessman by showing what life would have been like if he never existed.", diff --git a/web/scss/_blog.scss b/web/scss/_blog.scss index cf2dc66d..f183d126 100644 --- a/web/scss/_blog.scss +++ b/web/scss/_blog.scss @@ -109,7 +109,7 @@ margin-top: $spacing-vertical; } } -.post-content table, table.content +.post-content table, table.post-content-table { margin-bottom: $spacing-vertical; word-wrap: break-word; @@ -135,7 +135,6 @@ font-size: 0.9em; padding: $spacing-vertical/4+1 8px $spacing-vertical/4-2; text-align: left; - border-bottom: 1px solid #e2e2e2; img { vertical-align: text-bottom; @@ -145,37 +144,11 @@ { vertical-align: middle; } - tr.thead:not(:first-child) th - { - border-top: 1px solid #e2e2e2; - } tfoot td { padding: $spacing-vertical / 2 8px; font-size: .85em; } - tbody - { - tr - { - &:nth-child(even):not(.odd) - { - background-color: #f4f4f4; - } - &:nth-child(odd):not(.even) - { - background-color: white; - } - &.thead - { - background: none; - } - td - { - border: 0 none; - } - } - } &:last-child { @@ -187,6 +160,39 @@ width: 100%; } } +.post-content table +{ + thead th, > tr:first-child th + { + border-bottom: 1px solid #e2e2e2; + } + tr.thead:not(:first-child) th + { + border-top: 1px solid #e2e2e2; + } + tbody + { + tr + { + &.thead + { + background: none; + } + td + { + border: 0 none; + } + &:nth-child(even):not(.odd) + { + background-color: #f4f4f4; + } + &:nth-child(odd):not(.even) + { + background-color: white; + } + } + } +} .post-author-spotlight { diff --git a/web/scss/_code.scss b/web/scss/_code.scss index a28c2197..980c1cd3 100644 --- a/web/scss/_code.scss +++ b/web/scss/_code.scss @@ -7,9 +7,13 @@ pre, code code { padding: 3px 5px; - font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, monospace, serif; + font-family: $font-mono; color: darken($color-primary, 10%); } +.code-plain +{ + font-family: $font-mono; +} pre { > code { diff --git a/web/scss/_content.scss b/web/scss/_content.scss index 2bf7c601..dbbeb68b 100644 --- a/web/scss/_content.scss +++ b/web/scss/_content.scss @@ -128,11 +128,6 @@ &:last-child { margin-bottom: $spacing-vertical / 2; } padding-left: 2em; counter-reset: li-counter; - &.table-of-contents > li - { - line-height: 2em; - &:before { top: -0.1em; } - } > li { position: relative; diff --git a/web/scss/_global.scss b/web/scss/_global.scss index a19b3600..7b7a9d00 100644 --- a/web/scss/_global.scss +++ b/web/scss/_global.scss @@ -20,6 +20,7 @@ $max-post-content-width: 800px; $font-header: 'Raleway', sans-serif; $font-body: 'Raleway', sans-serif; +$font-mono: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, monospace, serif; $font-size-h1: 2.4em; $font-size-h2: 2.0em; diff --git a/web/scss/_quickstart.scss b/web/scss/_quickstart.scss new file mode 100644 index 00000000..65e15895 --- /dev/null +++ b/web/scss/_quickstart.scss @@ -0,0 +1,98 @@ +@import "global"; + +.quickstart +{ + max-width: 860px; +} + +.quickstart__table +{ + margin: 0 auto $spacing-vertical; + td, th + { + border-right: 1px dotted #eee; + padding: 4px 20px; + &:last-child + { + border-right: 0 none; + } + } +} + +.quickstart__section +{ + margin-bottom: $spacing-vertical * 3; +} + +.quickstart__claim-form +{ + margin: $spacing-vertical * 2 0; +} + +.quickstart__progress-bar +{ + margin: $spacing-vertical * 3 80px; + background: #ddd; + display: flex; + height: 16px; + list-style: none; + padding: 0; + position: relative; + + > li { + flex: auto; + list-style: none; + position: relative; + + &:first-child { + max-width: 0; + + > a { + // arbitrary values + // since % won't work + right: -30px; + width: 60px; + } + } + + &:before { + background: #ddd; + border-radius: 50%; + content: ""; + display: block; + height: 24px; + right: -12px; + position: absolute; + top: -4px; + width: 24px; + } + } + a { + cursor: pointer; + color: #ccc; + padding: 4px 0; + position: absolute; + right: -25%; + text-align: center; + text-decoration: underline; + top: -36px; + width: 50%; + } + $color-indicator: #777; + .completed { + background: lighten($color-indicator, 10%); + + &:before { + background: lighten($color-indicator, 10%); + } + } + .active { + a { font-weight: bold; } + background: lighten($color-indicator, 10%); + + &:before { + background: lighten($color-indicator, 16%); + box-shadow: 0 1px 1px rgba(0,0,0,0.3); + } + } +} \ No newline at end of file diff --git a/web/scss/all.scss b/web/scss/all.scss index f6020391..3efb75b5 100644 --- a/web/scss/all.scss +++ b/web/scss/all.scss @@ -15,4 +15,5 @@ @import "blog"; @import "bounty"; @import "roadmap"; +@import "quickstart"; @import "social"; \ No newline at end of file From 4a94d376d5f425fce043bd9e0b3b370f1b9d9811 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Mon, 20 Feb 2017 21:08:48 -0500 Subject: [PATCH 02/12] small fixes --- view/template/developer/_quickstartCredits.php | 2 ++ view/template/developer/_quickstartInstall.php | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/view/template/developer/_quickstartCredits.php b/view/template/developer/_quickstartCredits.php index e9279b9a..50d71085 100644 --- a/view/template/developer/_quickstartCredits.php +++ b/view/template/developer/_quickstartCredits.php @@ -23,6 +23,8 @@
+

Try the UI

+

LBRY comes with a UI so that normal people can use it to. You can download it here.

You Did It! What's Next?

Start building something awesome! LBRY works as a discovery and distribution backend for everything from films to CAD files. diff --git a/view/template/developer/_quickstartInstall.php b/view/template/developer/_quickstartInstall.php index 2fc7f4e9..bbacaec4 100644 --- a/view/template/developer/_quickstartInstall.php +++ b/view/template/developer/_quickstartInstall.php @@ -9,9 +9,9 @@ - Download .dmg - Download .deb - Download .msi + Download .dmg + Download .deb + Download .msi From 32ca0d7f94f15df7f122eb6bfb66c5a564e23201 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Tue, 21 Feb 2017 21:44:25 -0500 Subject: [PATCH 03/12] porting to internal apis --- controller/Session.class.php | 2 +- controller/action/DeveloperActions.class.php | 117 +++---------------- lib/thirdparty/LBRY.class.php | 19 +++ view/template/developer/_quickstartHome.php | 2 +- view/template/social/_listDev.php | 3 + 5 files changed, 37 insertions(+), 106 deletions(-) create mode 100644 lib/thirdparty/LBRY.class.php diff --git a/controller/Session.class.php b/controller/Session.class.php index 4291690f..148600b8 100644 --- a/controller/Session.class.php +++ b/controller/Session.class.php @@ -1,6 +1,6 @@ '0.8.4' + 'usdValue' => static::DEVELOPER_REWARD * LBRY::getLBCtoUSDRate() ]; } @@ -102,7 +102,8 @@ class DeveloperActions extends Actions ]; return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($githubParams)); } - return Controller::redirect('/developer-program'); + + return Controller::redirect(Request::getReferrer('/quickstart/credits')); } public static function executeDeveloperProgramGithubCallback() @@ -120,109 +121,17 @@ class DeveloperActions extends Actions } else { - $authResponseData = Curl::post('https://github.com/login/oauth/access_token', [ - 'code' => $code, - 'client_id' => Config::get('github_developer_credits_client_id'), - 'client_secret' => Config::get('github_developer_credits_client_secret') + $newUserUrl = LBRY::getApiUrl('/user/new_developer'); + $lbryApiResponseData = Curl::post($newUserUrl, [ + 'github_code' => $code ], [ - 'headers' => ['Accept: application/json'], - 'json_response' => true +// 'json_response' => true ]); - - if (!$authResponseData || !isset($authResponseData['access_token'])) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.'); - } - elseif (isset($authResponseData['error_description'])) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']); - } - else - { - $accessToken = $authResponseData['access_token']; - - $starResponseData = Curl::put('https://api.github.com/user/starred/lbryio/lbry', [], [ - 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio', 'Content-Length: 0'], - 'json_response' => true - ]); - - $userResponseData = Curl::get('https://api.github.com/user', [], [ - 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio'], - 'json_response' => true - ]); - - if (!$userResponseData || !$userResponseData['created_at'] || $starResponseData !== []) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Received unexpected response from GitHub. Perhaps authorization was revoked?'); - } - elseif(date('Y-m-d', strtotime($userResponseData['created_at'])) > '2017-01-30') - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This GitHub account is too recent.'); - } - else - { - $lockName = 'github_dev_credits_write'; - $dataFile = ROOT_DIR . '/data/writeable/github_developer_credits'; - - $lock = Lock::getLock($lockName, true); // EXCLUSIVE LOCK. IF SENDING CREDITS IS SLOW, THIS COULD BLOCK USERS - - $existing = is_file($dataFile) ? json_decode(file_get_contents($dataFile), true) : []; - - if (isset($existing[$userResponseData['login']]) || isset($existing[$userResponseData['id']])) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'You (' . $userResponseData['login'] . ') already received credits.'); - } - else - { - try - { - $response = - Curl::post('http://localhost:5279/lbryapi', [ - 'method' => 'send_amount_to_address', - 'params' => [['amount' => 250, 'address' => $walletAddress]], - ], [ - 'json_data' => true, - 'json_response' => true, - ]); - } - catch (Exception $e) - { - $response = null; - } - - $response = [true]; - - if ($response === [true]) - { - $existing[$userResponseData['id']] = [$userResponseData['email'], $walletAddress, date('Y-m-d H:i:s'), $userResponseData['login']]; - file_put_contents($dataFile, json_encode($existing)); - - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS, - 'Credits on their way to address ' . $walletAddress . ' for GitHub user ' . $userResponseData['login'] . '. It may take up to a minute for them to arrive.'); - } - elseif (is_array($response) && (isset($response['faultString']) && stripos($response['faultString'], 'InsufficientFundsError') !== false)) - { - Slack::sendErrorIfProd('Github dev credits need a refill'); - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, - 'Our wallet is running low on funds. Please ping jeremy@lbry.io so he can refill it, then try again.'); - } - else - { - Slack::sendErrorIfProd($response === null ? - 'Error connecting to LBRY API via cURL' : - 'Error of unknown origin in sending Github dev credits' . var_export($response, true) - ); - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Failed to send credits. This is an error on our side. Please email jeremy@lbry.io if it persists.'); - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, - 'Failed to send credits. This is an error on our side. Please email jeremy@lbry.io if it persists.'); - } - } - - Lock::freeLock($lock); - $lock = null; - } - } + echo '

';
+      print_r($lbryApiResponseData);
+      die('omg');
     }
-    return Controller::redirect('/developer-program');
+
+    return Controller::redirect(Request::getReferrer('/quickstart/credits'));
   }
 }
diff --git a/lib/thirdparty/LBRY.class.php b/lib/thirdparty/LBRY.class.php
new file mode 100644
index 00000000..8eeed0b7
--- /dev/null
+++ b/lib/thirdparty/LBRY.class.php
@@ -0,0 +1,19 @@
+ 3600, //one hour
+      'json_response' => true
+    ]);
+    return $response['rate'];
+  }
+}
\ No newline at end of file
diff --git a/view/template/developer/_quickstartHome.php b/view/template/developer/_quickstartHome.php
index c44f04a5..7821da47 100644
--- a/view/template/developer/_quickstartHome.php
+++ b/view/template/developer/_quickstartHome.php
@@ -7,7 +7,7 @@
 
 
  • Learned the basics of the LBRY API.

  • -
  • Earned $5.671 for downloading a hilarious film starring David Cross.

  • +
  • Earned $1 for downloading a hilarious film starring David Cross.

  • Irrevocably inscribed a piece of knowledge. Possibly of a cat.

    1USD price equivalent of 250 LBC as received from the Poloneix exchange. diff --git a/view/template/social/_listDev.php b/view/template/social/_listDev.php index f31f83af..783b7887 100644 --- a/view/template/social/_listDev.php +++ b/view/template/social/_listDev.php @@ -3,6 +3,9 @@ Documentation
    */ ?> + From ab45fce4ff6d648a4b7f5d752bb578f57bb3eb12 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Sun, 26 Feb 2017 14:59:44 -0500 Subject: [PATCH 04/12] it works? --- controller/Controller.class.php | 5 +- controller/Session.class.php | 3 +- controller/action/DeveloperActions.class.php | 95 +++++++++---------- lib/thirdparty/LBRY.class.php | 2 +- .../developer/_formCreditsPublish.php | 2 +- view/template/developer/_formNew.php | 20 ---- .../developer/_formNewDeveloperReward.php | 22 +++++ view/template/developer/_quickstartApi.php | 2 +- .../template/developer/_quickstartCredits.php | 6 +- .../template/developer/_quickstartInstall.php | 4 +- view/template/developer/developer-program.php | 31 ------ view/template/developer/quickstart.php | 1 + web/js/quickstart.js | 59 ++++++++++++ web/scss/_form.scss | 6 ++ 14 files changed, 144 insertions(+), 114 deletions(-) delete mode 100644 view/template/developer/_formNew.php create mode 100644 view/template/developer/_formNewDeveloperReward.php delete mode 100644 view/template/developer/developer-program.php create mode 100644 web/js/quickstart.js diff --git a/controller/Controller.class.php b/controller/Controller.class.php index d63841cd..cfff2bd7 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -89,10 +89,9 @@ class Controller $router->get(['/ios', 'get-ios'], 'DownloadActions::executeGet'); $router->get('/roadmap', 'ContentActions::executeRoadmap'); + $router->post('/quickstart/auth', 'DeveloperActions::executeQuickstartAuth'); $router->get('/quickstart/{step}?', 'DeveloperActions::executeQuickstart'); - $router->get('/developer-program', 'DeveloperActions::executeDeveloperProgram'); - $router->post('/developer-program/post', 'DeveloperActions::executeDeveloperProgramPost'); - $router->get('/developer-program/callback', 'DeveloperActions::executeDeveloperProgramGithubCallback'); + $router->get('/quickstart/github/callback', 'DeveloperActions::executeQuickstartGithubCallback'); $router->get(['/press-kit.zip', 'press-kit'], 'ContentActions::executePressKit'); diff --git a/controller/Session.class.php b/controller/Session.class.php index 148600b8..ee1e9e50 100644 --- a/controller/Session.class.php +++ b/controller/Session.class.php @@ -7,8 +7,9 @@ class Session KEY_PREFINERY_USER_ID = 'prefinery_user_id', KEY_PREFINER_USED_CUSTOM_CODE = 'prefinery_used_custom_code', KEY_DEVELOPER_CREDITS_ERROR = 'developer_credits_error', - KEY_DEVELOPER_CREDITS_SUCCESS = 'developer_credits_success', KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'developer_credits_wallet_address', + KEY_DEVELOPER_RETURN_URL_SUCCESS = 'developer_return_url_success', + KEY_GITHUB_ACCESS_TOKEN = 'github_access_token', KEY_LIST_SUB_ERROR = 'list_error', KEY_USER_CULTURE = 'user_culture'; diff --git a/controller/action/DeveloperActions.class.php b/controller/action/DeveloperActions.class.php index 92a2d59d..5a2dfea4 100644 --- a/controller/action/DeveloperActions.class.php +++ b/controller/action/DeveloperActions.class.php @@ -47,21 +47,14 @@ class DeveloperActions extends Actions ]; } - public static function executeDeveloperProgram() - { - return ['developer/developer-program', [ - 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), - 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), - 'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS) - ]]; - } - - public static function prepareFormNewPartial(array $vars) + public static function prepareFormNewDeveloperRewardPartial(array $vars) { + $sendToGithub = !Session::get(Session::KEY_GITHUB_ACCESS_TOKEN); return $vars + [ 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), - 'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS) + 'sendToGithub' => $sendToGithub, + 'apiUrl' => LBRY::getApiUrl('/user/new_github') ]; } @@ -70,68 +63,66 @@ class DeveloperActions extends Actions return $vars + [ 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), - 'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS) ]; } - public static function executeDeveloperProgramPost() + public static function executeQuickstartAuth() { - $walletAddress = trim(Request::getPostParam('wallet')); - Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress); + Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, trim(Request::getPostParam('wallet_address'))); - if (!$walletAddress) + if (Request::getPostParam('returnUrl')) { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Please provide a wallet address.'); - } - elseif (!preg_match('/^b[1-9A-HJ-NP-Za-km-z]{33}$/', $walletAddress)) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid wallet address.'); - } - else - { - if (!Config::get('github_developer_credits_client_id')) - { - throw new Exception('no github client id'); - } - - $githubParams = [ - 'client_id' => Config::get('github_developer_credits_client_id'), - 'redirect_uri' => Request::getHostAndProto() . '/developer-program/callback', - 'scope' => 'user:email public_repo', - 'allow_signup' => false - ]; - return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($githubParams)); + Session::set(Session::KEY_DEVELOPER_RETURN_URL_SUCCESS, Request::getPostParam('returnUrl')); } - return Controller::redirect(Request::getReferrer('/quickstart/credits')); + if (!Config::get('github_developer_credits_client_id')) + { + throw new Exception('no github client id'); + } + + $gitHubParams = [ + 'client_id' => Config::get('github_developer_credits_client_id'), + 'redirect_uri' => Request::getHostAndProto() . '/quickstart/github/callback', + 'scope' => 'user:email public_repo', + 'allow_signup' => false + ]; + + return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($gitHubParams)); } - public static function executeDeveloperProgramGithubCallback() + public static function executeQuickstartGithubCallback() { $code = Request::getParam('code'); - $walletAddress = Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS); - if (!$walletAddress) - { - Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.'); - } - elseif (!$code) + if (!$code) { Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.'); } else { - $newUserUrl = LBRY::getApiUrl('/user/new_developer'); - $lbryApiResponseData = Curl::post($newUserUrl, [ - 'github_code' => $code + $authResponseData = Curl::post('https://github.com/login/oauth/access_token', [ + 'code' => $code, + 'client_id' => Config::get('github_developer_credits_client_id'), + 'client_secret' => Config::get('github_developer_credits_client_secret') ], [ -// 'json_response' => true + 'headers' => ['Accept: application/json'], + 'json_response' => true ]); - echo '
    ';
    -      print_r($lbryApiResponseData);
    -      die('omg');
    +
    +      if (!$authResponseData || !isset($authResponseData['access_token']))
    +      {
    +        Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.');
    +      }
    +      elseif (isset($authResponseData['error_description']))
    +      {
    +        Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']);
    +      }
    +      else
    +      {
    +        Session::set(Session::KEY_GITHUB_ACCESS_TOKEN, $authResponseData['access_token']);
    +      }
         }
     
    -    return Controller::redirect(Request::getReferrer('/quickstart/credits'));
    +    return Controller::redirect(Session::get(Session::KEY_DEVELOPER_RETURN_URL_SUCCESS, '/quickstart/credits'));
       }
     }
    diff --git a/lib/thirdparty/LBRY.class.php b/lib/thirdparty/LBRY.class.php
    index 8eeed0b7..3caf74d3 100644
    --- a/lib/thirdparty/LBRY.class.php
    +++ b/lib/thirdparty/LBRY.class.php
    @@ -14,6 +14,6 @@ class LBRY
           'cache' => 3600, //one hour
           'json_response' => true
         ]);
    -    return $response['rate'];
    +    return $response['data']['lbc_usd'] ?? 0;
       }
     }
    \ No newline at end of file
    diff --git a/view/template/developer/_formCreditsPublish.php b/view/template/developer/_formCreditsPublish.php
    index b632b655..4ec14101 100644
    --- a/view/template/developer/_formCreditsPublish.php
    +++ b/view/template/developer/_formCreditsPublish.php
    @@ -1,4 +1,4 @@
    -
    +

    Receive Credits

    diff --git a/view/template/developer/_formNew.php b/view/template/developer/_formNew.php deleted file mode 100644 index d7b72721..00000000 --- a/view/template/developer/_formNew.php +++ /dev/null @@ -1,20 +0,0 @@ - -

    Receive Credits

    - -
    - -
    - -
    - -
    - -
    -
    -
    - -
    -
    We require a GitHub account to prevent abuse. This will record your email (no spam) and mark you as interested in the lbry repo. - No GitHub account? No problem! Join our Slack channel and post an introduction in #tech.
    -
    \ No newline at end of file diff --git a/view/template/developer/_formNewDeveloperReward.php b/view/template/developer/_formNewDeveloperReward.php new file mode 100644 index 00000000..4d4f1522 --- /dev/null +++ b/view/template/developer/_formNewDeveloperReward.php @@ -0,0 +1,22 @@ + + lbry.quickstartForm('#form-new-developer-reward', ""); + +
    +

    Receive Credits

    +
    +
    +
    + +
    + +
    +
    +
    + + + +
    +
    We require a GitHub account to prevent abuse. This will record your email (no spam) and mark you as interested in the lbry repo. + No GitHub account? No problem! Join our Slack channel and post an introduction in #tech.
    +
    \ No newline at end of file diff --git a/view/template/developer/_quickstartApi.php b/view/template/developer/_quickstartApi.php index 385df56b..a690a4d6 100644 --- a/view/template/developer/_quickstartApi.php +++ b/view/template/developer/_quickstartApi.php @@ -3,7 +3,7 @@ When running, the LBRY daemon provides a JSON-RPC server running at https://localhost:5279/lbryapi.

    - It can be accessed via cURL or any other utility capable of making HTTPS GET and POST requests. So, basically anything, including possibly your toaster. + It can be accessed by any utility capable of making HTTPS GET and POST requests, such as cURL or possibly your toaster.

    To verify the LBRY daemon is running correctly, let's try looking up a name: diff --git a/view/template/developer/_quickstartCredits.php b/view/template/developer/_quickstartCredits.php index 50d71085..2945f187 100644 --- a/view/template/developer/_quickstartCredits.php +++ b/view/template/developer/_quickstartCredits.php @@ -4,8 +4,10 @@ $curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_new_address","params":[]}' ["bbFxRyWCFRkA9YcuuZD8nE7XTLUxYnddTs"]

    Enter this address in the form below and we'll send you 50 credits.

    -
    - +
    + Request::getRelativeUri() . '#new-developer' + ]) ?>

    Next, confirm you've received your credits by calling wallet_balance:

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_balance"}' diff --git a/view/template/developer/_quickstartInstall.php b/view/template/developer/_quickstartInstall.php index bbacaec4..a26baf1d 100644 --- a/view/template/developer/_quickstartInstall.php +++ b/view/template/developer/_quickstartInstall.php @@ -29,5 +29,5 @@

    While running, the daemon will provide a JSON-RPC interface on localhost. We'll learn how to interact with that next.

    macOS and Windows do not currently bundle the daemon separately. Just launch the full app and the API will still be available. This will be resolved in v0.9.
    - */ ?> -
    The first time you run the daemon, it must catch-up with most recent blockheaders. This can take a few minutes.
    \ No newline at end of file +
    The first time you run the daemon, it must catch-up with most recent blockheaders. This can take a few minutes.
    + */ ?> \ No newline at end of file diff --git a/view/template/developer/developer-program.php b/view/template/developer/developer-program.php deleted file mode 100644 index 116e809f..00000000 --- a/view/template/developer/developer-program.php +++ /dev/null @@ -1,31 +0,0 @@ - - - - false, 'isAbsolute' => false]) ?> -
    -
    -

    Developer Program

    -

    All developers with a GitHub account prior to January 31st, 2017 are eligible for free credits.

    -

    To claim your credits, enter a wallet address in the form below and authenticate with GitHub.

    -

    - We will store your GitHub username and email address, but nothing else. -

    -
    -

    Receive Credits

    - -
    - -
    - -
    - -
    - -
    -
    - -
    -
    -
    - \ No newline at end of file diff --git a/view/template/developer/quickstart.php b/view/template/developer/quickstart.php index a3356c3f..48d6d030 100644 --- a/view/template/developer/quickstart.php +++ b/view/template/developer/quickstart.php @@ -1,4 +1,5 @@ + false, 'isAbsolute' => false]) ?> diff --git a/web/js/quickstart.js b/web/js/quickstart.js new file mode 100644 index 00000000..9e783349 --- /dev/null +++ b/web/js/quickstart.js @@ -0,0 +1,59 @@ +lbry.quickstartForm = function (selector, apiUrl) { + var form = $(selector), + accessToken = form.find(':input[name="access_token"]').val(), + walletAddressInput = form.find(':input[name="wallet_address"]'), + submitButton = form.find(':input[type="submit"]'), + isSubmitting = false; + + function resetFormState() { + isSubmitting = false; + walletAddressInput.attr('readonly', null); + submitButton.val(submitButton.data('submitLabel')).attr('disabled', null); + } + + if (window.localStorage.getItem("quickstartFormSuccessHtml")) { + form.find('.notice-success').html(window.localStorage.getItem("quickstartFormSuccessHtml")).show(); + form.find('.form-row, .submit-row').hide(); + } else if (accessToken) { + form.submit(function (event) { + if (isSubmitting) { + return false; + } + + form.find('.notice-success, .notice-error').hide(); + + if (!walletAddressInput.val()) { + resetFormState(); + form.find('.notice-error').html("Please supply a wallet address.").show(); + return false; + } + + event.preventDefault(); + + walletAddressInput.attr('readonly', 'readonly'); + submitButton.val(submitButton.data('submittingLabel')).attr('disabled', 'disabled'); + + $.post(apiUrl, { + access_token: accessToken, + wallet_address: walletAddressInput.val() + }) + .done(function (responseData) { + var data = responseData.data; + var anchor = $(''); + anchor.attr("href", "https://explorer.lbry.io/tx/" + data.TransactionHash); + anchor.html(data.TransactionHash) + form.find('.notice-success') + .html(data.RewardAmount + " credits sent in transaction ") + .append(anchor) + .show(); + window.localStorage.setItem("quickstartFormSuccessHtml", form.find('.notice-success').html()); + }) + .fail(function (xhr) { + var responseData = $.parseJSON(xhr.responseText); + form.find('.notice-error').html(responseData.error.length ? responseData.error : "Something went wrong. Please email grin@lbry.io").show(); + }) + .always(resetFormState); + }) + form.submit(); + } +} \ No newline at end of file diff --git a/web/scss/_form.scss b/web/scss/_form.scss index 4754d778..1194d479 100644 --- a/web/scss/_form.scss +++ b/web/scss/_form.scss @@ -104,6 +104,9 @@ input[type="date"] { border: 1px solid #ccc; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1); transition: all 0.2s linear; + &[readonly] { + background-color: #bbb; + } } textarea:focus, @@ -126,6 +129,9 @@ input[type="checkbox"] { width: auto; } +input[type="submit"][disabled] { + cursor: auto; +} .mail-submit, .invite-submit { From 18599846a76e74d3a2762d135bc90cb2ce639e08 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Sun, 26 Feb 2017 15:20:52 -0500 Subject: [PATCH 05/12] multi form refactor --- controller/Session.class.php | 1 + controller/action/DeveloperActions.class.php | 24 ++++++------ .../developer/_formCreditsPublish.php | 29 +++++++------- .../developer/_formNewDeveloperReward.php | 3 +- .../template/developer/_quickstartCredits.php | 6 ++- web/js/quickstart.js | 39 +++++++++++++++---- web/scss/_form.scss | 5 --- web/scss/_quickstart.scss | 1 + 8 files changed, 67 insertions(+), 41 deletions(-) diff --git a/controller/Session.class.php b/controller/Session.class.php index ee1e9e50..fdb944d2 100644 --- a/controller/Session.class.php +++ b/controller/Session.class.php @@ -6,6 +6,7 @@ class Session KEY_DOWNLOAD_ALLOWED = 'beta_download_allowed2', KEY_PREFINERY_USER_ID = 'prefinery_user_id', KEY_PREFINER_USED_CUSTOM_CODE = 'prefinery_used_custom_code', + KEY_DEVELOPER_LAST_FORM = 'developer_last_form', KEY_DEVELOPER_CREDITS_ERROR = 'developer_credits_error', KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'developer_credits_wallet_address', KEY_DEVELOPER_RETURN_URL_SUCCESS = 'developer_return_url_success', diff --git a/controller/action/DeveloperActions.class.php b/controller/action/DeveloperActions.class.php index 5a2dfea4..446d5ce3 100644 --- a/controller/action/DeveloperActions.class.php +++ b/controller/action/DeveloperActions.class.php @@ -3,22 +3,22 @@ class DeveloperActions extends Actions { const DEVELOPER_REWARD = 250, - API_DOC_URL = 'https://lbryio.github.io/lbry/api/'; + API_DOC_URL = 'https://lbryio.github.io/lbry/api/'; public static function executeQuickstart(string $step = null) { - $stepLabels = [ - '' => 'Home', + $stepLabels = [ + '' => 'Home', 'install' => 'Installation', - 'api' => 'The API', + 'api' => 'The API', 'credits' => 'Credits' ]; - $allSteps = array_keys($stepLabels); + $allSteps = array_keys($stepLabels); $currentStep = $step ?: $allSteps[0]; $viewParams = [ 'currentStep' => $currentStep, - 'stepLabels' => $stepLabels + 'stepLabels' => $stepLabels ]; if ($currentStep !== 'all') @@ -49,12 +49,10 @@ class DeveloperActions extends Actions public static function prepareFormNewDeveloperRewardPartial(array $vars) { - $sendToGithub = !Session::get(Session::KEY_GITHUB_ACCESS_TOKEN); return $vars + [ 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), - 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), - 'sendToGithub' => $sendToGithub, - 'apiUrl' => LBRY::getApiUrl('/user/new_github') + 'error' => Session::get(Session::KEY_DEVELOPER_LAST_FORM) == "new_developer" ? Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR) : '', + 'apiUrl' => LBRY::getApiUrl('/user/new_github') ]; } @@ -62,13 +60,15 @@ class DeveloperActions extends Actions { return $vars + [ 'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), - 'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR), + 'error' => Session::get(Session::KEY_DEVELOPER_LAST_FORM) == "new_publish" ? Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR) : '', + 'apiUrl' => LBRY::getApiUrl('/reward/new') ]; } public static function executeQuickstartAuth() { Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, trim(Request::getPostParam('wallet_address'))); + Session::set(Session::KEY_DEVELOPER_LAST_FORM, Request::getPostParam('formName')); if (Request::getPostParam('returnUrl')) { @@ -92,7 +92,7 @@ class DeveloperActions extends Actions public static function executeQuickstartGithubCallback() { - $code = Request::getParam('code'); + $code = Request::getParam('code'); if (!$code) { diff --git a/view/template/developer/_formCreditsPublish.php b/view/template/developer/_formCreditsPublish.php index 4ec14101..017f58a7 100644 --- a/view/template/developer/_formCreditsPublish.php +++ b/view/template/developer/_formCreditsPublish.php @@ -1,25 +1,28 @@ -
    -

    Receive Credits

    - -
    - -
    - + +lbry.quickstartForm('#form-new-publish-reward', ""); + + +

    Receive Credits for Publish

    +
    +
    - +
    - +
    -
    - +
    + + + +
    \ No newline at end of file diff --git a/view/template/developer/_formNewDeveloperReward.php b/view/template/developer/_formNewDeveloperReward.php index 4d4f1522..184e5a54 100644 --- a/view/template/developer/_formNewDeveloperReward.php +++ b/view/template/developer/_formNewDeveloperReward.php @@ -9,11 +9,12 @@
    + class="required standard " placeholder="bYnFQUPTTDM1BYNCxgxKEav4FFQsrgDBoE">
    +
    diff --git a/view/template/developer/_quickstartCredits.php b/view/template/developer/_quickstartCredits.php index 2945f187..bbb8f6a8 100644 --- a/view/template/developer/_quickstartCredits.php +++ b/view/template/developer/_quickstartCredits.php @@ -22,8 +22,10 @@ "metadata": {"what goes here": "who knows if you do not work for LBRY, certainly you will not be able to figure it out from response messages or API docs" }]}' [whatever this response looks like]
    -
    - +
    + Request::getRelativeUri() . '#new-developer' + ]) ?>

    Try the UI

    LBRY comes with a UI so that normal people can use it to. You can download it here.

    diff --git a/web/js/quickstart.js b/web/js/quickstart.js index 9e783349..5c8c18bc 100644 --- a/web/js/quickstart.js +++ b/web/js/quickstart.js @@ -2,17 +2,21 @@ lbry.quickstartForm = function (selector, apiUrl) { var form = $(selector), accessToken = form.find(':input[name="access_token"]').val(), walletAddressInput = form.find(':input[name="wallet_address"]'), + transactionHashInput = form.find(':input[name="transaction_hash"]'), + storageKey = form.attr('id') + "SuccessHTML", submitButton = form.find(':input[type="submit"]'), + isAutomaticSubmit = false, isSubmitting = false; function resetFormState() { isSubmitting = false; walletAddressInput.attr('readonly', null); + transactionHashInput.attr('readonly', null); submitButton.val(submitButton.data('submitLabel')).attr('disabled', null); } - if (window.localStorage.getItem("quickstartFormSuccessHtml")) { - form.find('.notice-success').html(window.localStorage.getItem("quickstartFormSuccessHtml")).show(); + if (window.localStorage.getItem(storageKey)) { + form.find('.notice-success').html(window.localStorage.getItem(storageKey)).show(); form.find('.form-row, .submit-row').hide(); } else if (accessToken) { form.submit(function (event) { @@ -20,23 +24,39 @@ lbry.quickstartForm = function (selector, apiUrl) { return false; } + var postData = { + access_token: accessToken, + wallet_address: walletAddressInput.val() + }; + form.find('.notice-success, .notice-error').hide(); if (!walletAddressInput.val()) { resetFormState(); - form.find('.notice-error').html("Please supply a wallet address.").show(); + if (!isAutomaticSubmit) { + form.find('.notice-error').html("Please supply a wallet address.").show(); + } return false; } + if (transactionHashInput.length) { + if (!transactionHashInput.val()) { + resetFormState(); + if (!isAutomaticSubmit) { + form.find('.notice-error').html("Please supply a transaction ID.").show(); + } + return false; + } + postData.transaction_hash = transactionHashInput.val(); + } + event.preventDefault(); walletAddressInput.attr('readonly', 'readonly'); + transactionHashInput.attr('readonly', 'readonly'); submitButton.val(submitButton.data('submittingLabel')).attr('disabled', 'disabled'); - $.post(apiUrl, { - access_token: accessToken, - wallet_address: walletAddressInput.val() - }) + $.post(apiUrl) .done(function (responseData) { var data = responseData.data; var anchor = $(''); @@ -46,7 +66,7 @@ lbry.quickstartForm = function (selector, apiUrl) { .html(data.RewardAmount + " credits sent in transaction ") .append(anchor) .show(); - window.localStorage.setItem("quickstartFormSuccessHtml", form.find('.notice-success').html()); + window.localStorage.setItem(storageKey, form.find('.notice-success').html()); }) .fail(function (xhr) { var responseData = $.parseJSON(xhr.responseText); @@ -54,6 +74,9 @@ lbry.quickstartForm = function (selector, apiUrl) { }) .always(resetFormState); }) + + isAutomaticSubmit = true; form.submit(); + isAutomaticSubmit = false; } } \ No newline at end of file diff --git a/web/scss/_form.scss b/web/scss/_form.scss index 1194d479..2f3d4d4b 100644 --- a/web/scss/_form.scss +++ b/web/scss/_form.scss @@ -81,11 +81,6 @@ input[type="date"] { vertical-align: middle; } -input.input-wallet -{ - width: 400px; -} - textarea { height: auto; min-height: 60px; diff --git a/web/scss/_quickstart.scss b/web/scss/_quickstart.scss index 65e15895..4c5bad69 100644 --- a/web/scss/_quickstart.scss +++ b/web/scss/_quickstart.scss @@ -27,6 +27,7 @@ .quickstart__claim-form { margin: $spacing-vertical * 2 0; + input[type="text"] { width: 100%; } } .quickstart__progress-bar From 7714531d03ee8a87edb41c53e7ce134576f2ca67 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Mon, 27 Feb 2017 12:56:11 -0500 Subject: [PATCH 06/12] fix missing data --- web/js/quickstart.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/js/quickstart.js b/web/js/quickstart.js index 5c8c18bc..36ca26b1 100644 --- a/web/js/quickstart.js +++ b/web/js/quickstart.js @@ -56,7 +56,7 @@ lbry.quickstartForm = function (selector, apiUrl) { transactionHashInput.attr('readonly', 'readonly'); submitButton.val(submitButton.data('submittingLabel')).attr('disabled', 'disabled'); - $.post(apiUrl) + $.post(apiUrl, postData) .done(function (responseData) { var data = responseData.data; var anchor = $(''); From 4f17304fd25ad60ee1d7122910b6e1219bb16232 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Mon, 27 Feb 2017 15:04:38 -0500 Subject: [PATCH 07/12] remove brackets --- view/template/developer/_quickstartApi.php | 4 ++-- view/template/developer/_quickstartCredits.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/view/template/developer/_quickstartApi.php b/view/template/developer/_quickstartApi.php index a690a4d6..49eef0c5 100644 --- a/view/template/developer/_quickstartApi.php +++ b/view/template/developer/_quickstartApi.php @@ -8,7 +8,7 @@

    To verify the LBRY daemon is running correctly, let's try looking up a name:

    -$curl 'http://localhost:5279/lbryapi' --data '{"method":"resolve_name","params":[{"name":"what"}]}' +$curl 'http://localhost:5279/lbryapi' --data '{"method":"resolve_name","params":{"name":"what"}}' [ { "ver": "0.0.3", @@ -27,7 +27,7 @@ ]

    Above, we called the method resolve_name for the URL lbry://what. This returned the metadata associated with the URL.

    Now let's download it. This time we're going to call the method get with the same parameters.

    -$curl 'http://localhost:5279/lbryapi' --data '{"method":"get","params":[{"name":"what"}]}' +$curl 'http://localhost:5279/lbryapi' --data '{"method":"get","params":{"name":"what"} }' ["d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"]

    The LBRY API consists about 50 calls, all related to discovering, distributing, and purchasing content. View the full API documentation.

    You can also list all of the commands available by calling the help command.

    diff --git a/view/template/developer/_quickstartCredits.php b/view/template/developer/_quickstartCredits.php index bbb8f6a8..0147dba0 100644 --- a/view/template/developer/_quickstartCredits.php +++ b/view/template/developer/_quickstartCredits.php @@ -15,12 +15,12 @@

    Publishing

    Publishing to LBRY is just as easy as everything else! If you publish something, we'll send you an additional 200 LBC for further use.

    Not sure what to publish? We recommend your favorite picture or home video. Or just grab something from here.

    -$curl 'http://localhost:5279/lbryapi' --data '{"method":"publish", "params": [{ +$curl 'http://localhost:5279/lbryapi' --data '{"method":"publish", "params": { "name": "electricsheep", "file_path": "\\home\kauffj\\Desktop\\electric-sheep.mp4", "bid": 1, "metadata": {"what goes here": "who knows if you do not work for LBRY, certainly you will not be able to figure it out from response messages or API docs" -}]}' +}}' [whatever this response looks like]
    Date: Mon, 27 Feb 2017 16:03:48 -0500 Subject: [PATCH 08/12] bash styling change + other fixes --- .../developer/_formCreditsPublish.php | 2 +- view/template/developer/_quickstartApi.php | 6 +- .../template/developer/_quickstartCredits.php | 8 +-- view/template/page/quickstart_old.php | 63 ------------------- view/template/page/what.php | 40 ++++++------ web/scss/_code.scss | 19 ++++-- web/scss/_global.scss | 7 +++ 7 files changed, 50 insertions(+), 95 deletions(-) delete mode 100644 view/template/page/quickstart_old.php diff --git a/view/template/developer/_formCreditsPublish.php b/view/template/developer/_formCreditsPublish.php index 017f58a7..71236bd3 100644 --- a/view/template/developer/_formCreditsPublish.php +++ b/view/template/developer/_formCreditsPublish.php @@ -2,7 +2,7 @@ lbry.quickstartForm('#form-new-publish-reward', "");
    -

    Receive Credits for Publish

    +

    Publishing Reward

    diff --git a/view/template/developer/_quickstartApi.php b/view/template/developer/_quickstartApi.php index 49eef0c5..f2c1111e 100644 --- a/view/template/developer/_quickstartApi.php +++ b/view/template/developer/_quickstartApi.php @@ -9,7 +9,7 @@ To verify the LBRY daemon is running correctly, let's try looking up a name:

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"resolve_name","params":{"name":"what"}}' -[ +[ { "ver": "0.0.3", "description": "What is LBRY? An introduction with Alex Tabarrok", @@ -24,11 +24,11 @@ "nsfw": false, "thumbnail": "https:\/\/s3.amazonaws.com\/files.lbry.io\/logo.png" } -] +]

    Above, we called the method resolve_name for the URL lbry://what. This returned the metadata associated with the URL.

    Now let's download it. This time we're going to call the method get with the same parameters.

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"get","params":{"name":"what"} }' -["d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"] +["d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"]

    The LBRY API consists about 50 calls, all related to discovering, distributing, and purchasing content. View the full API documentation.

    You can also list all of the commands available by calling the help command.

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"help"}' diff --git a/view/template/developer/_quickstartCredits.php b/view/template/developer/_quickstartCredits.php index 0147dba0..e148c05c 100644 --- a/view/template/developer/_quickstartCredits.php +++ b/view/template/developer/_quickstartCredits.php @@ -1,8 +1,8 @@

    Credits

    So far, everything we've done with LBRY has been free. However, some actions, such as reserving a name or purchasing paid content, require credits.

    To receive credits, first generate a wallet address:

    -$curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_new_address","params":[]}' -["bbFxRyWCFRkA9YcuuZD8nE7XTLUxYnddTs"] +$curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_new_address"}' +["bbFxRyWCFRkA9YcuuZD8nE7XTLUxYnddTs"]

    Enter this address in the form below and we'll send you 50 credits.

    Next, confirm you've received your credits by calling wallet_balance:

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_balance"}' -[50.00000000] +[50.00000000]

    Publishing

    Publishing to LBRY is just as easy as everything else! If you publish something, we'll send you an additional 200 LBC for further use.

    Not sure what to publish? We recommend your favorite picture or home video. Or just grab something from here.

    @@ -21,7 +21,7 @@ "bid": 1, "metadata": {"what goes here": "who knows if you do not work for LBRY, certainly you will not be able to figure it out from response messages or API docs" }}' -[whatever this response looks like] +[whatever this response looks like]
    Request::getRelativeUri() . '#new-developer' diff --git a/view/template/page/quickstart_old.php b/view/template/page/quickstart_old.php deleted file mode 100644 index efb4fa1c..00000000 --- a/view/template/page/quickstart_old.php +++ /dev/null @@ -1,63 +0,0 @@ - - - - false, 'isAbsolute' => false]) ?> -
    -
    -
    -

    Set Up

    -

    This step-by-step guide will have you running LBRY and interacting with the API in just a few minutes.

    -

    This guide is for programmers and other technical users. For consumer usage of LBRY, please go here.

    -

    What's Covered

    -
      -
    1. Installation
    2. -
    3. Running LBRY
    4. -
    5. The API
    6. -
    7. Credits
    8. -
    9. Community & Issues
    10. -
    -
    -

    1. Installation

    -

    The easiest way to install LBRY is to use a pre-packaged binary. We provide binaries for Windows, macOS, and Debian-based Linux.

    - - - - - - - - - - - - - - - -
    macOS Linux Windows
    Download DMGDownload DEBDownload MSI
    -

    - If you prefer to compile from source or are not on one of the above operating systems, follow - this guide. -

    -
    -
    -

    2. Running LBRY

    -

    - Launch the deamon to run as a background process: -

    -

    - $lbrynet-daemon -

    -

    The first time you run the daemon, it must catch-up with most recent blockheaders. This can take several minutes.

    -
    macOS and Windows do not currently bundle the daemon separately. Just launch the full app and the API will still be available. This will be resolved in v0.9.
    -
    -
    - -
    - - -
    -
    -
    - - diff --git a/view/template/page/what.php b/view/template/page/what.php index 9c9831cd..724ade3c 100644 --- a/view/template/page/what.php +++ b/view/template/page/what.php @@ -97,16 +97,16 @@

    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.

    $lbrynet-cli resolve_name name=wonderfullife -wonderfullife : { - title: "It’s a Wonderful Life", - description: "An angel helps a compassionate but despairingly frustrated businessman by showing what life would have been like if he never existed.", - thumbnail: "http://i.imgur.com/MW45x88.jpg", - license: "public domain", - price: 0, //free! - publisher: "A Fan Of George Bailey", //simplification - sources: { //extensible, variable list - lbry_hash : <unique id>, - url : <url> +wonderfullife : { + title: "It’s a Wonderful Life", + description: "An angel helps a compassionate but despairingly frustrated businessman by showing what life would have been like if he never existed.", + thumbnail: "http://i.imgur.com/MW45x88.jpg", + license: "public domain", + price: 0, //free! + publisher: "A Fan Of George Bailey", //simplification + sources: { //extensible, variable list + lbry_hash : <unique id>, + url : <url> } }

    A slightly simplified sample entry of metadata in the LBRY blockchain. Whichever party or parties bid the most in an ongoing auction control what a name returns.

    @@ -245,16 +245,16 @@

    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.

    -    wonderfullife : {
    -      title: "It’s a Wonderful Life",
    -      description: "An angel helps a compassionate but despairingly frustrated businessman by showing what life would have been like if he never existed.",
    -      thumbnail: "http://i.imgur.com/MW45x88.jpg",
    -      license: "public domain",
    -      price: 0, //free!
    -      publisher: "A Fan Of George Bailey", //simplification
    -      sources: { //extensible, variable list
    -        lbry_hash : <unique id>,
    -        url : <url>
    +    wonderfullife : {
    +      title: "It’s a Wonderful Life",
    +      description: "An angel helps a compassionate but despairingly frustrated businessman by showing what life would have been like if he never existed.",
    +      thumbnail: "http://i.imgur.com/MW45x88.jpg",
    +      license: "public domain",
    +      price: 0, //free!
    +      publisher: "A Fan Of George Bailey", //simplification
    +      sources: { //extensible, variable list
    +        lbry_hash : <unique id>,
    +        url : <url>
           }
         }
    diff --git a/web/scss/_code.scss b/web/scss/_code.scss index 980c1cd3..1d825263 100644 --- a/web/scss/_code.scss +++ b/web/scss/_code.scss @@ -34,7 +34,6 @@ pre user-select: text; margin-bottom: $spacing-vertical; - border-left: .3rem solid $color-primary; padding: $spacing-vertical / 2 $spacing-vertical; unicode-bidi: embed; overflow-x: auto; @@ -42,10 +41,22 @@ pre display: block; word-wrap: break-word; + background: #222; + color: #fff; + font-size: 0.75em; } -.code-bash__kw1 {color: #c20cb9; font-weight: bold;} -.code-bash__kw2 {color: #7a0874; font-weight: bold; } +.code-bash__response { + color: #ccc; +} + +.code-bash__kw {color: #c20cb9; font-weight: bold;} .code-bash__comment { color: #888; } -.code-bash__prompt { font-weight: bold; margin-right: 5px; } \ No newline at end of file +.code-bash__prompt +{ + font-weight: bold; + margin-right: 5px; + color: lighten($color-primary, 20%); + @include user-select(none); +} \ No newline at end of file diff --git a/web/scss/_global.scss b/web/scss/_global.scss index 7b7a9d00..d3959b3c 100644 --- a/web/scss/_global.scss +++ b/web/scss/_global.scss @@ -169,6 +169,13 @@ $info_text: #3a87ad; } +@mixin user-select ($value) { + -webkit-user-select: $value; + -moz-user-select: $value; + -ms-user-select: $value; + user-select: $value; +} + @mixin transition($transition-property, $transition-time, $method) { -webkit-transition: $transition-property $transition-time $method; -moz-transition: $transition-property $transition-time $method; From ebece99a1fa8cf3c9ce09f9f4a03cfa6a83937e0 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Mon, 27 Feb 2017 16:09:01 -0500 Subject: [PATCH 09/12] fix long links in notice --- web/js/quickstart.js | 2 +- web/scss/_basic.scss | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/web/js/quickstart.js b/web/js/quickstart.js index 36ca26b1..61d119f8 100644 --- a/web/js/quickstart.js +++ b/web/js/quickstart.js @@ -59,7 +59,7 @@ lbry.quickstartForm = function (selector, apiUrl) { $.post(apiUrl, postData) .done(function (responseData) { var data = responseData.data; - var anchor = $(''); + var anchor = $(''); anchor.attr("href", "https://explorer.lbry.io/tx/" + data.TransactionHash); anchor.html(data.TransactionHash) form.find('.notice-success') diff --git a/web/scss/_basic.scss b/web/scss/_basic.scss index b24881bd..73bcc505 100644 --- a/web/scss/_basic.scss +++ b/web/scss/_basic.scss @@ -82,6 +82,10 @@ section { @include anchor($color-primary); } +.link-primary--break-word +{ + word-break: break-all; +} a:hover img { opacity: 0.75; From dd7f3b99d79dd9b11d2c4f1671738bd3a90c9069 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Mon, 27 Feb 2017 16:17:37 -0500 Subject: [PATCH 10/12] stronger code styling --- view/template/developer/_quickstartApi.php | 6 +++--- view/template/developer/_quickstartCredits.php | 2 +- web/scss/_code.scss | 12 ++++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/view/template/developer/_quickstartApi.php b/view/template/developer/_quickstartApi.php index f2c1111e..0e2d4477 100644 --- a/view/template/developer/_quickstartApi.php +++ b/view/template/developer/_quickstartApi.php @@ -1,6 +1,6 @@

    The API

    - When running, the LBRY daemon provides a JSON-RPC server running at https://localhost:5279/lbryapi. + When running, the LBRY daemon provides a JSON-RPC server running at https://localhost:5279/lbryapi.

    It can be accessed by any utility capable of making HTTPS GET and POST requests, such as cURL or possibly your toaster. @@ -25,8 +25,8 @@ "thumbnail": "https:\/\/s3.amazonaws.com\/files.lbry.io\/logo.png" } ] -

    Above, we called the method resolve_name for the URL lbry://what. This returned the metadata associated with the URL.

    -

    Now let's download it. This time we're going to call the method get with the same parameters.

    +

    Above, we called the method resolve_name for the URL lbry://what. This returned the metadata associated with the URL.

    +

    Now let's download it. This time we're going to call the method get with the same parameters.

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"get","params":{"name":"what"} }' ["d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"]

    The LBRY API consists about 50 calls, all related to discovering, distributing, and purchasing content. View the full API documentation.

    diff --git a/view/template/developer/_quickstartCredits.php b/view/template/developer/_quickstartCredits.php index e148c05c..f2575aa5 100644 --- a/view/template/developer/_quickstartCredits.php +++ b/view/template/developer/_quickstartCredits.php @@ -9,7 +9,7 @@ 'returnUrl' => Request::getRelativeUri() . '#new-developer' ]) ?>
    -

    Next, confirm you've received your credits by calling wallet_balance:

    +

    Next, confirm you've received your credits by calling wallet_balance:

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_balance"}' [50.00000000]

    Publishing

    diff --git a/web/scss/_code.scss b/web/scss/_code.scss index 1d825263..fd046f77 100644 --- a/web/scss/_code.scss +++ b/web/scss/_code.scss @@ -9,10 +9,14 @@ code padding: 3px 5px; font-family: $font-mono; color: darken($color-primary, 10%); -} -.code-plain -{ - font-family: $font-mono; + &.code-inline { + padding: 0; + margin-left: 1px; + margin-right: 1px; + font-weight: bold; + color: inherit; + background-color: transparent; + } } pre { From ba2c62e91e3960dfa2f6d3a5b8031ba9c5ca0d33 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Mon, 27 Feb 2017 16:23:58 -0500 Subject: [PATCH 11/12] hack fix for bullet css bug --- web/scss/_quickstart.scss | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/web/scss/_quickstart.scss b/web/scss/_quickstart.scss index 4c5bad69..d1214e47 100644 --- a/web/scss/_quickstart.scss +++ b/web/scss/_quickstart.scss @@ -5,6 +5,14 @@ max-width: 860px; } +.quickstart .content-dark +{ + ul, ol, li + { + list-style-position: outside !important; /*hack fix for CSS bug affecting headers inside LI tags, ask Grin*/ + } +} + .quickstart__table { margin: 0 auto $spacing-vertical; From 8b83a954417a65c8f1b6abc8dea34ee673bfbccc Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Mon, 27 Feb 2017 18:14:03 -0500 Subject: [PATCH 12/12] more fixes --- controller/Controller.class.php | 1 + view/template/developer/_quickstartApi.php | 2 +- .../template/developer/_quickstartCredits.php | 10 ++- web/img/lbry-white-logo-only.svg | 79 +++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 web/img/lbry-white-logo-only.svg diff --git a/controller/Controller.class.php b/controller/Controller.class.php index cfff2bd7..023f059a 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -127,6 +127,7 @@ class Controller '/deck.pdf' => 'https://www.dropbox.com/s/0xj4vgucsbi8rtv/lbry-deck.pdf?dl=1', '/pln.pdf' => 'https://www.dropbox.com/s/uevjrwnyr672clj/lbry-pln.pdf?dl=1', '/plan.pdf' => 'https://www.dropbox.com/s/uevjrwnyr672clj/lbry-pln.pdf?dl=1', + '/api' => 'http://lbryio.github.io/lbry' ]; diff --git a/view/template/developer/_quickstartApi.php b/view/template/developer/_quickstartApi.php index 0e2d4477..f1782e72 100644 --- a/view/template/developer/_quickstartApi.php +++ b/view/template/developer/_quickstartApi.php @@ -29,7 +29,7 @@

    Now let's download it. This time we're going to call the method get with the same parameters.

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"get","params":{"name":"what"} }' ["d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"] -

    The LBRY API consists about 50 calls, all related to discovering, distributing, and purchasing content. View the full API documentation.

    +

    The LBRY API consists about 50 calls, all related to discovering, distributing, and purchasing content. View the full API documentation.

    You can also list all of the commands available by calling the help command.

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"help"}' \ No newline at end of file diff --git a/view/template/developer/_quickstartCredits.php b/view/template/developer/_quickstartCredits.php index f2575aa5..115f4667 100644 --- a/view/template/developer/_quickstartCredits.php +++ b/view/template/developer/_quickstartCredits.php @@ -13,13 +13,16 @@ $curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_balance"}' [50.00000000]

    Publishing

    +
    + The credit reward for this portion of the guide does not work yet. It will be added shortly. However, you can still follow this section to learn how to publish. +

    Publishing to LBRY is just as easy as everything else! If you publish something, we'll send you an additional 200 LBC for further use.

    Not sure what to publish? We recommend your favorite picture or home video. Or just grab something from here.

    $curl 'http://localhost:5279/lbryapi' --data '{"method":"publish", "params": { "name": "electricsheep", "file_path": "\\home\kauffj\\Desktop\\electric-sheep.mp4", "bid": 1, - "metadata": {"what goes here": "who knows if you do not work for LBRY, certainly you will not be able to figure it out from response messages or API docs" + "metadata": { } //this should match the metadata returned by resolve_name }}' [whatever this response looks like]
    @@ -27,8 +30,11 @@ 'returnUrl' => Request::getRelativeUri() . '#new-developer' ]) ?>
    +

    Enjoy a Hollywood Film

    +$curl 'http://localhost:5279/lbryapi' --data '{"method":"get","params":{"name":"itsadisaster"} }' +["d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"]

    Try the UI

    -

    LBRY comes with a UI so that normal people can use it to. You can download it here.

    +

    LBRY comes with a UI so that normal people can use it too. You can download it here.

    You Did It! What's Next?

    Start building something awesome! LBRY works as a discovery and distribution backend for everything from films to CAD files. diff --git a/web/img/lbry-white-logo-only.svg b/web/img/lbry-white-logo-only.svg new file mode 100644 index 00000000..9f2352f9 --- /dev/null +++ b/web/img/lbry-white-logo-only.svg @@ -0,0 +1,79 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + +