Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add namespace for composer, + ssl fix #6

Merged
merged 2 commits into from almost 2 years ago

2 participants

anaxamaxan Garret Heaton
anaxamaxan

Added namespace bits.
Also added a flag and setter method for whether or not curl should verify the hipchat api's SSL certificate. Our server had an old bundle, so I was getting errors. I came up with this solution before figuring how to update our CA bundle. Should be useful in shared/cloud situations where updating the CA bundle is infeasible.

I did not add a test for the new method, because I'm not sure how to consistently reproduce the error state across environments.

Garret Heaton
Owner

These should probably be two different pulls, but oh well. :)

Garret Heaton powdahound merged commit 086aa61 into from
anaxamaxan

Sorry, got a little turned around when I thought I sent pull to dshimy then it seemed to disappear after you guys changed the packagist link here instead of his. Anyway thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 21 additions and 1 deletion. Show diff stats Hide diff stats

  1. +21 1 src/HipChat/HipChat.php
22 src/HipChat/HipChat.php
... ... @@ -1,5 +1,7 @@
1 1 <?php
2 2
  3 +namespace HipChat;
  4 +
3 5 /**
4 6 * Library for interacting with the HipChat REST API.
5 7 *
@@ -37,6 +39,7 @@ class HipChat {
37 39
38 40 private $api_target;
39 41 private $auth_token;
  42 + private $verify_ssl = true;
40 43
41 44 /**
42 45 * Creates a new API interaction object.
@@ -158,6 +161,7 @@ public function curl_request($url, $post_data = null) {
158 161 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
159 162 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
160 163 curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  164 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
161 165 if (is_array($post_data)) {
162 166 curl_setopt($ch, CURLOPT_POST, 1);
163 167 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
@@ -216,11 +220,27 @@ public function make_request($api_method, $args = array(),
216 220
217 221 return $response;
218 222 }
  223 +
  224 + /**
  225 + * Enable/disable verify_ssl.
  226 + * This is useful when curl spits back ssl verification errors, most likely due to
  227 + * outdated SSL CA bundle file on server. If you are able to, update that CA bundle.
  228 + * If not, call this method with false for $bool param before interacting with the API.
  229 + *
  230 + * @param bool $bool
  231 + * @return bool
  232 + * @link http://davidwalsh.name/php-ssl-curl-error
  233 + */
  234 + public function set_verify_ssl($bool = true)
  235 + {
  236 + $this->verify_ssl = (bool) $bool;
  237 + return $this->verify_ssl;
  238 + }
219 239
220 240 }
221 241
222 242
223   -class HipChat_Exception extends Exception {
  243 +class HipChat_Exception extends \Exception {
224 244 public function __construct($code, $info, $url) {
225 245 $message = "HipChat API error: code=$code, info=$info, url=$url";
226 246 parent::__construct($message, (int)$code);

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.