Compare commits

..

38 commits
0.4 ... master

Author SHA1 Message Date
dependabot[bot]
f4744d10fd Bump rmccue/requests from 2.0.13 to 2.0.14
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.13 to 2.0.14.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.13...v2.0.14)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-11 20:30:00 +00:00
dependabot[bot]
1171642992 Bump rmccue/requests from 2.0.12 to 2.0.13
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.12 to 2.0.13.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.12...v2.0.13)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-29 20:46:13 +00:00
dependabot[bot]
c9d8e4ad61 Bump rmccue/requests from 2.0.11 to 2.0.12
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.11 to 2.0.12.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.11...v2.0.12)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-08 20:35:24 +00:00
dependabot[bot]
674be0f7fc Bump rmccue/requests from 2.0.10 to 2.0.11
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.10 to 2.0.11.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.10...v2.0.11)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-25 20:42:43 +00:00
dependabot[bot]
6128e82393 Bump rmccue/requests from 2.0.9 to 2.0.10
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.9 to 2.0.10.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.9...v2.0.10)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-08 20:51:37 +00:00
dependabot[bot]
17c53f7e7b Bump rmccue/requests from 2.0.8 to 2.0.9
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.8 to 2.0.9.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.8...v2.0.9)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-08 20:03:11 +00:00
dependabot[bot]
9bd1144042 Bump rmccue/requests from 2.0.7 to 2.0.8
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.7 to 2.0.8.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.7...v2.0.8)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 20:51:57 +00:00
Shane Mc Cormack
bfdab54f92 Update automerge.yml to shared 2023-08-09 05:45:37 +01:00
Shane Mc Cormack
a65579ee42 Update automerge.yml 2023-08-09 04:52:57 +01:00
dependabot[bot]
3e8ab8ed1b Bump rmccue/requests from 2.0.6 to 2.0.7
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.6 to 2.0.7.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.6...v2.0.7)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-02 20:57:36 +00:00
dependabot[bot]
3c5b7d4bc3 Bump rmccue/requests from 2.0.5 to 2.0.6
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.5 to 2.0.6.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.5...v2.0.6)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-14 04:36:26 +00:00
Shane Mc Cormack
a251147362 Automerge some dependabot PRs 2023-04-14 05:35:18 +01:00
Shane Mc Cormack
398e96c475 Fix fatal error if data given is not an array. 2022-11-22 07:13:36 +00:00
dependabot[bot]
98fa8b4c50 Bump rmccue/requests from 2.0.3 to 2.0.5
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.3 to 2.0.5.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.3...v2.0.5)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-22 06:54:31 +00:00
Shane Mc Cormack
d7d25e7a2e Add verifyDomain method. 2022-11-22 06:46:34 +00:00
dependabot[bot]
2f7b1a7e57 Bump rmccue/requests from 2.0.0 to 2.0.3
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 2.0.0 to 2.0.3.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v2.0.0...v2.0.3)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-05-26 20:05:33 +01:00
dependabot[bot]
c136026ef8 Bump rmccue/requests from 1.8.1 to 2.0.0
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 1.8.1 to 2.0.0.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-31 17:48:02 +00:00
dependabot[bot]
92e696cbe9 Bump rmccue/requests from 1.8.0 to 1.8.1
Bumps [rmccue/requests](https://github.com/WordPress/Requests) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/WordPress/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/WordPress/Requests/compare/v1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: rmccue/requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-05 03:26:06 +01:00
dependabot-preview[bot]
6e34fe92ff Upgrade to GitHub-native Dependabot 2021-05-02 23:20:06 +01:00
dependabot-preview[bot]
392e17d6f9 [Security] Bump rmccue/requests from 1.7.0 to 1.8.0
Bumps [rmccue/requests](https://github.com/rmccue/Requests) from 1.7.0 to 1.8.0. **This update includes a security fix.**
- [Release notes](https://github.com/rmccue/Requests/releases)
- [Changelog](https://github.com/WordPress/Requests/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rmccue/Requests/compare/v1.7.0...v1.8.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-28 11:25:04 +01:00
Shane Mc Cormack
c6728e4148 Fix BlockRegex CRUD. mydnshost/mydnshost-api#127 2021-04-03 07:21:38 +01:00
Shane Mc Cormack
203c6b01bb Add CRUD for BlockRegexes. 2021-04-03 07:10:24 +01:00
Shane Mc Cormack
e61399564d Allow getting multiple results from getSystemDataValue. 2020-08-04 07:58:13 +01:00
Shane Mc Cormack
687ad9c2e3 Support import/export formats. 2019-10-13 01:56:59 +01:00
Shane Mc Cormack
e4b45c9365 Probably shouldn't just ignore this param... 2019-07-13 20:36:35 +01:00
Shane Mc Cormack
59c7525150 Support for JWT Tokens. 2019-06-23 23:59:22 +01:00
Shane Mc Cormack
784268b94e Allow passing query params to the getDomains() call. 2019-04-15 22:09:51 +01:00
Shane Mc Cormack
78faf324ad Ground work for 2FA Push. mydnshost/mydnshost-api#35 2019-03-10 22:36:49 +00:00
Shane Mc Cormack
69f8584a0f Include data for updateArticle. 2019-03-10 19:55:36 +00:00
Shane Mc Cormack
92d5d03f8d Article things. 2019-03-10 19:13:07 +00:00
Shane Mc Cormack
b4fb05808b getDomainAccess() should return all data that the API gives us. 2019-03-10 06:34:37 +00:00
Shane Mc Cormack
4bc32e6b37 getDomainRecords should allow us to access other data as well. 2019-03-08 03:15:49 +00:00
Shane Mc Cormack
766233bb98 Add support for /articles end point. 2018-11-12 03:04:31 +00:00
Shane Mc Cormack
21ee8316b4 Add getDomainLogs() 2018-09-13 05:54:42 +01:00
Shane Mc Cormack
3202472ab7 Make api() public to allow interacting with unsupported APIs. 2018-09-13 03:55:15 +01:00
Shane Mc Cormack
62be53aee1 Add api call for accepting terms. 2018-06-11 05:40:08 +01:00
Shane Mc Cormack
ca882f9c9c Add support for requiring terms of service. 2018-06-11 04:38:46 +01:00
Shane Mc Cormack
123122c1de Add confirmed delete. 2018-06-11 04:00:25 +01:00
5 changed files with 356 additions and 49 deletions

7
.github/dependabot.yml vendored Normal file
View file

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

14
.github/workflows/automerge.yml vendored Normal file
View file

@ -0,0 +1,14 @@
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": "^1.7"
"rmccue/requests": "^2.0"
},
"autoload": {
"psr-0": {

72
composer.lock generated
View file

@ -1,37 +1,57 @@
{
"_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#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"hash": "cb150c262c5789b25121c563653566ff",
"content-hash": "0e9868a816da68c50ceb0f080e96fe30",
"content-hash": "55d65ecd209ff9bb30f393746ff9b81d",
"packages": [
{
"name": "rmccue/requests",
"version": "v1.7.0",
"version": "v2.0.14",
"source": {
"type": "git",
"url": "https://github.com/rmccue/Requests.git",
"reference": "87932f52ffad70504d93f04f15690cf16a089546"
"url": "https://github.com/WordPress/Requests.git",
"reference": "9b228eef149e1752b037bf79cef4ca73a7b1fea1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/rmccue/Requests/zipball/87932f52ffad70504d93f04f15690cf16a089546",
"reference": "87932f52ffad70504d93f04f15690cf16a089546",
"url": "https://api.github.com/repos/WordPress/Requests/zipball/9b228eef149e1752b037bf79cef4ca73a7b1fea1",
"reference": "9b228eef149e1752b037bf79cef4ca73a7b1fea1",
"shasum": ""
},
"require": {
"php": ">=5.2"
"ext-json": "*",
"php": ">=5.6"
},
"require-dev": {
"requests/test-server": "dev-master"
"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"
},
"type": "library",
"autoload": {
"psr-0": {
"Requests": "library/"
}
"files": [
"library/Deprecated.php"
],
"psr-4": {
"WpOrg\\Requests\\": "src/"
},
"classmap": [
"library/Requests.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@ -40,11 +60,23 @@
"authors": [
{
"name": "Ryan McCue",
"homepage": "http://ryanmccue.info"
"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"
}
],
"description": "A HTTP library written in PHP, for human beings.",
"homepage": "http://github.com/rmccue/Requests",
"homepage": "https://requests.ryanmccue.info/",
"keywords": [
"curl",
"fsockopen",
@ -54,7 +86,12 @@
"iri",
"sockets"
],
"time": "2016-10-13 00:11:37"
"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"
}
],
"packages-dev": [],
@ -66,5 +103,6 @@
"platform": {
"php": ">=7.1"
},
"platform-dev": []
"platform-dev": [],
"plugin-api-version": "2.6.0"
}

View file

@ -67,6 +67,20 @@
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.
*
@ -102,6 +116,17 @@
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.
*
@ -174,11 +199,13 @@
* Register a new account.
*
* @param $email Email address
* @param $name Real namereturn isset($result['response']) ? $result['response'] : NULL;/sessi
* @param $name Real name
* @param $acceptTerms Do we accept the terms of registration?
* @return Data from API
*/
public function register($email, $name) {
return $this->api('/register', 'POST', ['email' => $email, 'realname' => $name]);
public function register($email, $name, $acceptTerms = false) {
$registrationData = ['email' => $email, 'realname' => $name, 'acceptterms' => $acceptTerms];
return $this->api('/register', 'POST', $registrationData);
}
/**
@ -203,6 +230,16 @@
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
*
@ -268,11 +305,17 @@
*
* @return Result from the API.
*/
public function getSystemDataValue($key) {
if ($this->auth === FALSE || empty($key)) { return NULL; }
public function getSystemDataValue($key, $all = false) {
if (empty($key)) { return NULL; }
$result = $this->api('/system/datavalue/' . $key);
return isset($result['response'][$key]) ? $result['response'][$key] : NULL;
if ($all && isset($result['response'])) {
return $result['response'];
} else if (!$all && isset($result['response'][$key])) {
return $result['response'][$key];
} else {
return NULL;
}
}
/**
@ -352,6 +395,20 @@
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
*
@ -552,6 +609,18 @@
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
*
@ -582,7 +651,7 @@
* @param $value (Default: true) Set value for domain admin override.
*/
public function domainAdmin($value = true) {
$this->domainAdmin = true;
$this->domainAdmin = $value;
return $this;
}
@ -590,12 +659,17 @@
/**
* 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() {
public function getDomains($queryParams = []) {
if ($this->auth === FALSE) { return []; }
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains');
$url = ($this->domainAdmin ? '/admin' : '') . '/domains';
$qs = http_build_query($queryParams);
if (!empty($qs)) { $url .= '?' . $qs; }
$result = $this->api($url);
return isset($result['response']) ? $result['response'] : [];
}
@ -665,7 +739,7 @@
if ($this->auth === FALSE) { return []; }
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/access');
return isset($result['response']['access']) ? $result['response']['access'] : [];
return isset($result['response']) ? $result['response'] : [];
}
/**
@ -695,11 +769,24 @@
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 export.
* @return Array of records or an empty array.
* @param $domain Domain to sync.
* @return API Result
*/
public function syncDomain($domain) {
if ($this->auth === FALSE) { return []; }
@ -707,16 +794,29 @@
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) {
public function exportZone($domain, $type = NULL) {
if ($this->auth === FALSE) { return []; }
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/export');
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/export' . ($type !== NULL ? '/' . $type : ''));
return isset($result['response']['zone']) ? $result['response']['zone'] : [];
}
@ -725,12 +825,13 @@
*
* @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) {
public function importZone($domain, $zone, $type = NULL) {
if ($this->auth === FALSE) { return []; }
return $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/import', 'POST', ['zone' => $zone]);
return $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/import' . ($type !== NULL ? '/' . $type : ''), 'POST', ['zone' => $zone]);
}
@ -744,7 +845,7 @@
if ($this->auth === FALSE) { return []; }
$result = $this->api(($this->domainAdmin ? '/admin' : '') . '/domains/' . $domain . '/records');
return isset($result['response']['records']) ? $result['response']['records'] : [];
return isset($result['response']) ? $result['response'] : [];
}
/**
@ -951,6 +1052,141 @@
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
*
@ -966,24 +1202,32 @@
* @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.
*/
private function api($apimethod, $method = 'GET', $data = []) {
public function api($apimethod, $method = 'GET', $data = [], $auth = NULL) {
$headers = [];
$options = [];
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'];
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'];
}
}
}
@ -1003,6 +1247,10 @@
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'])) {