PluginProbe
Hostinger Tools / 2.1.9
Hostinger Tools v2.1.9
3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 All 108 releases
hostinger / includes / Requests / Client.php

Client.php in Hostinger Tools 2.1.9, at includes/Requests/Client.php

47 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hostinger\Requests;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class Client {
8 private string $api_url;
9 private array $default_headers;
10
11 public function __construct( $api_url, $default_headers = array() ) {
12 $this->api_url = $api_url;
13 $this->default_headers = $default_headers;
14 }
15
16 public function get( $endpoint, $params = array(), $headers = array(), $timeout = 120 ) {
17 $url = $this->api_url . $endpoint;
18 $request_args = array(
19 'method' => 'GET',
20 'headers' => array_merge( $this->default_headers, $headers ),
21 'timeout' => $timeout,
22 );
23
24 if ( ! empty( $params ) ) {
25 $url = add_query_arg( $params, $url );
26 }
27
28 $response = wp_remote_get( $url, $request_args );
29
30 return $response;
31 }
32
33 public function post( $endpoint, $params = array(), $headers = array(), $timeout = 120 ) {
34 $url = $this->api_url . $endpoint;
35 $request_args = array(
36 'method' => 'POST',
37 'timeout' => $timeout,
38 'headers' => array_merge( $this->default_headers, $headers ),
39 'body' => $params,
40 );
41
42 $response = wp_remote_post( $url, $request_args );
43
44 return $response;
45 }
46 }
47