Compare commits

..

No commits in common. "master" and "0.4" have entirely different histories.
master ... 0.4

5 changed files with 49 additions and 356 deletions

View file

@ -1,7 +0,0 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10

View file

@ -1,14 +0,0 @@
name: Dependabot auto-merge minor/patch
on:
workflow_dispatch:
pull_request:
permissions:
contents: write
pull-requests: write
repository-projects: write
jobs:
dependabot:
uses: ShaneMcC/.github/.github/workflows/automergeMinorOrPatch.yml@master
secrets: inherit

View file

@ -12,7 +12,7 @@
],
"require": {
"php": ">=7.1",
"rmccue/requests": "^2.0"
"rmccue/requests": "^1.7"
},
"autoload": {
"psr-0": {

72
composer.lock generated
View file

@ -1,57 +1,37 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "55d65ecd209ff9bb30f393746ff9b81d",
"hash": "cb150c262c5789b25121c563653566ff",
"content-hash": "0e9868a816da68c50ceb0f080e96fe30",
"packages": [
{
"name": "rmccue/requests",
"version": "v2.0.14",
"version": "v1.7.0",
"source": {
"type": "git",
"url": "https://github.com/WordPress/Requests.git",
"reference": "9b228eef149e1752b037bf79cef4ca73a7b1fea1"
"url": "https://github.com/rmccue/Requests.git",
"reference": "87932f52ffad70504d93f04f15690cf16a089546"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/WordPress/Requests/zipball/9b228eef149e1752b037bf79cef4ca73a7b1fea1",
"reference": "9b228eef149e1752b037bf79cef4ca73a7b1fea1",
"url": "https://api.github.com/repos/rmccue/Requests/zipball/87932f52ffad70504d93f04f15690cf16a089546",
"reference": "87932f52ffad70504d93f04f15690cf16a089546",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=5.6"
"php": ">=5.2"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"php-parallel-lint/php-console-highlighter": "^0.5.0",
"php-parallel-lint/php-parallel-lint": "^1.3.1",
"phpcompatibility/php-compatibility": "^9.0",
"requests/test-server": "dev-main",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.6",
"wp-coding-standards/wpcs": "^2.0",
"yoast/phpunit-polyfills": "^1.0.0"
},
"suggest": {
"art4/requests-psr18-adapter": "For using Requests as a PSR-18 HTTP Client",
"ext-curl": "For improved performance",
"ext-openssl": "For secure transport support",
"ext-zlib": "For improved performance when decompressing encoded streams"
"requests/test-server": "dev-master"
},
"type": "library",
"autoload": {
"files": [
"library/Deprecated.php"
],
"psr-4": {
"WpOrg\\Requests\\": "src/"
},
"classmap": [
"library/Requests.php"
]
"psr-0": {
"Requests": "library/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@ -60,23 +40,11 @@
"authors": [
{
"name": "Ryan McCue",
"homepage": "https://rmccue.io/"
},
{
"name": "Alain Schlesser",
"homepage": "https://github.com/schlessera"
},
{
"name": "Juliette Reinders Folmer",
"homepage": "https://github.com/jrfnl"
},
{
"name": "Contributors",
"homepage": "https://github.com/WordPress/Requests/graphs/contributors"
"homepage": "http://ryanmccue.info"
}
],
"description": "A HTTP library written in PHP, for human beings.",
"homepage": "https://requests.ryanmccue.info/",
"homepage": "http://github.com/rmccue/Requests",
"keywords": [
"curl",
"fsockopen",
@ -86,12 +54,7 @@
"iri",
"sockets"
],
"support": {
"docs": "https://requests.ryanmccue.info/",
"issues": "https://github.com/WordPress/Requests/issues",
"source": "https://github.com/WordPress/Requests"
},
"time": "2024-12-11T09:46:32+00:00"
"time": "2016-10-13 00:11:37"
}
],
"packages-dev": [],
@ -103,6 +66,5 @@
"platform": {
"php": ">=7.1"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"
"platform-dev": []
}

View file

@ -67,20 +67,6 @@
return $this;
}
/**
* Auth using 2FA Push.
* This isn't a real auth type, but will get us a 2fa code to use.
*
* @param $user User to auth with
* @param $pass Password to auth with
* @return $this for chaining.
*/
public function doAuth2FAPush($user, $pass) {
$auth = ['type' => 'userpass', 'user' => $user, 'pass' => $pass, '2fa_push' => true];
return $this->api('/session', 'GET', [], $auth);
}
/**
* Auth using a username and api key.
*
@ -116,17 +102,6 @@
return $this;
}
/**
* Auth using JWT Token.
*
* @param $token Token to auth with
* @return $this for chaining.
*/
public function setAuthJWT($token) {
$this->auth = ['type' => 'jwt', 'token' => $token];
return $this;
}
/**
* Auth using a custom auth method.
*
@ -199,13 +174,11 @@
* Register a new account.
*
* @param $email Email address
* @param $name Real name
* @param $acceptTerms Do we accept the terms of registration?
* @param $name Real namereturn isset($result['response']) ? $result['response'] : NULL;/sessi
* @return Data from API
*/
public function register($email, $name, $acceptTerms = false) {
$registrationData = ['email' => $email, 'realname' => $name, 'acceptterms' => $acceptTerms];
return $this->api('/register', 'POST', $registrationData);
public function register($email, $name) {
return $this->api('/register', 'POST', ['email' => $email, 'realname' => $name]);
}
/**
@ -230,16 +203,6 @@
return $this->api('/users/' . $userid . '/resendwelcome', 'POST', []);
}
/**
* Accept the terms of service.
*
* @param $user (Optional) User ID - defaults to self.
* @return Data from API
*/
public function acceptTerms($userid = 'self') {
return $this->api('/users/' . $userid . '/acceptterms', 'POST', ['acceptterms' => "true"]);
}
/**
* Submit a password reset request
*
@ -305,17 +268,11 @@
*
* @return Result from the API.
*/
public function getSystemDataValue($key, $all = false) {
if (empty($key)) { return NULL; }
public function getSystemDataValue($key) {
if ($this->auth === FALSE || empty($key)) { return NULL; }
$result = $this->api('/system/datavalue/' . $key);
if ($all && isset($result['response'])) {
return $result['response'];
} else if (!$all && isset($result['response'][$key])) {
return $result['response'][$key];
} else {
return NULL;
}
return isset($result['response'][$key]) ? $result['response'][$key] : NULL;
}
/**
@ -395,20 +352,6 @@
return $this->api('/users/' . $userID, 'DELETE');
}
/**
* Confirm delete the given user id
*
* @param $userid User ID to delete.
* @param $confirmCode Confirmation code.
* @param $twoFactorCode Optional twofactor code.
* @return Result from the api
*/
public function deleteUserConfirm($userID, $confirmCode, $twoFactorCode = '') {
if ($this->auth === FALSE) { return []; }
return $this->api('/users/' . $userID . '/confirm/' . $confirmCode . (!empty($twoFactorCode) ? '/' . $twoFactorCode : ''), 'DELETE');
}
/**
* Get API Keys for a user
*
@ -609,18 +552,6 @@
return $this->api('/users/' . $userid . '/customdata/' . $key, 'DELETE');
}
/**
* Get a JWT Token from the backend
*
* @return Backend JWT Token or null if we are not authed.
*/
public function getJWTToken() {
if ($this->auth === FALSE) { return NULL; }
$result = $this->api('/session/jwt');
return isset($result['response']['token']) ? $result['response']['token'] : NULL;
}
/**
* Get a session ID from the backend
*
@ -651,7 +582,7 @@
* @param $value (Default: true) Set value for domain admin override.
*/
public function domainAdmin($value = true) {
$this->domainAdmin = $value;
$this->domainAdmin = true;
return $this;
}
@ -659,17 +590,12 @@
/**
* Get list of our domains.
*
* @param $queryParams (Optional) Array of query params to use.
* @return Array of domains or an empty array.
*/
public function getDomains($queryParams = []) {
public function getDomains() {
if ($this->auth === FALSE) { return []; }
$url = ($this->domainAdmin ? '/admin' : '') . '/domains';
$qs = http_build_query($queryParams);
if (!empty($qs)) { $url .= '?' . $qs; }
$result = $this->api($url);
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains');
return isset($result['response']) ? $result['response'] : [];
}
@ -739,7 +665,7 @@
if ($this->auth === FALSE) { return []; }
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/access');
return isset($result['response']) ? $result['response'] : [];
return isset($result['response']['access']) ? $result['response']['access'] : [];
}
/**
@ -769,24 +695,11 @@
return isset($result['response']['stats']) ? $result['response']['stats'] : [];
}
/**
* Get domain logs
*
* @param $domain Domain to get logs for.
* @return Array of logs.
*/
public function getDomainLogs($domain) {
if ($this->auth === FALSE) { return []; }
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/logs', 'GET', $options);
return isset($result['response']) ? $result['response'] : [];
}
/**
* Attempt to sync the domain to the backends.
*
* @param $domain Domain to sync.
* @return API Result
* @param $domain Domain to export.
* @return Array of records or an empty array.
*/
public function syncDomain($domain) {
if ($this->auth === FALSE) { return []; }
@ -794,29 +707,16 @@
return $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/sync');
}
/**
* Attempt to verify a domain.
*
* @param $domain Domain to verify
* @return API Result
*/
public function verifyDomain($domain) {
if ($this->auth === FALSE) { return []; }
return $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/verify');
}
/**
* Export domain as bind zone file.
*
* @param $domain Domain to export.
* @param $type (Optional) Format to export as
* @return Array of records or an empty array.
*/
public function exportZone($domain, $type = NULL) {
public function exportZone($domain) {
if ($this->auth === FALSE) { return []; }
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/export' . ($type !== NULL ? '/' . $type : ''));
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/export');
return isset($result['response']['zone']) ? $result['response']['zone'] : [];
}
@ -825,13 +725,12 @@
*
* @param $domain Domain to import.
* @param $zone Zonefile data
* @param $type (Optional) Format to import from as
* @return Array of records or an empty array.
*/
public function importZone($domain, $zone, $type = NULL) {
public function importZone($domain, $zone) {
if ($this->auth === FALSE) { return []; }
return $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/import' . ($type !== NULL ? '/' . $type : ''), 'POST', ['zone' => $zone]);
return $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/import', 'POST', ['zone' => $zone]);
}
@ -845,7 +744,7 @@
if ($this->auth === FALSE) { return []; }
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/records');
return isset($result['response']) ? $result['response'] : [];
return isset($result['response']['records']) ? $result['response']['records'] : [];
}
/**
@ -1052,141 +951,6 @@
return $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/hooks/' . $hookid, 'DELETE');
}
/**
* Get articles.
*
* @return Result from the API.
*/
public function getArticles() {
$result = $this->api('/articles');
return isset($result['response']) ? $result['response'] : [];
}
/**
* Get all articles.
*
* @return Result from the API.
*/
public function getAllArticles() {
if ($this->auth === FALSE) { return []; }
$result = $this->api('/admin/articles');
return isset($result['response']) ? $result['response'] : [];
}
/**
* Crate a new article.
*
* @param $data Data for create
* @return Result from the API.
*/
public function createArticle($data) {
if ($this->auth === FALSE) { return []; }
return $this->api('/admin/articles', 'POST', $data);
}
/**
* Get a specific article.
*
* @param $articleid Article to get
* @return Result from the API.
*/
public function getArticle($articleid) {
if ($this->auth === FALSE) { return []; }
$result = $this->api('/admin/articles/' . $articleid);
return isset($result['response']) ? $result['response'] : [];
}
/**
* Update a specific article.
*
* @param $articleid Article to update
* @param $data Data for update
* @return Result from the API.
*/
public function updateArticle($articleid, $data) {
if ($this->auth === FALSE) { return []; }
return $this->api('/admin/articles/' . $articleid, 'POST', $data);
}
/**
* Delete a specific article.
*
* @param $articleid Article to delete
* @return Result from the API.
*/
public function deleteArticle($articleid) {
if ($this->auth === FALSE) { return []; }
return $this->api('/admin/articles/' . $articleid, 'DELETE');
}
/**
* Get all blockregexes.
*
* @return Result from the API.
*/
public function getAllBlockRegexes() {
if ($this->auth === FALSE) { return []; }
$result = $this->api('/admin/blockregexes');
return isset($result['response']) ? $result['response'] : [];
}
/**
* Create a new blockregex.
*
* @param $data Data for create
* @return Result from the API.
*/
public function createBlockRegex($data) {
if ($this->auth === FALSE) { return []; }
return $this->api('/admin/blockregexes', 'POST', $data);
}
/**
* Get a specific blockregex.
*
* @param $blockregexid BlockRegex to get
* @return Result from the API.
*/
public function getBlockRegex($blockregexid) {
if ($this->auth === FALSE) { return []; }
$result = $this->api('/admin/blockregexes/' . $blockregexid);
return isset($result['response']) ? $result['response'] : [];
}
/**
* Update a specific blockregex.
*
* @param $blockregexid BlockRegex to update
* @param $data Data for update
* @return Result from the API.
*/
public function updateBlockRegex($blockregexid, $data) {
if ($this->auth === FALSE) { return []; }
return $this->api('/admin/blockregexes/' . $blockregexid, 'POST', $data);
}
/**
* Delete a specific blockregex.
*
* @param $blockregexid BlockRegex to delete
* @return Result from the API.
*/
public function deleteBlockRegex($blockregexid) {
if ($this->auth === FALSE) { return []; }
return $this->api('/admin/blockregexes/' . $blockregexid, 'DELETE');
}
/**
* Get the last response from the API
*
@ -1202,32 +966,24 @@
* @param $apimethod API Method to poke
* @param $method Request method to access the API with
* @param $data (Default: []) Data to send if POST
* @param $auth (Default: []) Custom auth data to use for just this request.
* @return Response from the API as an array.
*/
public function api($apimethod, $method = 'GET', $data = [], $auth = NULL) {
private function api($apimethod, $method = 'GET', $data = []) {
$headers = [];
$options = [];
if ($auth == NULL) { $auth = $this->auth; }
if ($auth !== FALSE) {
if ($auth['type'] == 'jwt') {
$headers['Authorization'] = 'Bearer ' . $auth['token'];
} else if ($auth['type'] == 'session') {
$headers['X-SESSION-ID'] = $auth['sessionid'];
} else if ($auth['type'] == 'userkey') {
$headers['X-API-USER'] = $auth['user'];
$headers['X-API-KEY'] = $auth['key'];
} else if ($auth['type'] == 'domainkey') {
$headers['X-DOMAIN'] = $auth['domain'];
$headers['X-DOMAIN-KEY'] = $auth['key'];
} else if ($auth['type'] == 'userpass') {
$options['auth'] = [$auth['user'], $auth['pass']];
if (isset($auth['2fa'])) {
$headers['X-2FA-KEY'] = $auth['2fa'];
}
if (isset($auth['2fa_push'])) {
$headers['X-2FA-PUSH'] = $auth['2fa_push'];
if ($this->auth !== FALSE) {
if ($this->auth['type'] == 'session') {
$headers['X-SESSION-ID'] = $this->auth['sessionid'];
} else if ($this->auth['type'] == 'userkey') {
$headers['X-API-USER'] = $this->auth['user'];
$headers['X-API-KEY'] = $this->auth['key'];
} else if ($this->auth['type'] == 'domainkey') {
$headers['X-DOMAIN'] = $this->auth['domain'];
$headers['X-DOMAIN-KEY'] = $this->auth['key'];
} else if ($this->auth['type'] == 'userpass') {
$options['auth'] = [$this->auth['user'], $this->auth['pass']];
if (isset($this->auth['2fa'])) {
$headers['X-2FA-KEY'] = $this->auth['2fa'];
}
}
}
@ -1247,10 +1003,6 @@
try {
if ($method == 'GET') {
if (!is_array($data)) {
$data = empty($data) ? [] : ['data' => $data];
}
if (count($data) > 0) {
$url = parse_url($url);
if (isset($url['query'])) {