You are here

function mailchimp_get_memberinfo in Mailchimp 7.5

Same name and namespace in other branches
  1. 8 mailchimp.module \mailchimp_get_memberinfo()
  2. 7.2 mailchimp.module \mailchimp_get_memberinfo()
  3. 7.3 mailchimp.module \mailchimp_get_memberinfo()
  4. 7.4 mailchimp.module \mailchimp_get_memberinfo()
  5. 2.x mailchimp.module \mailchimp_get_memberinfo()

Get the MailChimp member info for a given email address and list.

Results are cached in the cache_mailchimp bin which is cleared by the MailChimp web hooks system when needed.

Parameters

string $list_id: The MailChimp list ID to get member info for.

string $email: The MailChimp user email address to load member info for.

bool $reset: Set to TRUE if member info should not be loaded from cache.

Return value

object Member info object, empty if there is no valid info.

8 calls to mailchimp_get_memberinfo()
MailchimpListsTestCase::testGetMemberInfo in modules/mailchimp_lists/tests/mailchimp_lists.test
Tests retrieval of member info for a list and email address.
mailchimp_get_marketing_permissions in ./mailchimp.module
Get the marketing permissions for a subscribed member
mailchimp_interest_groups_form_elements in ./mailchimp.module
Helper function to generate form elements for a list's interest groups.
mailchimp_is_subscribed in ./mailchimp.module
Check if the given email is subscribed to the given list.
mailchimp_lists_field_formatter_view in modules/mailchimp_lists/includes/mailchimp_lists.field.inc
Implements hook_field_formatter_view().

... See full list

File

./mailchimp.module, line 597
Mailchimp module.

Code

function mailchimp_get_memberinfo($list_id, $email, $reset = FALSE) {
  $cache = $reset ? NULL : cache_get($list_id . '-' . $email, 'cache_mailchimp');

  // Return cached lists:
  if ($cache) {
    return $cache->data;
  }

  // Query lists from the MCAPI and store in cache:
  $memberinfo = new stdClass();

  /* @var \Mailchimp\MailchimpLists $mc_lists */
  $mc_lists = mailchimp_get_api_object('MailchimpLists');
  try {
    if (!$mc_lists) {
      throw new MailchimpException('Cannot get member info without MailChimp API. Check API key has been entered.');
    }
    try {
      $memberinfo = $mc_lists
        ->getMemberInfo($list_id, $email);
      cache_set($list_id . '-' . $email, $memberinfo, 'cache_mailchimp', CACHE_TEMPORARY);
    } catch (Exception $e) {

      // Throw exception only for errors other than member not found.
      if ($e
        ->getCode() != 404) {
        throw new Exception($e
          ->getMessage(), $e
          ->getCode(), $e);
      }
    }
  } catch (Exception $e) {
    watchdog('mailchimp', 'An error occurred requesting memberinfo for @email in list @list. "%message"', array(
      '@email' => $email,
      '@list' => $list_id,
      '%message' => $e
        ->getMessage(),
    ), WATCHDOG_ERROR);
  }
  return $memberinfo;
}