Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespace for composer, + ssl fix #6

Merged
merged 2 commits into from
Oct 2, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/HipChat/HipChat.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace HipChat;

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

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

/**
* 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_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);
Expand Down Expand Up @@ -216,11 +220,27 @@ 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
* @link http://davidwalsh.name/php-ssl-curl-error
*/
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);
Expand Down