url = $url; } /** * Test the URL * Makes an POST request to the URL and check the response * * @return bool */ public function testUrl() { $url = $this->url; $response = tve_dash_api_remote_post( $url ); if ( is_wp_error( $response ) ) { return false; } if ( $response['response']['code'] != 200 ) { return false; } return true; } /** * @param $email string * @param $list_id string * @param string $name string * * @throws Thrive_Dash_Api_Sendy_Exception * * @return bool */ public function subscribe( $email, $list_id, $name = '', $phone = null ) { if ( empty( $email ) ) { throw new Thrive_Dash_Api_Sendy_Exception( 'Invalid Email' ); } if ( empty( $list_id ) ) { throw new Thrive_Dash_Api_Sendy_Exception( 'List not set' ); } $args = array( 'email' => $email, 'list' => $list_id, 'boolean' => 'true', 'phone' => $phone, ); if ( ! empty( $name ) ) { $args['name'] = $name; } $response = tve_dash_api_remote_post( rtrim( $this->url, "/" ) . '/subscribe', array( 'body' => $args, ) ); if ( is_wp_error( $response ) ) { throw new Thrive_Dash_Api_Sendy_Exception( 'Error occurred' ); } if ( $response['body'] == 1 ) { return true; } else { throw new Thrive_Dash_Api_Sendy_Exception( $response['body'] ); } return false; } }