Skip to content

Commit

Permalink
Add namespace for Composer installation, and add verify_ssl flag to t…
Browse files Browse the repository at this point in the history
…urn off SSL CA verification if needed.
  • Loading branch information
anaxamaxan committed Oct 1, 2012
1 parent 61cff90 commit b11b1f6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/HipChat/HipChat.php
@@ -1,5 +1,7 @@
<?php <?php


namespace HipChat;

/** /**
* Library for interacting with the HipChat REST API. * Library for interacting with the HipChat REST API.
* *
Expand Down Expand Up @@ -37,6 +39,7 @@ class HipChat {


private $api_target; private $api_target;
private $auth_token; private $auth_token;
private $verify_ssl = true;


/** /**
* Creates a new API interaction object. * Creates a new API interaction object.
Expand Down Expand Up @@ -158,6 +161,7 @@ public function curl_request($url, $post_data = null) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
if (is_array($post_data)) { if (is_array($post_data)) {
curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
Expand Down Expand Up @@ -216,11 +220,26 @@ public function make_request($api_method, $args = array(),


return $response; 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) { public function __construct($code, $info, $url) {
$message = "HipChat API error: code=$code, info=$info, url=$url"; $message = "HipChat API error: code=$code, info=$info, url=$url";
parent::__construct($message, (int)$code); parent::__construct($message, (int)$code);
Expand Down

0 comments on commit b11b1f6

Please sign in to comment.