PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 1.1.1
JetFormBuilder — Dynamic Blocks Form Builder v1.1.1
3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 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 All 130 releases
jetformbuilder / includes / integrations / getresponse-handler.php
getresponse-handler.php
99 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Jet_Form_Builder\Integrations;
4
5 /**
6 * GetResponse Handler
7 */
8
9 // If this file is called directly, abort.
10 if ( ! defined( 'WPINC' ) ) {
11 die;
12 }
13
14 /**
15 * Define Getresponse_Handler class
16 */
17 class Getresponse_Handler extends Integration_Base {
18
19 protected $api_base_url = 'https://api.getresponse.com/v3/';
20
21 /**
22 * Constructor for the class
23 *
24 * @param $api_key
25 */
26 public function __construct( $api_key ) {
27
28 if ( empty( $api_key ) ) {
29 return new \WP_Error( 'invalid_api_key' );
30 }
31
32 $this->api_key = $api_key;
33 $this->api_request_args = array(
34 'headers' => array(
35 'X-Auth-Token' => 'api-key ' . $api_key,
36 'Content-Type' => 'application/json',
37 ),
38 );
39
40 }
41
42
43 public function get_all_data() {
44 return array(
45 'lists' => $this->get_lists(),
46 'fields' => $this->get_fields(),
47 );
48 }
49
50 public function get_lists() {
51 $result = array();
52 $lists = $this->request( 'campaigns' );
53
54 if ( ! empty( $lists ) ) {
55 foreach ( $lists as $list ) {
56 if ( ! is_array( $list ) ) {
57 continue;
58 }
59 if ( ! isset( $list['campaignId'] ) ) {
60 return array();
61 }
62
63 $result[ $list['campaignId'] ] = $list['name'];
64 }
65 }
66
67 return $result;
68 }
69
70 public function get_fields() {
71 $result = array(
72 'email' => array(
73 'label' => esc_html__( 'Email', 'jet-form-builder' ),
74 'required' => true,
75 ),
76 'name' => array(
77 'label' => esc_html__( 'Name', 'jet-form-builder' ),
78 'required' => false,
79 ),
80 );
81
82 $custom_fields = $this->request( 'custom-fields' );
83
84 if ( ! empty( $custom_fields ) ) {
85 foreach ( $custom_fields as $field ) {
86 if ( ! isset( $field['customFieldId'] ) ) {
87 return array();
88 }
89 $result[ $field['customFieldId'] ] = array(
90 'label' => $field['name'],
91 'required' => false,
92 );
93 }
94 }
95
96 return $result;
97 }
98 }
99