Permalink
Browse files

Add namespace for Composer installation, and add verify_ssl flag to t…

…urn off SSL CA verification if needed.
  • Loading branch information...
1 parent 61cff90 commit b11b1f6ad35b9ec871ef7563e7b1ed325117a9ca @anaxamaxan anaxamaxan committed Oct 1, 2012
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/HipChat/HipChat.php
View
@@ -1,5 +1,7 @@
<?php
+namespace HipChat;
+
/**
* Library for interacting with the HipChat REST API.
*
@@ -37,6 +39,7 @@ class HipChat {
private $api_target;
private $auth_token;
+ private $verify_ssl = true;
/**
* Creates a new API interaction object.
@@ -158,6 +161,7 @@ public function curl_request($url, $post_data = null) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
if (is_array($post_data)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
@@ -216,11 +220,26 @@ public function make_request($api_method, $args = array(),
return $response;
}
+
+ /**
+ * Enable/disable verify_ssl.
+ * This is useful when curl spits back ssl verification errors, most likely due to
+ * outdated SSL CA bundle file on server. If you are able to, update that CA bundle.
+ * If not, call this method with false for $bool param before interacting with the API.
+ *
+ * @param bool $bool
+ * @return bool
+ */
+ public function set_verify_ssl($bool = true)
+ {
+ $this->verify_ssl = (bool) $bool;
+ return $this->verify_ssl;
+ }
}
-class HipChat_Exception extends Exception {
+class HipChat_Exception extends \Exception {
public function __construct($code, $info, $url) {
$message = "HipChat API error: code=$code, info=$info, url=$url";
parent::__construct($message, (int)$code);

0 comments on commit b11b1f6

Please sign in to comment.