class MandrillReportsService in Mandrill 8
Mandrill Reports service.
Hierarchy
- class \Drupal\mandrill_reports\MandrillReportsService implements MandrillReportsInterface
Expanded class hierarchy of MandrillReportsService
1 string reference to 'MandrillReportsService'
- mandrill_reports.services.yml in modules/
mandrill_reports/ mandrill_reports.services.yml - modules/mandrill_reports/mandrill_reports.services.yml
2 services use MandrillReportsService
- mandrill_reports.service in modules/
mandrill_reports/ mandrill_reports.services.yml - Drupal\mandrill_reports\MandrillReportsService
- mandrill_reports.test.service in modules/
mandrill_reports/ mandrill_reports.services.yml - Drupal\mandrill_reports\MandrillReportsService
File
- modules/
mandrill_reports/ src/ MandrillReportsService.php, line 16 - Contains \Drupal\mandrill_reports\MandrillReportsService.
Namespace
Drupal\mandrill_reportsView source
class MandrillReportsService implements MandrillReportsInterface {
/**
* The Mandrill API service.
*
* @var \Drupal\mandrill\MandrillAPIInterface
*/
protected $mandrill_api;
/**
* The Config Factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config;
/**
* Constructs the service.
*
* @param \Drupal\mandrill\MandrillAPIInterface $mandrill_api
* The Mandrill API service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
*/
public function __construct(MandrillAPIInterface $mandrill_api, ConfigFactoryInterface $config_factory) {
$this->mandrill_api = $mandrill_api;
$this->config = $config_factory;
}
public function getUser() {
return $this->mandrill_api
->getUser();
}
/**
* Gets tag data formatted for reports.
*
* @return array
*/
public function getTags() {
$cache = \Drupal::cache('mandrill');
$cached_tags = $cache
->get('tags');
if (!empty($cached_tags)) {
return $cached_tags->data;
}
$data = array();
$tags = $this->mandrill_api
->getTags();
foreach ($tags as $tag) {
if (!empty($tag['tag'])) {
$data[$tag['tag']] = $this->mandrill_api
->getTag($tag['tag']);
$data[$tag['tag']]['time_series'] = $this->mandrill_api
->getTagTimeSeries($tag['tag']);
}
}
$cache
->set('tags', $data);
return $data;
}
/**
* Gets recent history for all tags.
*
* @return array
*/
public function getTagsAllTimeSeries() {
$cache = \Drupal::cache('mandrill');
$cached_tags_series = $cache
->get('tags_series');
if (!empty($cached_tags_series)) {
return $cached_tags_series->data;
}
$data = $this->mandrill_api
->getTagsAllTimeSeries();
$cache
->set('tags_series', $data);
return $data;
}
/**
* Gets sender data formatted for reports.
*
* @return array
*/
public function getSenders() {
$cache = \Drupal::cache('mandrill');
$cached_senders = $cache
->get('senders');
if (!empty($cached_senders)) {
return $cached_senders->data;
}
$data = array();
$senders = $this->mandrill_api
->getSenders();
foreach ($senders as $sender) {
try {
$data[$sender['address']] = $this->mandrill_api
->getSender($sender['address']);
$data[$sender['address']]['time_series'] = $this->mandrill_api
->getSenderTimeSeries($sender['address']);
} catch (\Exception $e) {
\Drupal::logger('mandrill')
->error('An error occurred requesting sender information from Mandrill for address %address. "%message"', array(
'%address' => $sender['address'],
'%message' => $e
->getMessage(),
));
}
}
$cache
->set('senders', $data);
return $data;
}
/**
* Gets URLs formatted for reports.
*
* @return array
*/
public function getUrls() {
$cache = \Drupal::cache('mandrill');
$cached_urls = $cache
->get('urls');
if (!empty($cached_urls)) {
return $cached_urls->data;
}
$data = array();
$urls = $this->mandrill_api
->getURLs();
foreach ($urls as $url) {
if (isset($url['url'])) {
$data[$url['url']] = $url;
$data[$url['url']]['time_series'] = $this->mandrill_api
->getURLTimeSeries($url['url']);
}
}
$cache
->set('urls', $data);
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MandrillReportsService:: |
protected | property | The Config Factory service. | |
MandrillReportsService:: |
protected | property | The Mandrill API service. | |
MandrillReportsService:: |
public | function | Gets sender data formatted for reports. | |
MandrillReportsService:: |
public | function | Gets tag data formatted for reports. | |
MandrillReportsService:: |
public | function | Gets recent history for all tags. | |
MandrillReportsService:: |
public | function | Gets URLs formatted for reports. | |
MandrillReportsService:: |
public | function | ||
MandrillReportsService:: |
public | function | Constructs the service. |