Compare commits
4 Commits
7cd6339996
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d4b6efe34 | ||
|
|
92f6e190dc | ||
|
|
5c11fc0552 | ||
|
|
8c3c022f0c |
@@ -8,7 +8,7 @@ It produce a shortcode to fetch and format content from a APIgoat project API.
|
|||||||
It is based on DevinVinson/WordPress-Plugin-Boilerplate(https://github.com/DevinVinson/WordPress-Plugin-Boilerplate)
|
It is based on DevinVinson/WordPress-Plugin-Boilerplate(https://github.com/DevinVinson/WordPress-Plugin-Boilerplate)
|
||||||
|
|
||||||
## Details
|
## Details
|
||||||
* classes/APIgoatList.php is the main shortcode definition
|
* classes/APIgoatListModifiers.php is the main shortcode definition
|
||||||
* classes/APIgoatFetchAPI.php contains the authentication and query
|
* classes/APIgoatFetchAPI.php contains the authentication and query
|
||||||
* classes/APIgoatDoc.php is a formater
|
* classes/APIgoatDoc.php is a formater
|
||||||
|
|
||||||
|
|||||||
@@ -3,23 +3,65 @@
|
|||||||
class APIgoatDoc extends APIgoatTemplate
|
class APIgoatDoc extends APIgoatTemplate
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static function getExamples(array $data, array $headers)
|
||||||
|
{
|
||||||
|
$content = '';
|
||||||
|
$menu = '';
|
||||||
|
|
||||||
|
foreach ($data as $row) {
|
||||||
|
if (!empty($row['name'])) {
|
||||||
|
$menu .= li(href($row['name'], '#' . $row['name']), "class='page_item wd-state-closed'");
|
||||||
|
$content .= div(
|
||||||
|
anchor($row['name'])
|
||||||
|
. h2($row['name'], "class='entry-title'")
|
||||||
|
. p(trim($row['text']))
|
||||||
|
. ((!empty($row['json'])) ? div(span("Example:") . $row['json']) : ''),
|
||||||
|
"",
|
||||||
|
"class='doc-item'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($headers as $name => $header) {
|
||||||
|
$menu = h3($header) . $menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return div(
|
||||||
|
div(
|
||||||
|
ul($menu, "class='doc-nav-list'"),
|
||||||
|
'',
|
||||||
|
"class='wedocs-sidebar wedocs-hide-mobile'"
|
||||||
|
) . div(
|
||||||
|
$content,
|
||||||
|
'',
|
||||||
|
"class='wedocs-single-content'"
|
||||||
|
),
|
||||||
|
'',
|
||||||
|
"class='wedocs-single-wrap'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static function getDocs(array $data, array $headers)
|
static function getDocs(array $data, array $headers)
|
||||||
{
|
{
|
||||||
$content = '';
|
$content = '';
|
||||||
$menu = '';
|
$menu = '';
|
||||||
|
|
||||||
//preprint($data);
|
|
||||||
|
|
||||||
foreach ($data as $row) {
|
foreach ($data as $row) {
|
||||||
|
if (!empty($row['name'])) {
|
||||||
$menu .= li(href($row['name'], '#' . $row['title']), "class='page_item current_page_item'");
|
$menu .= li(href($row['name'], '#' . $row['title']), "class='page_item wd-state-closed'");
|
||||||
$content .= div(
|
$content .= div(
|
||||||
anchor($row['title']) . h3($row['name'])
|
anchor($row['title'])
|
||||||
. h2($row['title'], "class='entry-title'")
|
. h2($row['title'], "class='entry-title'")
|
||||||
. p($row['type'] . " " . $row['value'])
|
. h3($row['name'])
|
||||||
. ((!empty($row['example'])) ? pre(htmlentities($row['example'])) : '')
|
. h4($row['group'])
|
||||||
. p(trim($row['text']))
|
. span($row['type'] . " " . $row['value'])
|
||||||
);
|
. p(trim($row['text']))
|
||||||
|
. ((!empty($row['example'])) ? div(span("Example:") . pre(htmlentities($row['example']))) : ''),
|
||||||
|
"",
|
||||||
|
"class='doc-item'"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($headers as $name => $header) {
|
foreach ($headers as $name => $header) {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ include_once plugin_dir_path(dirname(__FILE__)) . 'includes/html_helper.php';
|
|||||||
class APIgoatFetchAPI
|
class APIgoatFetchAPI
|
||||||
{
|
{
|
||||||
|
|
||||||
private $username = 'wp-behavior@apigoat.com';
|
private $username = 'sysadmin';
|
||||||
private $password = '0sKtegdSSk';
|
private $password = 'vezvez';
|
||||||
private $baseURI = 'https://goat.local/p/goatcheese/api/v1/';
|
private $baseURI = 'https://goat.local/p/goatcheese/api/v1/';
|
||||||
private $jwt_pubkey = '9sKjdjuue8sSjwh6';
|
private $jwt_pubkey = '9sKjdjuue8sSjwh6';
|
||||||
private $jwt_alg = ['HS256'];
|
private $jwt_alg = ['HS256'];
|
||||||
@@ -23,9 +23,13 @@ class APIgoatFetchAPI
|
|||||||
$this->clientOptions = [
|
$this->clientOptions = [
|
||||||
'verify' => false,
|
'verify' => false,
|
||||||
'content-Type' => 'application/json',
|
'content-Type' => 'application/json',
|
||||||
'accept' => 'application/json'
|
'accept' => 'application/json',
|
||||||
|
'debug' => false,
|
||||||
|
'timeout' => 10
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//unset($_SESSION['APIgoat']);
|
||||||
|
|
||||||
if (!$this->authenticationValid()) {
|
if (!$this->authenticationValid()) {
|
||||||
$this->authenticate();
|
$this->authenticate();
|
||||||
$this->saveCredentials();
|
$this->saveCredentials();
|
||||||
@@ -40,26 +44,47 @@ class APIgoatFetchAPI
|
|||||||
{
|
{
|
||||||
$clientOptions = $this->clientOptions;
|
$clientOptions = $this->clientOptions;
|
||||||
$clientOptions['query'] = [
|
$clientOptions['query'] = [
|
||||||
"Query" => [
|
"query" => [
|
||||||
"select" => [
|
"select" => [
|
||||||
["behavior.name", "name"], ["code", "title"], ["description", "text"], "value", "example", "type", ["behavior_category.name", "category_name"]
|
["behavior.name", "name"], ["code", "title"], ["description", "text"], "value", "example", "type", ["behavior_category.name", "category_name"], "group"
|
||||||
],
|
],
|
||||||
"filter" => [
|
"filter" => [
|
||||||
"behavior" => [
|
["status", "Active"]
|
||||||
0 => ["group", "Free"],
|
|
||||||
1 => ["status", "Active"]
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
"join" => ["behavior_category"],
|
"join" => ["behavior_category"]
|
||||||
"limit" => 20
|
]
|
||||||
],
|
|
||||||
"debug" => true
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//$clientOptions['debug'] = true;
|
||||||
$response = $this->client->get('Behavior', $clientOptions);
|
$response = $this->client->get('Behavior', $clientOptions);
|
||||||
|
|
||||||
$body = json_decode($response->getBody()->getContents(), true);
|
$body = json_decode($response->getBody()->getContents(), true);
|
||||||
|
//$body['debug'][] = $clientOptions['query'];
|
||||||
|
if ($response->getStatusCode() == 200) {
|
||||||
|
return $body;
|
||||||
|
} else {
|
||||||
|
$body = json_decode($response->getBody(), true);
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetchExamples()
|
||||||
|
{
|
||||||
|
$clientOptions = $this->clientOptions;
|
||||||
|
$clientOptions['query'] = [
|
||||||
|
"query" => [
|
||||||
|
"select" => [
|
||||||
|
"name", ["description", "text"], ["example_category.name", "category_name"], "json"
|
||||||
|
],
|
||||||
|
"join" => ["example_category"]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
//$clientOptions['debug'] = true;
|
||||||
|
$response = $this->client->get('Example', $clientOptions);
|
||||||
|
|
||||||
|
$body = json_decode($response->getBody()->getContents(), true);
|
||||||
|
//$body['debug'][] = $clientOptions['query'];
|
||||||
if ($response->getStatusCode() == 200) {
|
if ($response->getStatusCode() == 200) {
|
||||||
return $body;
|
return $body;
|
||||||
} else {
|
} else {
|
||||||
@@ -85,11 +110,14 @@ class APIgoatFetchAPI
|
|||||||
'u' => $this->username,
|
'u' => $this->username,
|
||||||
'pw' => md5($this->password)
|
'pw' => md5($this->password)
|
||||||
],
|
],
|
||||||
'debug' => false
|
'debug' => false,
|
||||||
|
'timeout' => 10
|
||||||
];
|
];
|
||||||
// authenticate on API to get token
|
// authenticate on API to get token
|
||||||
$response = $this->client->post('Authy/auth', $options);
|
$response = $this->client->post('Authy/auth', $options);
|
||||||
$loginResponseDecoded = json_decode($response->getBody()->getContents(), true);
|
$loginResponseDecoded = json_decode($response->getBody()->getContents(), true);
|
||||||
|
/*print_r($loginResponseDecoded);
|
||||||
|
die();*/
|
||||||
|
|
||||||
$this->credentials = new AccessTokenCredentials($loginResponseDecoded['token']);
|
$this->credentials = new AccessTokenCredentials($loginResponseDecoded['token']);
|
||||||
}
|
}
|
||||||
|
|||||||
25
classes/APIgoatListExamples.php
Normal file
25
classes/APIgoatListExamples.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class APIgoatListExamples
|
||||||
|
{
|
||||||
|
|
||||||
|
static function init($atts, $content = null)
|
||||||
|
{
|
||||||
|
$APIgoatFetchAPI = new APIgoatFetchAPI();
|
||||||
|
$Behaviors = $APIgoatFetchAPI->fetchExamples();
|
||||||
|
if (isset($Behaviors['debug'])) {
|
||||||
|
echo "<br>" . preprint($Behaviors['debug']) . "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($Behaviors['messages'])) {
|
||||||
|
echo "<br>" . preprint($Behaviors['messages']) . "<br>";
|
||||||
|
}
|
||||||
|
if ($Behaviors['data']) {
|
||||||
|
$table = APIgoatDoc::getExamples($Behaviors['data'], ['Code' => 'Examples']);
|
||||||
|
|
||||||
|
return $content . div($table, '', "class='site-main'");
|
||||||
|
} else {
|
||||||
|
return $content . "<br>Error" . preprint($Behaviors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class APIgoatList
|
class APIgoatListModifiers
|
||||||
{
|
{
|
||||||
|
|
||||||
static function init($atts, $content = null)
|
static function init($atts, $content = null)
|
||||||
@@ -15,7 +15,7 @@ class APIgoatList
|
|||||||
echo "<br>" . preprint($Behaviors['messages']) . "<br>";
|
echo "<br>" . preprint($Behaviors['messages']) . "<br>";
|
||||||
}*/
|
}*/
|
||||||
if ($Behaviors['data']) {
|
if ($Behaviors['data']) {
|
||||||
$table = APIgoatDoc::getDocs($Behaviors['data'], ['Code' => 'Parameters']);
|
$table = APIgoatDoc::getDocs($Behaviors['data'], ['Code' => 'Modifiers']);
|
||||||
|
|
||||||
return $content . div($table, '', "class='site-main'");
|
return $content . div($table, '', "class='site-main'");
|
||||||
} else {
|
} else {
|
||||||
@@ -124,7 +124,8 @@ class apigoat_doc
|
|||||||
*/
|
*/
|
||||||
require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-apigoat_doc-public.php';
|
require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-apigoat_doc-public.php';
|
||||||
|
|
||||||
require plugin_dir_path(dirname(__FILE__)) . 'classes/APIgoatList.php';
|
require plugin_dir_path(dirname(__FILE__)) . 'classes/APIgoatListModifiers.php';
|
||||||
|
require plugin_dir_path(dirname(__FILE__)) . 'classes/APIgoatListExamples.php';
|
||||||
|
|
||||||
$this->loader = new apigoat_doc_Loader();
|
$this->loader = new apigoat_doc_Loader();
|
||||||
}
|
}
|
||||||
@@ -174,7 +175,8 @@ class apigoat_doc
|
|||||||
$this->loader->add_action('init', $plugin_public, 'register_session', 1);
|
$this->loader->add_action('init', $plugin_public, 'register_session', 1);
|
||||||
$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
|
$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
|
||||||
$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
|
$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
|
||||||
$this->loader->add_shortcode('APIgoat_list', $plugin_public, array('APIgoatList', 'init'));
|
$this->loader->add_shortcode('APIgoat_list_modifiers', $plugin_public, array('APIgoatListModifiers', 'init'));
|
||||||
|
$this->loader->add_shortcode('APIgoat_list_examples', $plugin_public, array('APIgoatListExamples', 'init'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user