forked from InfinityFreeHosting/mofh-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major refactor of entire API client (InfinityFreeHosting#61)
* Big refactor of the entire API client - Remove the separate Request classes, the Client just returns the Responses themselves. - The Client functions now take their input parameters as function arguments, instead of using an array. - Use custom exception classes for Guzzle errors and custom logic errors. - Add isAvailable method to AvailabilityResponse, isSuccessful also returns true if a domain is not found but no error was returned. - Add pre-commit with various linters. - Completely rewrite the test suite to use Guzzle mocks. * Remove Pint for PHP 7 support * Downgrade php-cs-fixer for old PHP versions * Enhance documentation * Fix timeout settings
- Loading branch information
Showing
45 changed files
with
1,214 additions
and
2,000 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,15 @@ jobs: | |
php_version: "${{ matrix.php_version }}" | ||
- uses: php-actions/phpunit@v3 | ||
with: | ||
configuration: "phpunit.xml.dist" | ||
configuration: "phpunit.xml" | ||
php_version: "${{ matrix.php_version }}" | ||
version: "9" | ||
|
||
pre-commit: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: php-actions/composer@v6 | ||
- uses: actions/setup-python@v3 | ||
- uses: pre-commit/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
$config = new \PhpCsFixer\Config(); | ||
$config->setRules([ | ||
'braces' => false, | ||
]); | ||
|
||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-case-conflict | ||
- id: check-executables-have-shebangs | ||
- id: check-json | ||
- id: check-merge-conflict | ||
- id: check-shebang-scripts-are-executable | ||
- id: check-symlinks | ||
- id: check-toml | ||
- id: check-xml | ||
- id: check-yaml | ||
- id: destroyed-symlinks | ||
- id: detect-private-key | ||
- id: end-of-file-fixer | ||
- id: fix-byte-order-marker | ||
- id: mixed-line-ending | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/InfinityFreeHosting/pre-commit-php | ||
rev: 1.3.1 | ||
hooks: | ||
- id: php-lint | ||
# - id: php-cs | ||
# - id: php-cbf | ||
- id: php-cs-fixer | ||
args: | ||
- --config=.php-cs-fixer.php | ||
# - id: pint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# MyOwnFreeHost API Client | ||
|
||
An API client to use the free hosting system from [MyOwnFreeHost](https://myownfreehost.net). | ||
|
||
**IMPORTANT: THIS LIBRARY IS AIMED AT EXPERIENCED PHP DEVELOPERS. Experience with object-oriented PHP and Composer is required. If you can't use oo-PHP and Composer, don't bother with this library.** | ||
|
@@ -12,29 +13,33 @@ composer require infinityfree/mofh-client | |
``` | ||
|
||
## Usage | ||
|
||
Before you can get started, you need to get the API credentials from MyOwnFreeHost. Login to the [reseller panel](https://panel.myownfreehost.net), go to API -> Setup WHM API -> select the domain you want to configure. Copy the API Username and API password and set your own IP address as the Allowed IP Address (the IP address of your computer, server, or wherever you want to use this API client). | ||
|
||
### Available Methods | ||
|
||
The MyOwnFreeHost API exposes the following methods. The available parameters are listed below. | ||
- createAccount | ||
|
||
- createAccount: Create a new hosting account. | ||
- username: A unique, 8 character identifier of the account. | ||
- password: A password to login to the control panel, FTP and databases. | ||
- domain: A domain name to create the account. Can be a subdomain or a custom domain. | ||
- email: The email address of the user. | ||
- plan: The name of the hosting plan to create the account on. Requires a hosting package to be configured through MyOwnFreeHost. | ||
- suspend | ||
- suspend: Suspend a hosting account. | ||
- username: The unique, 8 character identifier of the account. | ||
- reason: A string with information about why you are suspending the account. | ||
- linked: If true, related accounts will be suspended as well. | ||
- unsuspend | ||
- unsuspend: Reactivate a hosting account. | ||
- username: The unique, 8 character identifier of the account. | ||
- password | ||
- password: Change the password of a hosting account. | ||
- username: The unique, 8 character identifier of the account. | ||
- password: The new password to set for the account. | ||
- availability | ||
- availability: Check if a given domain name is available to be added to an account. | ||
- domain: The domain name or subdomain to check. | ||
- getUserDomains | ||
- getUserDomains: Get the domain names linked to a given account. | ||
- username: The vistaPanel login username (e.g. abcd_12345678). | ||
- getDomainUser | ||
- getDomainUser: Get the information of a particular hosting domain name, including the account it's hosted on and the document root. | ||
- domain: The domain name to search for. | ||
|
||
### Example | ||
|
@@ -43,35 +48,29 @@ The MyOwnFreeHost API exposes the following methods. The available parameters ar | |
use \InfinityFree\MofhClient\Client; | ||
|
||
// Create a new API client with your API credentials. | ||
$client = Client::create([ | ||
'apiUsername' => 'your_api_username', | ||
'apiPassword' => 'your_api_password', | ||
'plan' => 'my_plan', // Optional, you can define it here or define it with the createAccount call. | ||
]); | ||
|
||
// Create a request object to create the request. | ||
$request = $client->createAccount([ | ||
'username' => 'abcdefgh', // A unique, 8 character identifier of the account. | ||
'password' => 'password123', // A password to login to the control panel, FTP and databases. | ||
'domain' => 'userdomain.example.com', // Can be a subdomain or a custom domain. | ||
'email' => '[email protected]', // The email address of the user. | ||
'plan' => 'my_plan', // Optional, you can submit a hosting plan here or with the Client instantiation. | ||
]); | ||
|
||
// Send the API request and keep the response. | ||
$response = $request->send(); | ||
$client = new Client("<MOFH API username>", "<MOFH API password>"); | ||
|
||
// Create a new hosting account. | ||
$createResponse = $client->createAccount( | ||
'abcd1234', // A unique, 8 character identifier of the account. Primarily used as internal identifier. | ||
'password123', // A password to login to the control panel, FTP and databases. | ||
'[email protected]', // The email address of the user. | ||
'userdomain.example.com', // Initial domain of the account. Can be a subdomain or a custom domain. | ||
'my_plan', // The hosting plan name at MyOwnFreeHost. | ||
); | ||
|
||
// Check whether the request was successful. | ||
if ($response->isSuccessful()) { | ||
echo 'You can login as: ' . $response->getVpUsername(); | ||
if ($createResponse->isSuccessful()) { | ||
echo "Created account with username: ".$createResponse->getVpUsername(); | ||
} else { | ||
echo 'Failed to create account: ' . $response->getMessage(); | ||
die(); | ||
} | ||
``` | ||
|
||
## License | ||
|
||
Copyright 2020 Hans Adema | ||
Copyright 2023 InfinityFree | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"> | ||
<coverage> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.