mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-09-03 20:35:16 +00:00
fixed PUT via curl, addde mailgun unsubscribe
This commit is contained in:
parent
b2f8bc619a
commit
c298e5860c
2 changed files with 38 additions and 8 deletions
35
lib/thirdparty/Mailgun.class.php
vendored
35
lib/thirdparty/Mailgun.class.php
vendored
|
@ -6,6 +6,29 @@ class Mailgun
|
||||||
|
|
||||||
const LIST_GENERAL = 'lbryians@lbry.io';
|
const LIST_GENERAL = 'lbryians@lbry.io';
|
||||||
|
|
||||||
|
public static function unsubscribeFromMailingList($listAddress, $email)
|
||||||
|
{
|
||||||
|
list($status, $headers, $body) = static::put('/lists/' . $listAddress . '/members/' . $email, [
|
||||||
|
'subscribed' => 'no',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($status == 200)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_decode($body, true);
|
||||||
|
$message = $data['error'] ?? $data['message'] ?? false;
|
||||||
|
|
||||||
|
if (strpos($message, 'Member '.$email) === 0 && strrpos($message, ' not found') === (strlen($message) - strlen(' not found')))
|
||||||
|
{
|
||||||
|
// message says "Member $email ... not found", so email is not on list. that's the same as unsubscribing, right?
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
public static function sendDmcaReport($data)
|
public static function sendDmcaReport($data)
|
||||||
{
|
{
|
||||||
list($status, $headers, $body) = static::post('/lbry.io/messages', [
|
list($status, $headers, $body) = static::post('/lbry.io/messages', [
|
||||||
|
@ -89,7 +112,17 @@ class Mailgun
|
||||||
|
|
||||||
protected static function post($endpoint, $data)
|
protected static function post($endpoint, $data)
|
||||||
{
|
{
|
||||||
return Curl::doCurl(Curl::POST, self::BASE_URL . $endpoint, $data, [
|
return static::request(Curl::POST, $endpoint, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function put($endpoint, $data)
|
||||||
|
{
|
||||||
|
return static::request(Curl::PUT, $endpoint, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function request($method, $endpoint, $data)
|
||||||
|
{
|
||||||
|
return Curl::doCurl($method, self::BASE_URL . $endpoint, $data, [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Authorization: Basic ' . base64_encode('api:' . Config::get('mailgun_api_key'))
|
'Authorization: Basic ' . base64_encode('api:' . Config::get('mailgun_api_key'))
|
||||||
],
|
],
|
||||||
|
|
|
@ -70,7 +70,7 @@ class Curl
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
// curl_setopt($ch, CURLOPT_VERBOSE, true);
|
// curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||||
// curl_setopt($ch, CURLOPT_STDERR, fopen('php://temp', 'w+'));
|
// curl_setopt($ch, CURLOPT_STDERR, fopen(sys_get_temp_dir().'/curl-debug-'.date('Ymd-His'), 'w+'));
|
||||||
|
|
||||||
if ($ch === false || $ch === null)
|
if ($ch === false || $ch === null)
|
||||||
{
|
{
|
||||||
|
@ -100,12 +100,9 @@ class Curl
|
||||||
{
|
{
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
}
|
}
|
||||||
|
elseif ($method == static::PUT)
|
||||||
if ($method == static::PUT)
|
|
||||||
{
|
{
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||||
curl_setopt($ch, CURLOPT_PUT, 1);
|
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($method, [static::PUT, static::POST]))
|
if (in_array($method, [static::PUT, static::POST]))
|
||||||
|
|
Loading…
Add table
Reference in a new issue