interfaces
1 year ago
traits
1 year ago
action-factory.php
1 year ago
base-api-action.php
1 year ago
create-tags-action.php
1 year ago
get-categories-action.php
1 year ago
get-categories-interests-action.php
1 year ago
get-fields-action.php
1 year ago
get-lists-action.php
1 year ago
put-member-in-list-action.php
1 year ago
get-lists-action.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JFB_Modules\Actions_V2\Mailchimp\Api; |
| 4 | |
| 5 | use Jet_Form_Builder\Exceptions\Gateway_Exception; |
| 6 | |
| 7 | class Get_Lists_Action extends Base_Api_Action { |
| 8 | |
| 9 | protected $method = 'GET'; |
| 10 | |
| 11 | public function action_endpoint() { |
| 12 | return add_query_arg( |
| 13 | array( |
| 14 | 'count' => 999, |
| 15 | ), |
| 16 | 'lists' |
| 17 | ); |
| 18 | } |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * @return \Generator |
| 23 | * @throws Gateway_Exception |
| 24 | */ |
| 25 | public function generate_lists(): \Generator { |
| 26 | $response = $this->get_response_body(); |
| 27 | |
| 28 | if ( ! empty( $response['errors'] ) ) { |
| 29 | // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 30 | throw new Gateway_Exception( $response['detail'] ); |
| 31 | } |
| 32 | |
| 33 | foreach ( $response['lists'] as $list ) { |
| 34 | yield array( |
| 35 | 'value' => $list['id'], |
| 36 | 'label' => $list['name'], |
| 37 | ); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | } |
| 42 |