Files

109 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2017-02-21 21:44:25 -05:00
<?php
class LBRY
{
2018-05-21 11:49:15 -04:00
public static function getApiUrl($endpoint)
{
2018-09-21 09:57:16 -05:00
if (!strlen(Config::get(Config::LBRY_API_SERVER)) > 0) {
throw new Exception("API server URL is missing from configuration");
2018-09-21 09:57:16 -05:00
}
2018-05-21 11:49:15 -04:00
return Config::get(Config::LBRY_API_SERVER) . $endpoint;
}
2017-02-21 21:44:25 -05:00
2018-05-21 11:49:15 -04:00
public static function getLBCtoUSDRate()
{
$response = CurlWithCache::get(static::getApiUrl('/lbc/exchange_rate'), [], [
2019-04-26 11:18:15 -05:00
'cache' => 3600, //one hour
'json_response' => true
]);
2018-05-21 11:49:15 -04:00
return $response['data']['lbc_usd'] ?? 0;
}
2017-05-26 13:18:28 -04:00
2018-05-21 11:49:15 -04:00
public static function subscribe($email, $tag = null)
{
return Curl::post(static::getApiUrl('/list/subscribe'), array_filter([
2019-04-26 11:18:15 -05:00
'email' => $email,
'tag' => $tag,
]), ['json_response' => true]);
}
2018-08-13 22:28:31 -04:00
public static function editEmailSettings($token, $email, $isPrimary =null, $isEnabled = null)
{
2018-10-20 12:04:26 -04:00
return Curl::post(static::getApiUrl('/user_email/edit'), ['auth_token' => $token], ['email' => $email], ['is_primary' => $isPrimary], ['is_enabled' => $isEnabled]);
2018-08-13 22:28:31 -04:00
}
public static function emailStatus($token)
{
2018-10-20 12:04:26 -04:00
list($status, $headers, $body) = Curl::doCurl(Curl::POST, static::getApiUrl('/user_email/status'), ['auth_token' => $token], ['json_response' => true]);
return array($status,$headers,$body);
2018-08-13 22:28:31 -04:00
}
public static function applyTags($type, $token, $tags)
{
2018-10-20 12:04:26 -04:00
return Curl::post(static::getApiUrl('/user_tag/edit'), ['auth_token' => $token], [$type => $tags]);
2018-08-13 22:28:31 -04:00
}
2018-05-21 11:49:15 -04:00
public static function unsubscribe($email)
{
2018-10-20 12:04:26 -04:00
return Curl::post(static::getApiUrl('/user/unsubscribe'), ['email' => $email], ['json_response' => true]);
2018-05-21 11:49:15 -04:00
}
2019-04-19 14:30:46 -05:00
public static function connectYoutube($channel_name, $immediateSync = false)
{
2019-04-16 16:51:43 -05:00
// Uncomment next line for production and comment other return
2019-04-26 11:18:15 -05:00
return Curl::post(static::getApiUrl('/yt/new'), [ 'desired_lbry_channel_name' => $channel_name, 'immediate_sync' => $immediateSync, 'type' => 'sync' ], [ 'json_response' => true ]);
2019-04-26 10:31:33 -05:00
// Uncomment next line for development and comment other return (this also requires the testnet API)
2019-04-26 11:18:15 -05:00
// return Curl::post(static::getApiUrl('/yt/new'), [
// 'desired_lbry_channel_name' => $channel_name,
// 'immediate_sync' => $immediateSync,
// 'return_url' => 'http://localhost:8000/youtube/status/',
// 'type' => 'sync'
// ], [
// 'json_response' => true
// ]);
2018-05-21 11:49:15 -04:00
}
// Check the sync status
public static function statusYoutube($status_token)
{
return Curl::get(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]);
}
public static function editYouTube($status_token, $channel_name, $email, $sync_consent)
{
2019-04-26 10:31:33 -05:00
$postParams = array('status_token' => $status_token);
if ($email) {
2019-04-26 11:18:15 -05:00
$postParams['new_email'] = $email;
2018-05-21 11:49:15 -04:00
}
2019-04-26 10:31:33 -05:00
if ($sync_consent) {
2019-04-26 11:18:15 -05:00
if ($sync_consent === 0) {
$sync_consent = null;
}
$postParams['sync_consent'] = $sync_consent;
2019-04-26 10:31:33 -05:00
}
2019-05-23 17:34:39 +02:00
if ($channel_name) {
2019-04-26 11:18:15 -05:00
$postParams['new_preferred_channel'] = $channel_name;
2019-04-26 10:31:33 -05:00
}
return Curl::post(static::getApiUrl("/yt/update"), $postParams, ['json_response' => true]);
}
public static function logWebVisitor($site, $visitorID, $IPAddress)
{
2019-04-19 14:30:46 -05:00
if (IS_PRODUCTION) {
2018-12-27 15:08:24 -05:00
return Curl::post(static::getApiUrl("/visitor/new"), ['site' => $site, 'visitor_id' => $visitorID, 'ip_address' => $IPAddress], ['json_response' => true]);
}
}
}