Skip to content

Commit

Permalink
fixed example.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif committed Feb 9, 2015
1 parent f92e0cc commit dae0ebb
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 91 deletions.
66 changes: 37 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,22 @@ create config.jira.php file on your project root.
````php
<?php

/*
* Description get Jira Host Configuration
*
* @return array
*/
function getHostConfig() {
$jira_config = array ('host' => 'https://jira.example.com',
'username' => 'username',
'password' => 'secure_passwd');

return $jira_config;
function getConfig() {
return array(
// JIRA Host config
'host' => 'https://jira.example.com',
'username' => 'username',
'password' => 'password',

// Options
'CURLOPT_SSL_VERIFYHOST' => false,
'CURLOPT_SSL_VERIFYPEER' => false,
'CURLOPT_VERBOSE' => true,
'LOG_FILE' => 'QQjira-rest-client.log',
'LOG_LEVEL' => 'DEBUG'
);
}

/**
* Description get Client options
*
* @return array
*/
function getOptions() {
$options = array(
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_VERBOSE => false,
'LOG_FILE' => 'jira-rest-client.log',
'LOG_LEVEL' => \Monolog\Logger::INFO
);

return $options;
}
?>
````

Expand All @@ -46,6 +33,10 @@ function getOptions() {
## Get Project Info

````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Project\ProjectService;

try {
Expand All @@ -57,10 +48,15 @@ try {
} catch (HTTPException $e) {
print("Error Occured! " . $e->getMessage());
}
?>
````

## Get All Project list
````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Project\ProjectService;

try {
Expand All @@ -78,11 +74,16 @@ try {
} catch (HTTPException $e) {
print("Error Occured! " . $e->getMessage());
}
?>
````

## Get Issue Info

````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Issue\IssueService;
try {
$issueService = new IssueService();
Expand All @@ -93,11 +94,17 @@ try {
} catch (HTTPException $e) {
print("Error Occured! " . $e->getMessage());
}

?>
````

## Create Issue

````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\IssueField;
try {
Expand All @@ -120,6 +127,8 @@ try {
} catch (HTTPException $e) {
print("Error Occured! " . $e->getMessage());
}

?>
````

# License
Expand All @@ -128,5 +137,4 @@ Apache V2 License

# JIRA Rest API Documents
* 6.2 - https://docs.atlassian.com/jira/REST/6.2/
* latest - https://docs.atlassian.com/jira/REST/latest/

* latest - https://docs.atlassian.com/jira/REST/latest/
57 changes: 28 additions & 29 deletions src/JiraClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ class JiraClient {
/** @var Monolog instance */
protected $log;

private $options = array(
// disable SSL Certification validation
CURLOPT_SSL_VERIFYHOST => 0,
// FALSE to stop CURL from verifying the peer's certificate.
CURLOPT_SSL_VERIFYPEER => 0,
// disable SSL Certification validation
protected $CURLOPT_SSL_VERIFYHOST = false;
// FALSE to stop CURL from verifying the peer's certificate.
protected $CURLOPT_SSL_VERIFYPEER = false;

CURLOPT_VERBOSE => true,

'LOG_FILE' => 'jira-rest-client.log',
'LOG_LEVEL' => Logger::INFO,
);
// debug curl
protected $CURLOPT_VERBOSE = false;

protected $LOG_FILE = 'jira-rest-client.log';
protected $LOG_LEVEL = Logger::INFO;

private function convertLogLevel($log_level) {
if ($log_level == 'DEBUG')
return Logger::DEBUG;
Expand All @@ -58,7 +57,7 @@ private function convertLogLevel($log_level) {
return Logger::INFO;
}

public function __construct($config, $options = null)
public function __construct($config)
{
$this->json_mapper = new \JsonMapper();
$this->json_mapper->bExceptionOnUndefinedProperty = true;
Expand All @@ -67,25 +66,25 @@ public function __construct($config, $options = null)
$this->username = $config['username'];
$this->password = $config['password'];

if (!is_null($options)) {
//http://stackoverflow.com/questions/5929642/php-array-merge-with-numerical-keys
// array_merge with numeric key
$this->options = $this->options + $options;
//$this->options = array_merge($this->options, $options);
if (isset($config['CURLOPT_SSL_VERIFYHOST']))
$this->CURLOPT_SSL_VERIFYHOST = $config['CURLOPT_SSL_VERIFYHOST'] === 'true'? true: false;

if (isset($config['CURLOPT_SSL_VERIFYPEER']))
$this->CURLOPT_SSL_VERIFYPEER = $config['CURLOPT_SSL_VERIFYPEER'] === 'true'? true: false;

if (isset($config['CURLOPT_VERBOSE']))
$this->CURLOPT_VERBOSE = $config['CURLOPT_VERBOSE'] === 'true'? true: false;

if (isset($options['LOG_FILE']))
$this->options['LOG_FILE'] = $options['LOG_FILE'];
if (isset($options['LOG_LEVEL']))
$this->options['LOG_LEVEL'] = $this->convertLogLevel($options['LOG_LEVEL']);
}
if (isset($config['LOG_FILE']))
$this->LOG_FILE = $config['LOG_FILE'];

// create logger
$log_file = $options['LOG_FILE'];
$log_level = $this->convertLogLevel($options['LOG_LEVEL']);
if (isset($config['LOG_LEVEL']))
$this->LOG_LEVEL = $this->convertLogLevel($config['LOG_LEVEL']);

// create logger
$this->log = new Logger('JiraClient');
$this->log->pushHandler(new StreamHandler($this->options['LOG_FILE'],
$this->options['LOG_LEVEL']));
$this->log->pushHandler(new StreamHandler($this->LOG_FILE,
$this->LOG_LEVEL));

$this->http_response = 200;
}
Expand Down Expand Up @@ -117,14 +116,14 @@ public function exec($context, $post_data = null, $custom_request = null) {

curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password");

curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, $this->options[CURLOPT_SSL_VERIFYHOST]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->options[CURLOPT_SSL_VERIFYPEER]);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, $this->CURLOPT_SSL_VERIFYHOST);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->CURLOPT_SSL_VERIFYPEER);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Accept: */*', 'Content-Type: application/json'));

curl_setopt($ch, CURLOPT_VERBOSE, $this->options[CURLOPT_VERBOSE]);
curl_setopt($ch, CURLOPT_VERBOSE, $this->CURLOPT_VERBOSE);

$this->log->addDebug('Curl exec=' . $url);
$response = curl_exec($ch);
Expand Down
40 changes: 13 additions & 27 deletions src/config.jira.example.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
<?php

/**
* Description get Jira Host Configuration
*
* @return array
*/
function getHostConfig() {
$jira_config = array ('host' => 'https://jira.example.com',
'username' => 'username',
'password' => 'password');
function getConfig() {
return array(
// JIRA Host config
'host' => 'https://jira.example.com',
'username' => 'username',
'password' => 'password',

return $jira_config;
}

/**
* Description get Client options
*
* @return array
*/
function getOptions() {
$options = array(
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_VERBOSE => true,
'LOG_FILE' => 'log/jira-rest-client.log',
'LOG_LEVEL' => \Monolog\Logger::INFO
);

return $options;
// Options
'CURLOPT_SSL_VERIFYHOST' => false,
'CURLOPT_SSL_VERIFYPEER' => false,
'CURLOPT_VERBOSE' => true,
'LOG_FILE' => 'QQjira-rest-client.log',
'LOG_LEVEL' => 'DEBUG'
);
}

?>
4 changes: 1 addition & 3 deletions src/issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace JiraRestApi\Issue;

require 'vendor/autoload.php';

class IssueService extends \JiraRestApi\JiraClient {
private $uri = "/issue";

public function __construct() {
parent::__construct(getHostConfig(), getOptions());
parent::__construct(getConfig());
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/project/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace JiraRestApi\Project;

require 'vendor/autoload.php';

class ProjectService extends \JiraRestApi\JiraClient {
private $uri = "/project";

public function __construct() {
parent::__construct(getHostConfig(), getOptions());
parent::__construct(getConfig());
}

/**
Expand Down

0 comments on commit dae0ebb

Please sign in to comment.