PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.3.1
JetFormBuilder — Dynamic Blocks Form Builder v3.3.1
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / integrations / integration-base.php
jetformbuilder / includes / integrations Last commit date
getresponse-handler.php 2 years ago integration-base.php 2 years ago mailchimp-handler.php 2 years ago
integration-base.php
71 lines
1 <?php
2
3 namespace Jet_Form_Builder\Integrations;
4
5 use Jet_Form_Builder\Exceptions\Action_Exception;
6 use Jet_Form_Builder\Exceptions\Silence_Exception;
7
8 // If this file is called directly, abort.
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 abstract class Integration_Base {
14 protected $api_base_url = '';
15 protected $api_key = '';
16 protected $api_request_args = array();
17
18 public function __construct( $api_key ) {
19 $this->api_key = $api_key;
20 }
21
22 public function success_codes(): array {
23 return array( 204, 200 );
24 }
25
26 abstract public function get_all_data();
27
28 public function request( $end_point, $request_args = array() ) {
29 $response = $this->base_request( $end_point, $request_args );
30
31 if ( ! $response || is_wp_error( $response ) ) {
32 return false;
33 }
34
35 $data = wp_remote_retrieve_body( $response );
36
37 if ( ! $data ) {
38 return array();
39 }
40
41 $data = json_decode( $data, true );
42
43 return $data;
44 }
45
46 /**
47 * @param $end_point
48 * @param array $request_args
49 *
50 * @throws Silence_Exception
51 */
52 public function request_with_code( $end_point, $request_args = array() ) {
53 $response = $this->base_request( $end_point, $request_args );
54 $code = (int) wp_remote_retrieve_response_code( $response );
55
56 if ( ! in_array( $code, $this->success_codes(), true ) ) {
57 $message = wp_remote_retrieve_response_message( $response );
58
59 throw new Silence_Exception( esc_html( $message ) );
60 }
61 }
62
63 public function base_request( $end_point, $request_args = array() ) {
64 $args = array_merge_recursive( $this->api_request_args, $request_args );
65 $url = esc_url_raw( $this->api_base_url . $end_point );
66
67 return wp_remote_request( $url, $args );
68 }
69
70 }
71