lesstif / confluence-rest-api
Confluence REST API Client for PHP Users.
Installs: 12 314
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 3
Forks: 12
Open Issues: 2
Requires
- php: ^7.3|^8.0
- ext-curl: *
- ext-iconv: *
- ext-json: *
- guzzlehttp/guzzle: ^7.0.1
- league/flysystem: ^1.1
- monolog/monolog: ~1.12|^2.0
- netresearch/jsonmapper: ^2.0|^3.0|^4.0
- vlucas/phpdotenv: ^4.0|^5.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpstan/phpstan: ^0.12.79
- phpunit/phpunit: ^8.0|^9.0
- symfony/var-dumper: ^4.0|^5.0
- vimeo/psalm: ^4.6
This package is auto-updated.
Last update: 2024-11-05 08:02:14 UTC
README
Atlassian's Confluence & Confluence Question REST API Client for PHP Users.
installation
-
Install PHP Composer manually or download it from composer home page.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php php -r "unlink('composer-setup.php');"
-
run composer for install dependency.
php composer.phar require 'lesstif/confluence-rest-api'
or update your composer.json.
"require": {
"lesstif/confluence-rest-api": "^0.1"
}
Configuration
you can choose loads environment variables either 'dotenv' or 'array'.
use dotenv
copy .env.example file to .env on your project root directory.
CONFLUENCE_HOST="https://your-confluence.host.com"
CONFLUENCE_USER="confluence-username"
CONFLUENCE_PASS="confluence-password"
use array
create Service class with ArrayConfiguration parameter.
use Lesstif\Confluence\Question\QuestionService; $qs = new QuestionService(new \Lesstif\Confluence\Configuration\ArrayConfiguration( [ 'host' => 'https://your-confluence.host.com', 'user' => 'confluence-username', 'password' => 'confluence-password', ] ));
Usage
CQL
$cql = [ 'SPACE' => 'LAR', 'type' => 'page', ]; try { $s = new CQLService(); $ret = $s->search($cql); dump($ret); } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
Question
getting Question list
$queryParam = [ // the number of questions needed (10 by default) 'limit' => 10, //the start index (0 by default) 'start' => 0, // The optional filter string which value is one of "unanswered", "popular", "my", "recent" // (default value 'recent') 'filter' => 'unanswered', ]; try { $qs = new QuestionService(); $questions = $qs->getQuestion($queryParam); foreach($questions as $q) { echo sprintf("<a href=\"%s\">%s</a><p/>\n", $q->url, $q->title); } } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
getting Question's detail info.
try { $qs = new QuestionService(); $q = $qs->getQuestionDetail($questionId); foreach($q->answers as $a) { // print accepted answer if ($a->accepted === true) { dump($a); } } } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
getting accepted answer
try { $qs = new QuestionService(); $q = $qs->getAcceptedAnswer($questionId); dump($q); } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
Answer
getting user's answer list
try { $username = 'lesstif'; $as = new AnswerService(); $ans = $as->getAnswers($username); foreach($ans as $a) { dump($a); } } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
getting related question.
try { $answerId = '123456'; $as = new AnswerService(); $q = $as->getQuestion($answerId); dump($q); } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
Confluence Rest API Documents
- Confluence Server REST API - https://developer.atlassian.com/confdev/confluence-server-rest-api
- latest server - https://docs.atlassian.com/atlassian-confluence/REST/latest-server/
- Confluence Question REST API - https://docs.atlassian.com/confluence-questions/rest/index.html