ActivationForm.php
4 years ago
CheckForm.php
4 years ago
Endpoint.php
4 years ago
License.php
4 years ago
RequestResponse.php
4 years ago
Updater.php
4 years ago
Endpoint.php
56 lines
| 1 | <?php |
| 2 | namespace Kubio\Core\License; |
| 3 | |
| 4 | use WP_Error; |
| 5 | use WP_Http; |
| 6 | |
| 7 | class Endpoint { |
| 8 | |
| 9 | |
| 10 | /** |
| 11 | * @return RequestResponse |
| 12 | */ |
| 13 | public static function activate() { |
| 14 | $content = static::request( License::getInstance()->getActivateEndpoint(), 'POST' ); |
| 15 | |
| 16 | return new RequestResponse( $content ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @param $url |
| 21 | * @param string $method |
| 22 | * |
| 23 | * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. |
| 24 | * |
| 25 | */ |
| 26 | private static function request( $url, $method = 'GET' ) { |
| 27 | $http = new WP_Http(); |
| 28 | $body = array( |
| 29 | 'project_url' => get_option( 'kubio_sync_data_source', '' ), |
| 30 | 'license' => License::getInstance()->getLicenseKey(), |
| 31 | ); |
| 32 | |
| 33 | $body = apply_filters( 'kubio/endpoints/request_body', $body ); |
| 34 | |
| 35 | return $http->request( |
| 36 | $url, |
| 37 | array( |
| 38 | 'method' => $method, |
| 39 | 'timeout' => 30, |
| 40 | 'user-agent' => 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), |
| 41 | 'sslverify' => false, |
| 42 | 'body' => $body, |
| 43 | ) |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @return RequestResponse |
| 49 | */ |
| 50 | public static function check() { |
| 51 | $content = static::request( License::getInstance()->getCheckEndpoint(), 'POST' ); |
| 52 | |
| 53 | return new RequestResponse( $content ); |
| 54 | } |
| 55 | } |
| 56 |