/**
  * @test
  */
 public function can_throw_request_error()
 {
     $descriptor = new Descriptor("http://localhost:1", "delete", array("header1" => "value1", "header2" => "value2"), "this is a body");
     $portatext = new Client();
     try {
         $portatext->execute($descriptor);
     } catch (\PortaText\Exception\RequestError $e) {
         $eDescriptor = $e->getDescriptor();
         $this->assertTrue(strlen($e->getMessage()) > 10);
         $this->assertEquals($eDescriptor->uri, $descriptor->uri);
         $this->assertEquals($eDescriptor->method, $descriptor->method);
         $this->assertEquals($eDescriptor->headers, $descriptor->headers);
         $this->assertEquals($eDescriptor->body, $descriptor->body);
         $this->assertNull($e->getResult());
     }
 }
        $alertSources[] = "{$source} {$metric} value: {$value}";
    }
}
$alertSources = implode(" and ", $alertSources);
foreach ($body['conditions'] as $data) {
    $threshold = $data['threshold'];
    $cond = $data['type'];
    $alertConditions[] = "{$cond} {$threshold}";
}
$alertConditions = implode(" and ", $alertConditions);
foreach ($body['violations'] as $source => $data) {
    foreach ($data as $values) {
        $metric = $values['metric'];
        $value = $values['value'];
        $alertSources[] = "{$source} {$metric} value: {$value}";
    }
}
$alertSources = implode(" and ", $alertSources);
/* Create the SMS content */
$text = "Librato alert: {$alertName} ({$alertDescription}) {$alertConditions} for {$alertSources}";
/* Send the message! :) */
$portatext = new Client();
try {
    $portatext->setApiKey($apiKey)->sms()->toContactLists($contactLists)->text($text)->from($from)->post();
    header("HTTP/1.1 200 OK");
    echo '{"result": "ok"}';
} catch (\Exception $e) {
    file_put_contents('/tmp/errors', print_r($e->getMessage(), true) . "\n" . print_r($e->getResult(), true));
    header("HTTP/1.1 500 OK");
    echo '{"result": "error"}';
}