diff --git a/README.md b/README.md index db29aa9..49e6a76 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ You can find function references in the [client folder](https://github.com/omnis Before using Omnisend Client you need to ensure the following conditions: * Omnisend Plugin is installed `is_plugin_active( 'omnisend/class-omnisend-core-bootstrap.php' )` -* Omnisend Plugin is up to date `class_exists( 'Omnisend\Public\V1\Omnisend' )` -* Omnisend is connected to the WordPress `Omnisend\Public\V1\Omnisend::is_connected()` +* Omnisend Plugin is up to date `class_exists( 'Omnisend\SDK\V1\Omnisend' )` +* Omnisend is connected to account `Omnisend\SDK\V1\Omnisend::is_connected()` If any of these conditions are false you should ask to resolve them. @@ -36,7 +36,7 @@ To send contact to the Omnisend you need to provide your integration name & vers This is done by getting an actual client -` $client = \Omnisend\Public\V1\Omnisend::get_client( 'integration name', 'integration version' );` +` $client = \Omnisend\SDK\V1\Omnisend::get_client( 'integration name', 'integration version' );` 'integration name' - should be your integration name 'integration version' - should be your integration version @@ -64,7 +64,7 @@ Here is how you can create a basic client & submit contact. $contact->set_email_opt_in( 'where user opted to become subscriber' ); } - $client = \Omnisend\Public\V1\Omnisend::get_client( 'integration name', 'integration version' ); + $client = \Omnisend\SDK\V1\Omnisend::get_client( 'integration name', 'integration version' ); $response = $client->create_contact( $contact ); ``` @@ -74,15 +74,15 @@ Here is how you can create a basic client & submit contact. If data provided is invalid or creation fails, then ```php -$client->create_contact($contact) +$response = $client->create_contact($contact) ``` -Will return `errors` in `WP_Error`. Depending on your integration logic you should handle the error i.e +Will return `CreateContactResponse`. Depending on your integration logic you should handle the error i.e ```php - if ( is_wp_error( $response ) ) { - error_log( 'Error in after_submission: ' . $response->get_error_message()); - return; + if ( $response->get_wp_error()->has_errors() ) { + error_log( 'Error in after_submission: ' . $response->get_wp_error()->get_error_message()); + return; } ``` diff --git a/omnisend/class-omnisend-core-bootstrap.php b/omnisend/class-omnisend-core-bootstrap.php index 44d50ea..eb97a4e 100644 --- a/omnisend/class-omnisend-core-bootstrap.php +++ b/omnisend/class-omnisend-core-bootstrap.php @@ -4,7 +4,7 @@ * * Plugin Name: Omnisend * Description: Omnisend main plugin that enables integration with Omnisend. - * Version: 1.1.4 + * Version: 1.2.0 * Author: Omnisend * Author URI: https://www.omnisend.com * Developer: Omnisend @@ -22,7 +22,7 @@ defined( 'ABSPATH' ) || die( 'no direct access' ); -const OMNISEND_CORE_PLUGIN_VERSION = '1.1.4'; +const OMNISEND_CORE_PLUGIN_VERSION = '1.2.0'; const OMNISEND_CORE_SETTINGS_PAGE = 'omnisend'; const OMNISEND_CORE_PLUGIN_NAME = 'Email Marketing by Omnisend'; @@ -71,13 +71,13 @@ public static function load_omnisend_admin_styles(): void { 'roboto.css', plugin_dir_url( __FILE__ ) . 'assets/fonts/roboto/roboto.css?' . time(), array(), - '1.1.4', + OMNISEND_CORE_PLUGIN_VERSION, ); wp_enqueue_style( 'styles.css', plugin_dir_url( __FILE__ ) . 'styles/styles.css?' . time(), array(), - '1.1.4', + OMNISEND_CORE_PLUGIN_VERSION, ); } } diff --git a/omnisend/includes/Internal/V1/class-client.php b/omnisend/includes/Internal/V1/class-client.php index 4f70bbf..a3b9833 100644 --- a/omnisend/includes/Internal/V1/class-client.php +++ b/omnisend/includes/Internal/V1/class-client.php @@ -7,12 +7,13 @@ namespace Omnisend\Internal\V1; -use Omnisend\Public\V1\Contact; +use Omnisend\SDK\V1\Contact; +use Omnisend\SDK\V1\CreateContactResponse; use WP_Error; defined( 'ABSPATH' ) || die( 'no direct access' ); -class Client implements \Omnisend\Public\V1\Client { +class Client implements \Omnisend\SDK\V1\Client { private string $api_key; private string $plugin_name; @@ -30,19 +31,19 @@ public function __construct( string $api_key, string $plugin_name, string $plugi } - public function create_contact( $contact ): mixed { + public function create_contact( $contact ): CreateContactResponse { $error = new WP_Error(); if ( $contact instanceof Contact ) { $error->merge_from( $contact->validate() ); } else { - $error->add( 'contact', 'Contact is not instance of Omnisend\Public\V1\Contact.' ); + $error->add( 'contact', 'Contact is not instance of Omnisend\SDK\V1\Contact.' ); } $error->merge_from( $this->check_setup() ); if ( $error->has_errors() ) { - return $error; + return new CreateContactResponse( '', $error ); } $response = wp_remote_post( @@ -61,7 +62,7 @@ public function create_contact( $contact ): mixed { if ( is_wp_error( $response ) ) { error_log('wp_remote_post error: ' . $response->get_error_message()); // phpcs:ignore - return $response; + return new CreateContactResponse( '', $response ); } $http_code = wp_remote_retrieve_response_code( $response ); @@ -69,23 +70,23 @@ public function create_contact( $contact ): mixed { $body = wp_remote_retrieve_body( $response ); $err_msg = "HTTP error: {$http_code} - " . wp_remote_retrieve_response_message( $response ) . " - {$body}"; $error->add( 'omnisend_api', $err_msg ); - return $error; + return new CreateContactResponse( '', $error ); } $body = wp_remote_retrieve_body( $response ); if ( ! $body ) { $error->add( 'omnisend_api', 'empty response' ); - return $error; + return new CreateContactResponse( '', $error ); } $arr = json_decode( $body, true ); if ( empty( $arr['contactID'] ) ) { $error->add( 'omnisend_api', 'contactID not found in response.' ); - return $error; + return new CreateContactResponse( '', $error ); } - return (string) $arr['contactID']; + return new CreateContactResponse( (string) $arr['contactID'], $error ); } /** diff --git a/omnisend/includes/Internal/class-connection.php b/omnisend/includes/Internal/class-connection.php index 35641eb..0e43b4c 100644 --- a/omnisend/includes/Internal/class-connection.php +++ b/omnisend/includes/Internal/class-connection.php @@ -30,7 +30,7 @@ public static function display(): void { return; } - if ( $response['verified'] === true && $response['platform'] !== wordpress_platform ) { + if ( $response['verified'] === true && $response['platform'] !== $wordpress_platform ) { echo '

This Omnisend account is already connected to non-WordPress site. Log in to access it. Contact our support if you have other issues.

'; require_once __DIR__ . '/../../view/connection-form.html'; @@ -38,7 +38,7 @@ public static function display(): void { } $connected = false; - if ( $response['platform'] === wordpress_platform ) { + if ( $response['platform'] === $wordpress_platform ) { $connected = true; } diff --git a/omnisend/includes/Public/V1/class-client.php b/omnisend/includes/SDK/V1/class-client.php similarity index 69% rename from omnisend/includes/Public/V1/class-client.php rename to omnisend/includes/SDK/V1/class-client.php index 411d841..9a0cd88 100644 --- a/omnisend/includes/Public/V1/class-client.php +++ b/omnisend/includes/SDK/V1/class-client.php @@ -5,7 +5,7 @@ * @package OmnisendClient */ -namespace Omnisend\Public\V1; +namespace Omnisend\SDK\V1; use WP_Error; @@ -22,7 +22,7 @@ interface Client { * * @param Contact $contact * - * @return string|WP_Error Created/updated contact identifier (ID) or WP_Error + * @return CreateContactResponse */ - public function create_contact( $contact ): mixed; + public function create_contact( $contact ): CreateContactResponse; } diff --git a/omnisend/includes/Public/V1/class-contact.php b/omnisend/includes/SDK/V1/class-contact.php similarity index 99% rename from omnisend/includes/Public/V1/class-contact.php rename to omnisend/includes/SDK/V1/class-contact.php index bb69b7e..1e6d4aa 100644 --- a/omnisend/includes/Public/V1/class-contact.php +++ b/omnisend/includes/SDK/V1/class-contact.php @@ -5,7 +5,7 @@ * @package OmnisendClient */ -namespace Omnisend\Public\V1; +namespace Omnisend\SDK\V1; use Omnisend\Internal\Utils; use WP_Error; diff --git a/omnisend/includes/SDK/V1/class-createcontactresponse.php b/omnisend/includes/SDK/V1/class-createcontactresponse.php new file mode 100644 index 0000000..e61a332 --- /dev/null +++ b/omnisend/includes/SDK/V1/class-createcontactresponse.php @@ -0,0 +1,36 @@ +contact_id = $contact_id; + $this->wp_error = $wp_error; + } + + public function get_contact_id(): string { + return $this->contact_id; + } + + public function get_wp_error(): WP_Error { + return $this->wp_error; + } +} diff --git a/omnisend/includes/Public/V1/class-omnisend.php b/omnisend/includes/SDK/V1/class-omnisend.php similarity index 96% rename from omnisend/includes/Public/V1/class-omnisend.php rename to omnisend/includes/SDK/V1/class-omnisend.php index 148e070..8f04b78 100644 --- a/omnisend/includes/Public/V1/class-omnisend.php +++ b/omnisend/includes/SDK/V1/class-omnisend.php @@ -5,7 +5,7 @@ * @package OmnisendClient */ -namespace Omnisend\Public\V1; +namespace Omnisend\SDK\V1; use Omnisend\Internal\Options; diff --git a/omnisend/readme.txt b/omnisend/readme.txt index 3f826cb..41e59b4 100644 --- a/omnisend/readme.txt +++ b/omnisend/readme.txt @@ -5,7 +5,7 @@ Tags: email marketing, marketing, newsletter, sms, form Requires at least: 4.7.0 Tested up to: 6.4 Requires PHP: 7.1 -Stable tag: 1.1.4 +Stable tag: 1.2.0 License: GPLv3 or later URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -54,6 +54,10 @@ Read Omnisend [Terms of Use](https://www.omnisend.com/terms) == Changelog == += 1.2.0 = + +* Improve SDK client + = 1.1.4 = * Improve connection messages