/**
  * @dataProvider getFailedApiResponses
  */
 public function testFailedApiResponses($code)
 {
     $this->setExpectedException('CloudFlarePhpSdk\\Exceptions\\CloudFlareApiException');
     $mock = new MockHandler([new Response(200, [], $code)]);
     $api = new ZoneApi("68ow48650j63zfzx1w9jd29cr367u0ezb6a4g", "email", $mock);
     $zones = $api->listZones();
 }
 /**
  * @dataProvider httpMockErrorResponses
  */
 function testInvalidHttpResponses($code, $response_header)
 {
     $this->setExpectedException('CloudFlarePhpSdk\\Exceptions\\CloudFlareHttpException');
     $mock = new MockHandler([new Response($code, $response_header)]);
     $api = new ZoneApi("68ow48650j63zfzx1w9jd29cr367u0ezb6a4g", "email", $mock);
     $api->listZones();
 }
 /**
  * Form callback to purge paths.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  */
 public function purgePaths(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config('cloudflare.settings');
     $api_key = $config->get('apikey');
     $email = $config->get('email');
     $zone = $config->get('zone');
     try {
         $zone_api = new ZoneApi($api_key, $email);
         // @todo rethink how to handle cloudflare zones in Drupal.
         if (is_null($zone)) {
             $zones = $zone_api->listZones();
             $zone = $zones[0]->getZoneId();
         }
         $zone_api->purgeAllFiles($zone);
     } catch (CloudFlareHttpException $e) {
         drupal_set_message("Unable to clear paths. " . $e->getMessage(), 'error');
         \Drupal::logger('cloudflare')->error($e->getMessage());
         return;
     } catch (CloudFlareApiException $e) {
         drupal_set_message("Unable to clear paths. " . $e->getMessage(), 'error');
         \Drupal::logger('cloudflare')->error($e->getMessage());
         return;
     }
     // If no exceptions have been thrown then the request has been successful.
     drupal_set_message("The zone: {$zone} was successfully cleared.");
 }