Esempio n. 1
0
 private function add_verify(array $request, &$options, $value, &$params)
 {
     if ($value === true) {
         // PHP 5.6 or greater will find the system cert by default. When
         // < 5.6, use the Guzzle bundled cacert.
         if (PHP_VERSION_ID < 50600) {
             $options['ssl']['cafile'] = ClientUtils::getDefaultCaBundle();
         }
     } elseif (is_string($value)) {
         $options['ssl']['cafile'] = $value;
         if (!file_exists($value)) {
             throw new RingException("SSL CA bundle not found: {$value}");
         }
     } elseif ($value === false) {
         $options['ssl']['verify_peer'] = false;
         return;
     } else {
         throw new RingException('Invalid verify request option');
     }
     $options['ssl']['verify_peer'] = true;
     $options['ssl']['allow_self_signed'] = true;
 }
Esempio n. 2
0
 public function testUsesSystemDefaultBundle()
 {
     $path = $path = ClientUtils::getDefaultCaBundle();
     $res = $this->getSendResult(['verify' => true]);
     $this->assertArrayNotHasKey('error', $res);
     $opts = stream_context_get_options($res['body']);
     if (PHP_VERSION_ID < 50600) {
         $this->assertEquals($path, $opts['ssl']['cafile']);
     }
 }
Esempio n. 3
0
 public function __construct($apiKey = NULL, $opts = array())
 {
     if (!$apiKey) {
         $apiKey = getenv('MAILCHIMP_APIKEY');
     }
     if (!$apiKey) {
         $apiKey = $this->readConfigs();
     }
     if (!$apiKey) {
         throw new Error('You must provide a MailChimp API key');
     }
     $this->apiKey = $apiKey;
     $dc = "us1";
     if (strstr($this->apiKey, "-")) {
         list($key, $dc) = explode("-", $this->apiKey, 2);
         if (!$dc) {
             $dc = "us1";
         }
     }
     $this->root = str_replace('https://api', 'https://' . $dc . '.api', $this->root);
     $this->root = rtrim($this->root, '/') . '/';
     if (isset($opts['debug'])) {
         $this->debug = TRUE;
     }
     $handler = new StreamHandler();
     $this->client = new Client(array('handler' => $handler));
     $this->client->setDefaultOption('connect_timeout', 6);
     $this->client->setDefaultOption('timeout', 6);
     $this->client->setDefaultOption('exceptions', false);
     try {
         $ca = ClientUtils::getDefaultCaBundle();
         if (strlen($ca) === 0) {
             $this->client->setDefaultOption('verify', false);
             trigger_error(ClientUtils::CA_ERR, E_USER_WARNING);
         }
     } catch (\RuntimeException $ex) {
         $this->client->setDefaultOption('verify', false);
         trigger_error(ClientUtils::CA_ERR, E_USER_WARNING);
     }
     $this->folders = new Folders($this);
     $this->templates = new Templates($this);
     $this->users = new Users($this);
     $this->helper = new Helper($this);
     $this->mobile = new Mobile($this);
     $this->ecomm = new Ecomm($this);
     $this->neapolitan = new Neapolitan($this);
     $this->lists = new Lists($this);
     $this->campaigns = new Campaigns($this);
     $this->vip = new Vip($this);
     $this->reports = new Reports($this);
     $this->gallery = new Gallery($this);
 }
Esempio n. 4
0
 /**
  * Check if we can/should use SSL/TLS/HTTP2 or HTTP.
  *
  * @return boolean
  */
 public function useSsl()
 {
     if ($this->useSsl !== null) {
         return $this->useSsl;
     }
     if (!extension_loaded('openssl')) {
         return $this->useSsl = false;
     }
     try {
         ClientUtils::getDefaultCaBundle();
         return $this->useSsl = true;
     } catch (\RuntimeException $e) {
         $this->messages[] = $e->getMessage();
         return $this->useSsl = false;
     }
 }
Esempio n. 5
0
 /**
  * Check if we can/should use SSL/TLS/HTTP2 or HTTP.
  *
  * @return boolean
  */
 public function useSsl()
 {
     if ($this->useSsl !== null) {
         return $this->useSsl;
     }
     if (!extension_loaded('openssl')) {
         return $this->useSsl = false;
     }
     try {
         if ($this->app['guzzle.api_version'] === 5) {
             ClientUtils::getDefaultCaBundle();
         } else {
             \GuzzleHttp\default_ca_bundle();
         }
         return $this->useSsl = true;
     } catch (\RuntimeException $e) {
         $this->messages[] = $e->getMessage();
         return $this->useSsl = false;
     }
 }