Skip to content

Commit

Permalink
Merge pull request #59 from ebizmarts/Issue-58
Browse files Browse the repository at this point in the history
closes #58
  • Loading branch information
gonzaloebiz authored Dec 4, 2024
2 parents 43dfa26 + e8ff5d3 commit 681e7b9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Change Log

## [3.0.42](https://github.com/ebizmarts/mailchimp-lib/tree/3.0.42) (2024-12-04)

[Full Changelog](https://github.com/ebizmarts/mailchimp-lib/compare/3.0.41...3.0.42)

**Implemented enhancements:**

- Add SaveNotification enhancement [\#58](https://github.com/ebizmarts/mailchimp-lib/issues/58)

## [3.0.41](https://github.com/ebizmarts/mailchimp-lib/tree/3.0.41) (2024-12-03)

[Full Changelog](https://github.com/ebizmarts/mailchimp-lib/compare/3.0.40...3.0.41)

**Implemented enhancements:**

- Structure response of getFriendlyMessage [\#54](https://github.com/ebizmarts/mailchimp-lib/issues/56)
- Structure response of getFriendlyMessage [\#56](https://github.com/ebizmarts/mailchimp-lib/issues/56)

## [3.0.40](https://github.com/ebizmarts/mailchimp-lib/tree/3.0.40) (2024-11-20)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ebizmarts/mailchimp-lib",
"type": "library",
"version": "3.0.41",
"version": "3.0.42",
"description": "API client library for the MailChimp",
"keywords": ["email", "api","mailchimp"],
"homepage": "https://github.com/ebizmarts/mailchimp-lib",
Expand Down
27 changes: 24 additions & 3 deletions src/Mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class Mailchimp
protected $_ch = null;
protected $_root = 'https://api.mailchimp.com/3.0';
protected $_debug = false;
protected $helper = null;

public $root;
public $authorizedApps;
public $automation;
Expand Down Expand Up @@ -204,6 +206,10 @@ public function getAdminUrl()

return $url;
}
public function setHelper($helper)
{
$this->helper = $helper;
}

public function setUserAgent($userAgent)
{
Expand Down Expand Up @@ -251,7 +257,7 @@ public function call($url,$params,$method=Mailchimp::GET)

$info = curl_getinfo($ch);
if(curl_error($ch)) {
throw new Mailchimp_HttpError($this->_root . $url, $method, $params, '', curl_error($ch));
throw new Mailchimp_HttpError($this->_root . $url, $method, $params, '', curl_error($ch),null,null, $this->helper);
}
$result = json_decode($response_body, true);

Expand All @@ -261,10 +267,25 @@ public function call($url,$params,$method=Mailchimp::GET)
$errors = array_key_exists('errors', $result) ? $result['errors'] : null;
$title = array_key_exists('title', $result) ? $result['title'] : '';
$instance = array_key_exists('title', $result) ? $result['instance'] : null;
throw new Mailchimp_Error($this->_root . $url, $method, $params, $title, $detail, $errors, $instance);
throw new Mailchimp_Error($this->_root . $url, $method, $params, $title, $detail, $errors, $instance, $this->helper);
} else {
throw new Mailchimp_Error($this->_root . $url, $method, $params, $result, null, null, null, $this->helper);
}
}
if ($this->helper) {
$curlinfo = [];
if (array_key_exists('total_time', $info)) {
$total_time = $info['total_time'];
} else {
throw new Mailchimp_Error($this->_root . $url, $method, $params, $result);
$total_time = 0;
}
$curlinfo['info']['total_time'] = $total_time;
$curlinfo['info']['time'] = $this->helper->getGmtDate();
$curlinfo['info']['url'] = $this->_root . $url;
$curlinfo['info']['method'] = $method;
$curlinfo['info']['params'] = $params;
$curlinfo['info']['response'] = $result;
$this->helper->saveNotification($curlinfo);
}

return $result;
Expand Down
8 changes: 7 additions & 1 deletion src/Mailchimp/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ class Mailchimp_Error extends Exception
* @var string
*/
protected $instance;
protected $helper;

/**
* @var string
*/
protected $params;

public function __construct($url,$method='',$params='',$title='',$detail='',$errors=null, $instance = null)
public function __construct($url,$method='',$params='',$title='',$detail='',$errors=null, $instance = null, $helper=null)
{
$titleComplete = $title . " for Api Call: " . $url;
parent::__construct($titleComplete . " - " . $detail);
Expand All @@ -52,6 +54,7 @@ public function __construct($url,$method='',$params='',$title='',$detail='',$err
$this->errors = $errors;
$this->params = $params;
$this->instance = $instance;
$this->helper = $helper;
}
public function getFriendlyMessage()
{
Expand All @@ -77,6 +80,9 @@ public function getFriendlyMessage()
}
$errors = [];
$errors['error'] = $error;
if ($this->helper) {
$this->helper->saveNotification($errors);
}
return $errors;
}
public function getUrl()
Expand Down

0 comments on commit 681e7b9

Please sign in to comment.