action-factory.php
1 year ago
base-api-action.php
1 year ago
create-contact-action.php
1 year ago
get-custom-fields-action.php
1 year ago
get-lists-action.php
1 year ago
create-contact-action.php
112 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JFB_Modules\Actions_V2\Get_Response\Api; |
| 4 | |
| 5 | class Create_Contact_Action extends Base_Api_Action { |
| 6 | |
| 7 | protected $method = 'POST'; |
| 8 | |
| 9 | private $list_id = ''; |
| 10 | private $email = ''; |
| 11 | private $name = ''; |
| 12 | private $day_of_cycle = ''; |
| 13 | private $custom_fields = array(); |
| 14 | |
| 15 | public function action_endpoint() { |
| 16 | return 'contacts'; |
| 17 | } |
| 18 | |
| 19 | public function action_body() { |
| 20 | return array( |
| 21 | 'campaign' => array( |
| 22 | 'campaignId' => $this->get_list_id(), |
| 23 | ), |
| 24 | 'email' => $this->get_email(), |
| 25 | 'name' => $this->get_name(), |
| 26 | 'customFieldValues' => $this->get_custom_fields(), |
| 27 | 'dayOfCycle' => (int) $this->get_day_of_cycle(), |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | |
| 33 | public function add_custom_field( string $name, $value ) { |
| 34 | $this->custom_fields[] = array( |
| 35 | 'customFieldId' => $name, |
| 36 | 'value' => array( $value ), |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param string $list_id |
| 42 | */ |
| 43 | public function set_list_id( string $list_id ) { |
| 44 | $this->list_id = $list_id; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @return string |
| 49 | */ |
| 50 | public function get_list_id(): string { |
| 51 | return $this->list_id; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @param array $custom_fields |
| 56 | */ |
| 57 | public function set_custom_fields( array $custom_fields ) { |
| 58 | $this->custom_fields = $custom_fields; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @return array |
| 63 | */ |
| 64 | public function get_custom_fields(): array { |
| 65 | return $this->custom_fields; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return string |
| 70 | */ |
| 71 | public function get_email(): string { |
| 72 | return $this->email; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @param string $email |
| 77 | */ |
| 78 | public function set_email( string $email ) { |
| 79 | $this->email = $email; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @return string |
| 84 | */ |
| 85 | public function get_name(): string { |
| 86 | return $this->name; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @param string $name |
| 91 | */ |
| 92 | public function set_name( string $name ) { |
| 93 | $this->name = $name; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @param string $day_of_cycle |
| 98 | */ |
| 99 | public function set_day_of_cycle( string $day_of_cycle ) { |
| 100 | $this->day_of_cycle = $day_of_cycle; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @return string |
| 105 | */ |
| 106 | public function get_day_of_cycle(): string { |
| 107 | return $this->day_of_cycle; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | } |
| 112 |