linkorb/answers-client

Answers Client for Answers Application

v1.0 2015-11-25 18:32 UTC

This package is auto-updated.

Last update: 2024-03-29 02:53:01 UTC


README

PHP client library for Answers application.

Installation

composer require linkorb/answers-client

Example

Client

require_once __DIR__ . '/../../vendor/autoload.php'; 

use Linkorb\AnswersClient\Client as Client;
use Linkorb\AnswersClient\Question as Question;

// get the client
$client = new Client(
    '<Host>',
    '<Username>',
    '<Password>'
);

Question

// Create Question 
$question = new Question( $client );
$question->setQuestion(<Question>);
$question->setDescription(<Description>);
$question->setTopicId(<topic id>);

try {
	$question->create(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

$question->setQuestion(<question>);

try {
	$question->update(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

// Get Question 
$question = new Question( $client );
$question->get(<Question id>);

$answers = $question->getAnswers();
var_dump($answers);

$comments = $question->getComments();
var_dump($comments);

$votes = $question->getVotes();
var_dump($votes);

// Update question
$question = new Question( $client );
$question->get(<Question id>);

$question->setQuestion(<Question>);
$question->setDescription(<Description>);

try {
	$question->update(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

// Delete question
$question = new Question( $client );
$question->get(<Question Id>);

try {
	$question->delete(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

//Comment
$question = new Question( $client );
$question->get(<Question id>);

try {
	$question->comment(<Comment>); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

// Vote
$question = new Question( $client );
$question->get(<Question id>);

try {
	$question->vote(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

Answer

// Create Answer 
$answer = new Answer( $client );
$answer->setQuestionId( <Question id> );
$answer->setAnswer( <Answer id> );

try {
	$answer->create(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

// Get Answer
$answer = new Answer( $client );
$answer->get( <Answer id> );

$comments = $answer->getComments();
var_dump($comments);

$votes = $answer->getVotes();
var_dump($votes);

// Update Answer
$answer = new Answer( $client );
$answer->get( <Answer id> );

$answer->setAnswer(<Answer>);

try {
	$answer->update(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

// Delete Answer
$answer = new Answer( $client );
$answer->get(<Answer id>);

try {
	$answer->delete(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

// Commnent Answer
$answer = new Answer( $client );
$answer->get(<Answer Id>);

try {
	$answer->comment(<Comment>); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

// Vote Answer
$answer = new Answer( $client );
$answer->get(<Answer Id>);

try {
	$answer->vote(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

Comment

// Get comment
$comment = new Comment( $client );
$comment->get(<Comment Id>);

$votes = $comment->getVotes();
var_dump($votes);

// Update comment
$answer = new Answer( $client );
$answer->get(<Answer id>);

$answer->setAnswer(<Answer>);

try {
	$answer->update(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

// Delete comment
$comment = new Comment( $client );
$comment->get(<Comment id>);

try {
	$comment->delete(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

// Vote comment
$comment = new Comment( $client );
$comment->get(<Comment id>);

try {
	$comment->vote(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

Vote

// Delete comment
$vote = new Vote( $client );
$vote->get(<Vote id>);

try {
	$vote->delete(); 
} catch( Exception $e ) {
	echo $e->getMessage();
} 

Brought to you by the LinkORB Engineering team

687474703a2f2f7777772e6c696e6b6f72622e636f6d2f642f6d6574612f74696572312f696d616765732f6c696e6b6f7262656e67696e656572696e672d6c6f676f2e706e67
Check out our other projects at engineering.linkorb.com.

Btw, we're hiring!