PluginProbe
SendWP / 1.1
SendWP v1.1
trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.2.10 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.4.4 1.4.5 1.4.6 1.4.8
sendwp / includes / api / class.request.php

class.request.php in SendWP 1.1, at includes/api/class.request.php

55 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SendWP\API;
4
5 class Request
6 {
7 protected $server_url;
8 protected $endpoint;
9 protected $client_name;
10 protected $client_secret;
11
12 public static function create( $endpoint )
13 {
14 $server_url = sendwp_get_server_url();
15 $client_name = sendwp_get_client_name();
16 $client_secret = sendwp_get_client_secret();
17 return new self( $server_url, $endpoint, $client_name, $client_secret );
18 }
19
20 public function __construct( $server_url, $endpoint, $client_name, $client_secret )
21 {
22 $this->server_url = $server_url;
23 $this->set_endpoint( $endpoint );
24 $this->client_name = $client_name;
25 $this->client_secret = $client_secret;
26 }
27
28 public function set_endpoint( $target )
29 {
30 $this->endpoint = 'wp-json/sendwp/' . $target;
31 }
32
33 public function request_url()
34 {
35 return $this->server_url . $this->endpoint;
36 }
37
38 public function post( $args )
39 {
40 return $this->request( 'POST', $args );
41 }
42
43 public function request( $method, $args )
44 {
45 $args[ 'method' ] = $method;
46 $args['reject_unsafe_urls'] = false; // Whitelist requests to the service.
47 $args[ 'headers' ][ 'x-sendwp-client-auth' ] = $this->get_auth_headers();
48 return wp_remote_request( $this->request_url(), $args );
49 }
50
51 protected function get_auth_headers()
52 {
53 return 'Basic ' . base64_encode( $this->client_name . ':' . $this->client_secret );
54 }
55 }