Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| HiiveWorker | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| request | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\Data; |
| 4 | |
| 5 | /** |
| 6 | * Class HiiveWorker |
| 7 | * |
| 8 | * Base class for Hiive Worker related actions. |
| 9 | * |
| 10 | * @package NewfoldLabs\WP\Module\Data |
| 11 | */ |
| 12 | class HiiveWorker { |
| 13 | |
| 14 | /** |
| 15 | * The URL of the worker. |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | protected $url; |
| 20 | |
| 21 | /** |
| 22 | * The endpoint of the worker URL. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | protected $endpoint; |
| 27 | |
| 28 | /** |
| 29 | * HiiveWorker constructor. |
| 30 | * |
| 31 | * @param string $endpoint The endpoint of the worker URL. |
| 32 | */ |
| 33 | public function __construct( $endpoint ) { |
| 34 | |
| 35 | if ( ! defined( 'NFD_HIIVE_BASE_URL' ) ) { |
| 36 | define( 'NFD_HIIVE_BASE_URL', 'https://hiive.cloud' ); |
| 37 | } |
| 38 | |
| 39 | $this->endpoint = $endpoint; |
| 40 | $this->url = NFD_HIIVE_BASE_URL . '/workers/' . $endpoint; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Places an HTTP request to the Hiive CF worker. |
| 45 | * |
| 46 | * @param string $method The HTTP request method (GET, POST, ....). |
| 47 | * @param array $args The HTTP request arguments (headers, body, ...) |
| 48 | * @return array |
| 49 | */ |
| 50 | public function request( $method, $args ) { |
| 51 | $args['method'] = $method; |
| 52 | |
| 53 | return \wp_remote_request( |
| 54 | $this->url, |
| 55 | $args |
| 56 | ); |
| 57 | } |
| 58 | } |