diff --git a/README.md b/README.md index 5067f55..0cab7b2 100644 --- a/README.md +++ b/README.md @@ -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) ## 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/APIgoatDoc.php is a formater diff --git a/classes/APIgoatDoc.php b/classes/APIgoatDoc.php index cca9a6a..e56eae3 100644 --- a/classes/APIgoatDoc.php +++ b/classes/APIgoatDoc.php @@ -9,18 +9,20 @@ class APIgoatDoc extends APIgoatTemplate $menu = ''; foreach ($data as $row) { - - $menu .= li(href($row['name'], '#' . $row['title']), "class='page_item wd-state-closed'"); - $content .= div( - anchor($row['title']) - . h2($row['title'], "class='entry-title'") - . h3($row['name']) - . span($row['type'] . " " . $row['value']) - . p(trim($row['text'])) - . ((!empty($row['example'])) ? div(span("Example:") . pre(htmlentities($row['example']))) : ''), - "", - "class='doc-item'" - ); + if (!empty($row['name'])) { + $menu .= li(href($row['name'], '#' . $row['title']), "class='page_item wd-state-closed'"); + $content .= div( + anchor($row['title']) + . h2($row['title'], "class='entry-title'") + . h3($row['name']) + . h4($row['group']) + . 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) { diff --git a/classes/APIgoatFetchAPI.php b/classes/APIgoatFetchAPI.php index 0dae5a0..b42c5dc 100644 --- a/classes/APIgoatFetchAPI.php +++ b/classes/APIgoatFetchAPI.php @@ -9,9 +9,9 @@ include_once plugin_dir_path(dirname(__FILE__)) . 'includes/html_helper.php'; class APIgoatFetchAPI { - private $username = 'wp-behavior@apigoat.com'; - private $password = 'iDhj3wsyYs7WrrS'; - private $baseURI = 'https://x.apigoat.com/api/v1/'; + private $username = 'sysadmin'; + private $password = 'vezvez'; + private $baseURI = 'https://goat.local/p/goatcheese/api/v1/'; private $jwt_pubkey = '9sKjdjuue8sSjwh6'; private $jwt_alg = ['HS256']; private $client; @@ -21,12 +21,15 @@ class APIgoatFetchAPI { $this->client = new APIClient($this->baseURI); $this->clientOptions = [ - 'verify' => true, + 'verify' => false, 'content-Type' => 'application/json', 'accept' => 'application/json', - 'debug' => false + 'debug' => false, + 'timeout' => 10 ]; + //unset($_SESSION['APIgoat']); + if (!$this->authenticationValid()) { $this->authenticate(); $this->saveCredentials(); @@ -43,25 +46,20 @@ class APIgoatFetchAPI $clientOptions['query'] = [ "query" => [ "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" => [ - "behavior" => [ - 0 => ["group", "Free"], - 1 => ["status", "Active"] - ] + ["status", "Active"] ], - "join" => ["behavior_category"], - "limit" => 20, - "recurse" => "behavior_file" - ], - "debug" => true + "join" => ["behavior_category"] + ] ]; - + //$clientOptions['debug'] = true; $response = $this->client->get('Behavior', $clientOptions); $body = json_decode($response->getBody()->getContents(), true); + //$body['debug'][] = $clientOptions['query']; if ($response->getStatusCode() == 200) { return $body; } else { @@ -87,7 +85,8 @@ class APIgoatFetchAPI 'u' => $this->username, 'pw' => md5($this->password) ], - 'debug' => false + 'debug' => false, + 'timeout' => 10 ]; // authenticate on API to get token $response = $this->client->post('Authy/auth', $options); diff --git a/classes/APIgoatList.php b/classes/APIgoatListModifiers.php similarity index 96% rename from classes/APIgoatList.php rename to classes/APIgoatListModifiers.php index 7639683..737d5b1 100644 --- a/classes/APIgoatList.php +++ b/classes/APIgoatListModifiers.php @@ -1,6 +1,6 @@ loader = new apigoat_doc_Loader(); } @@ -174,7 +174,8 @@ class apigoat_doc $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_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')); } /**