get() public method

Make an HTTP GET request - for retrieving data
public get ( string $method, array $args = [], integer $timeout = 10 ) : array | false
$method string URL of the API request method
$args array Assoc array of arguments (usually your data)
$timeout integer Timeout limit for request in seconds
return array | false Assoc array of API response, decoded from JSON
Exemplo n.º 1
1
<?php

require "../vendor/autoload.php";
use DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('255970dd153fe7b1d83bec1478cbaa74-us11');
$result = $MailChimp->get('lists');
// Mailing List
// $list_id = '5c6bd183d4';
// Simpleblend Blog
$list_id = '53f4059701';
$result = $MailChimp->post("lists/{$list_id}/members", ['email_address' => '*****@*****.**', 'status' => 'subscribed']);
if ($MailChimp->success()) {
    print_r($result);
} else {
    echo $MailChimp->getLastError();
}
// require_once 'inc/MCAPI.class.php';
// $api = new MCAPI('[[YOUR_API_KEY]]');
// $merge_vars = array('FNAME'=>$_POST["fname"], 'LNAME'=>$_POST["lname"]);
//
// // Submit subscriber data to MailChimp
// // For parameters doc, refer to: http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php
// $retval = $api->listSubscribe( '[[YOUR_LIST_ID]]', $_POST["email"], $merge_vars, 'html', false, true );
//
// if ($api->errorCode){
//   echo "<h4>Please try again.</h4>";
//
// } else {
//   echo "<h4>Thank you, you have been added to our mailing list.</h4>";
//
// }
 public function import_content(\DrewM\MailChimp\MailChimp $MailChimpAPI)
 {
     // import content
     $campaignID = $this->campaignMailChimpID();
     $content = $MailChimpAPI->get("campaigns/{$campaignID}/content");
     if ($MailChimpAPI->success()) {
         $this->update(['campaignText' => $content['plain_text'], 'campaignHTML' => $content['html']]);
     }
 }
Exemplo n.º 3
0
 public function testGetLists()
 {
     $MC_API_KEY = getenv('MC_API_KEY');
     if (!$MC_API_KEY) {
         $this->markTestSkipped('No API key in ENV');
     }
     $MailChimp = new MailChimp($MC_API_KEY);
     $lists = $MailChimp->get('lists');
     $this->assertArrayHasKey('lists', $lists);
 }
 /**
  * Fetches a list of email templates from MailChimp.
  *
  * @param MailChimp $mailChimp
  * @return ArrayList
  */
 public function getMailChimpTemplates($mailChimp)
 {
     $templates = ArrayList::create();
     $response = $mailChimp->get('templates');
     if (!$mailChimp->success()) {
         $message = $response && array_key_exists($response['errors']) ? $response['errors'][0]['message'] : 'Error connecting to MailChimp API';
         user_error($message, E_USER_ERROR);
     }
     foreach ($response['templates'] as $template) {
         if ($template['type'] == 'user') {
             $templates->push(ArrayData::create($template));
         }
     }
     $this->extend('updateMailChimpTemplates', $templates);
     return $templates;
 }
Exemplo n.º 5
0
<?php

include 'libraries/Mailchimp.php';
use DrewM\MailChimp\MailChimp;
$mailChimp = new MailChimp('27f9b677ffb5e53f3d000bfd19ca305f-us12');
$listData = $mailChimp->get('lists');
if ($listData) {
    $listId = $listData['lists'][0]['id'];
    $subscriberEmail = filter_input(INPUT_POST, 'email');
    $subscriber = $mailChimp->post("lists/{$listId}/members", ['email_address' => $subscriberEmail, 'status' => 'subscribed']);
}
 public function testGetLists()
 {
     $MailChimp = new MailChimp(getenv('MC_API_KEY'));
     $lists = $MailChimp->get('lists');
     $this->assertArrayHasKey('lists', $lists);
 }
Exemplo n.º 7
0
 /**
  * @param string $email
  * @param string $listName
  *
  * @return array|bool
  *
  * @throws \Spatie\Newsletter\Exceptions\InvalidNewsletterList
  */
 public function getMember($email, $listName = '')
 {
     $list = $this->lists->findByName($listName);
     return $this->mailChimp->get("lists/{$list->getId()}/members/{$this->getSubscriberHash($email)}");
 }