Skip to content

Commit dae0ebb

Browse files
committed
fixed example.
1 parent f92e0cc commit dae0ebb

File tree

5 files changed

+80
-91
lines changed

5 files changed

+80
-91
lines changed

README.md

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,22 @@ create config.jira.php file on your project root.
99
````php
1010
<?php
1111

12-
/*
13-
* Description get Jira Host Configuration
14-
*
15-
* @return array
16-
*/
17-
function getHostConfig() {
18-
$jira_config = array ('host' => 'https://jira.example.com',
19-
'username' => 'username',
20-
'password' => 'secure_passwd');
21-
22-
return $jira_config;
12+
function getConfig() {
13+
return array(
14+
// JIRA Host config
15+
'host' => 'https://jira.example.com',
16+
'username' => 'username',
17+
'password' => 'password',
18+
19+
// Options
20+
'CURLOPT_SSL_VERIFYHOST' => false,
21+
'CURLOPT_SSL_VERIFYPEER' => false,
22+
'CURLOPT_VERBOSE' => true,
23+
'LOG_FILE' => 'QQjira-rest-client.log',
24+
'LOG_LEVEL' => 'DEBUG'
25+
);
2326
}
2427

25-
/**
26-
* Description get Client options
27-
*
28-
* @return array
29-
*/
30-
function getOptions() {
31-
$options = array(
32-
CURLOPT_SSL_VERIFYHOST => 0,
33-
CURLOPT_SSL_VERIFYPEER => 0,
34-
CURLOPT_VERBOSE => false,
35-
'LOG_FILE' => 'jira-rest-client.log',
36-
'LOG_LEVEL' => \Monolog\Logger::INFO
37-
);
38-
39-
return $options;
40-
}
4128
?>
4229
````
4330

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

4835
````php
36+
<?php
37+
require 'vendor/autoload.php';
38+
require_once 'config.jira.php';
39+
4940
use JiraRestApi\Project\ProjectService;
5041

5142
try {
@@ -57,10 +48,15 @@ try {
5748
} catch (HTTPException $e) {
5849
print("Error Occured! " . $e->getMessage());
5950
}
51+
?>
6052
````
6153

6254
## Get All Project list
6355
````php
56+
<?php
57+
require 'vendor/autoload.php';
58+
require_once 'config.jira.php';
59+
6460
use JiraRestApi\Project\ProjectService;
6561

6662
try {
@@ -78,11 +74,16 @@ try {
7874
} catch (HTTPException $e) {
7975
print("Error Occured! " . $e->getMessage());
8076
}
77+
?>
8178
````
8279

8380
## Get Issue Info
8481

8582
````php
83+
<?php
84+
require 'vendor/autoload.php';
85+
require_once 'config.jira.php';
86+
8687
use JiraRestApi\Issue\IssueService;
8788
try {
8889
$issueService = new IssueService();
@@ -93,11 +94,17 @@ try {
9394
} catch (HTTPException $e) {
9495
print("Error Occured! " . $e->getMessage());
9596
}
97+
98+
?>
9699
````
97100

98101
## Create Issue
99102

100103
````php
104+
<?php
105+
require 'vendor/autoload.php';
106+
require_once 'config.jira.php';
107+
101108
use JiraRestApi\Issue\IssueService;
102109
use JiraRestApi\Issue\IssueField;
103110
try {
@@ -120,6 +127,8 @@ try {
120127
} catch (HTTPException $e) {
121128
print("Error Occured! " . $e->getMessage());
122129
}
130+
131+
?>
123132
````
124133

125134
# License
@@ -128,5 +137,4 @@ Apache V2 License
128137

129138
# JIRA Rest API Documents
130139
* 6.2 - https://docs.atlassian.com/jira/REST/6.2/
131-
* latest - https://docs.atlassian.com/jira/REST/latest/
132-
140+
* latest - https://docs.atlassian.com/jira/REST/latest/

src/JiraClient.php

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,17 @@ class JiraClient {
3535
/** @var Monolog instance */
3636
protected $log;
3737

38-
private $options = array(
39-
// disable SSL Certification validation
40-
CURLOPT_SSL_VERIFYHOST => 0,
41-
// FALSE to stop CURL from verifying the peer's certificate.
42-
CURLOPT_SSL_VERIFYPEER => 0,
38+
// disable SSL Certification validation
39+
protected $CURLOPT_SSL_VERIFYHOST = false;
40+
// FALSE to stop CURL from verifying the peer's certificate.
41+
protected $CURLOPT_SSL_VERIFYPEER = false;
4342

44-
CURLOPT_VERBOSE => true,
45-
46-
'LOG_FILE' => 'jira-rest-client.log',
47-
'LOG_LEVEL' => Logger::INFO,
48-
);
43+
// debug curl
44+
protected $CURLOPT_VERBOSE = false;
4945

46+
protected $LOG_FILE = 'jira-rest-client.log';
47+
protected $LOG_LEVEL = Logger::INFO;
48+
5049
private function convertLogLevel($log_level) {
5150
if ($log_level == 'DEBUG')
5251
return Logger::DEBUG;
@@ -58,7 +57,7 @@ private function convertLogLevel($log_level) {
5857
return Logger::INFO;
5958
}
6059

61-
public function __construct($config, $options = null)
60+
public function __construct($config)
6261
{
6362
$this->json_mapper = new \JsonMapper();
6463
$this->json_mapper->bExceptionOnUndefinedProperty = true;
@@ -67,25 +66,25 @@ public function __construct($config, $options = null)
6766
$this->username = $config['username'];
6867
$this->password = $config['password'];
6968

70-
if (!is_null($options)) {
71-
//http://stackoverflow.com/questions/5929642/php-array-merge-with-numerical-keys
72-
// array_merge with numeric key
73-
$this->options = $this->options + $options;
74-
//$this->options = array_merge($this->options, $options);
69+
if (isset($config['CURLOPT_SSL_VERIFYHOST']))
70+
$this->CURLOPT_SSL_VERIFYHOST = $config['CURLOPT_SSL_VERIFYHOST'] === 'true'? true: false;
71+
72+
if (isset($config['CURLOPT_SSL_VERIFYPEER']))
73+
$this->CURLOPT_SSL_VERIFYPEER = $config['CURLOPT_SSL_VERIFYPEER'] === 'true'? true: false;
74+
75+
if (isset($config['CURLOPT_VERBOSE']))
76+
$this->CURLOPT_VERBOSE = $config['CURLOPT_VERBOSE'] === 'true'? true: false;
7577

76-
if (isset($options['LOG_FILE']))
77-
$this->options['LOG_FILE'] = $options['LOG_FILE'];
78-
if (isset($options['LOG_LEVEL']))
79-
$this->options['LOG_LEVEL'] = $this->convertLogLevel($options['LOG_LEVEL']);
80-
}
78+
if (isset($config['LOG_FILE']))
79+
$this->LOG_FILE = $config['LOG_FILE'];
8180

82-
// create logger
83-
$log_file = $options['LOG_FILE'];
84-
$log_level = $this->convertLogLevel($options['LOG_LEVEL']);
81+
if (isset($config['LOG_LEVEL']))
82+
$this->LOG_LEVEL = $this->convertLogLevel($config['LOG_LEVEL']);
8583

84+
// create logger
8685
$this->log = new Logger('JiraClient');
87-
$this->log->pushHandler(new StreamHandler($this->options['LOG_FILE'],
88-
$this->options['LOG_LEVEL']));
86+
$this->log->pushHandler(new StreamHandler($this->LOG_FILE,
87+
$this->LOG_LEVEL));
8988

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

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

120-
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, $this->options[CURLOPT_SSL_VERIFYHOST]);
121-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->options[CURLOPT_SSL_VERIFYPEER]);
119+
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, $this->CURLOPT_SSL_VERIFYHOST);
120+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->CURLOPT_SSL_VERIFYPEER);
122121

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

127-
curl_setopt($ch, CURLOPT_VERBOSE, $this->options[CURLOPT_VERBOSE]);
126+
curl_setopt($ch, CURLOPT_VERBOSE, $this->CURLOPT_VERBOSE);
128127

129128
$this->log->addDebug('Curl exec=' . $url);
130129
$response = curl_exec($ch);

src/config.jira.example.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
<?php
22

3-
/**
4-
* Description get Jira Host Configuration
5-
*
6-
* @return array
7-
*/
8-
function getHostConfig() {
9-
$jira_config = array ('host' => 'https://jira.example.com',
10-
'username' => 'username',
11-
'password' => 'password');
3+
function getConfig() {
4+
return array(
5+
// JIRA Host config
6+
'host' => 'https://jira.example.com',
7+
'username' => 'username',
8+
'password' => 'password',
129

13-
return $jira_config;
14-
}
15-
16-
/**
17-
* Description get Client options
18-
*
19-
* @return array
20-
*/
21-
function getOptions() {
22-
$options = array(
23-
CURLOPT_SSL_VERIFYHOST => 0,
24-
CURLOPT_SSL_VERIFYPEER => 0,
25-
CURLOPT_VERBOSE => true,
26-
'LOG_FILE' => 'log/jira-rest-client.log',
27-
'LOG_LEVEL' => \Monolog\Logger::INFO
28-
);
29-
30-
return $options;
10+
// Options
11+
'CURLOPT_SSL_VERIFYHOST' => false,
12+
'CURLOPT_SSL_VERIFYPEER' => false,
13+
'CURLOPT_VERBOSE' => true,
14+
'LOG_FILE' => 'QQjira-rest-client.log',
15+
'LOG_LEVEL' => 'DEBUG'
16+
);
3117
}
3218

3319
?>

src/issue/IssueService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
namespace JiraRestApi\Issue;
44

5-
require 'vendor/autoload.php';
6-
75
class IssueService extends \JiraRestApi\JiraClient {
86
private $uri = "/issue";
97

108
public function __construct() {
11-
parent::__construct(getHostConfig(), getOptions());
9+
parent::__construct(getConfig());
1210
}
1311

1412
/**

src/project/ProjectService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
namespace JiraRestApi\Project;
44

5-
require 'vendor/autoload.php';
6-
75
class ProjectService extends \JiraRestApi\JiraClient {
86
private $uri = "/project";
97

108
public function __construct() {
11-
parent::__construct(getHostConfig(), getOptions());
9+
parent::__construct(getConfig());
1210
}
1311

1412
/**

0 commit comments

Comments
 (0)