Skip to content

Commit

Permalink
Updated learn page (TODO have it load Swagger instead of the plugin);…
Browse files Browse the repository at this point in the history
… fixed Swagger manifest newline issue; Advanced plugin version. Ready for release.
  • Loading branch information
alexdma committed Feb 11, 2016
1 parent 883ec3b commit 78e5817
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 107 deletions.
124 changes: 68 additions & 56 deletions pages/learn.htm
Original file line number Diff line number Diff line change
@@ -1,85 +1,97 @@
<!-- Swagger stuff -->
<link rel='stylesheet' id='swaggerui-screen-css' href='wp-content/plugins/ecapi/lib/swagger-ui/css/screen.css' type='text/css' media='all'/>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/shred.bundle.js?ver=4.0.1'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/jquery.slideto.min.js?ver=4.0.1'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/jquery.wiggle.min.js?ver=4.0.1'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/jquery.ba-bbq.min.js?ver=4.0.1'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/underscore-min.js?ver=4.0.1'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/backbone-min.js?ver=4.0.1'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/handlebars-1.0.0.js?ver=4.0.1'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/swagger.js?ver=2.0.47'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/swagger-client.js?ver=4.0.1'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/swagger-ui.min.js?ver=4.0.1'></script>
<script type='text/javascript' src='wp-content/plugins/ecapi/lib/swagger-ui/lib/highlight.7.3.pack.js?ver=4.0.1'></script>
<!-- END Swagger stuff -->

[insert_php]$opts = get_option('ecapi_options');[/insert_php]

[insert_php]$opts = get_option('ecapi_options');[/insert_php]
<section>Alongside obtaining data by <a title="Reading Feeds: the Developers’ API" href="/developers-api/">reading feeds</a>, the MK Data Hub provides an interface for reading streams of integrated data that are aggregated from a multitude of datasets registered with the Data Catalogue. The aggregation logic revolves around presenting all the data that the user has access to regarding a specific <em>entity</em> (e.g. a location in Milton Keynes). This way, the user is not required to specify the URL or name of a data source or feed. This document is a guide for developers who do not require to tweak their data-intensive applications to use specific data-sources.</section>
&nbsp;
<section>
<p>Alongside obtaining data by <a href="developers-api" title="Reading Feeds: the Developers’ API">reading feeds</a>, the MK Data Hub provides an interface for reading streams of integrated data that are aggregated from a multitude of datasets registered with the Data Catalogue. The aggregation logic revolves around presenting all the data that the user has access to regarding a specific <em>entity</em> (e.g. a location in Milton Keynes). This way, the user is not required to specify the URL or name of a data source or feed.

This document is a guide for developers who do not require to tweak their data-intensive applications to use specific data-sources.</p>
</section>
<section>
<h2>Getting started</h2>
<ol>
<li>Arm yourself with an HTTP client (e.g. <strong>curl</strong>, your own client code, or even this browser) and you're good to go.</li>
<li>Perform an HTTP GET request to <a href="[insert_php] echo $opts['ecapi_url']; [/insert_php]">[insert_php] echo $opts['ecapi_url']; [/insert_php]</a> e.g.</li>
<code>curl [insert_php] echo $opts['ecapi_url']; [/insert_php]</code>
</ol>
<p>If the response is JSON content of the type
<pre>{
<h2>Getting started</h2>
<ol>
<ol>
<li>Arm yourself with an HTTP client (e.g. <strong>curl</strong>, your own client code, or even this browser) and you're good to go.</li>
</ol>
</ol>
<li>Perform an HTTP GET request to <a href="[insert_php] echo $opts['ecapi_url']; [/insert_php]">[insert_php] echo $opts['ecapi_url']; [/insert_php]</a> e.g.</li>

<code>curl [insert_php] echo $opts['ecapi_url']; [/insert_php]</code>

If the response is JSON content of the type

<pre lang="json">{
"subresources": [ ... ],
"comment": "Beware: I live!",
"live": true
}</pre>
then the API is alive and reachable.</p>
<p>In order to explore the data published by the API, you need to be able to identify the entity to obtain data about. Identifying an entity essentially means constructing a URI that is submitted to the API. Note that the <a href="https://datahub.beta.mksmart.org/entity-lookup/">Entity Lookup</a> Facility provides a way to simply construct requests to the entity-centric API.
<!-- This can be done either by <em>type and property</em> or by <em>property</em> alone.</p> -->

then the API is alive and reachable.

In order to explore the data published by the API, you need to be able to identify the entity to obtain data about. Identifying an entity essentially means constructing a URI that is submitted to the API. Note that the <a href="https://datahub.beta.mksmart.org/entity-lookup/">Entity Lookup</a> Facility provides a way to simply construct requests to the entity-centric API. <!-- This can be done either by <em>type and property</em> or by <em>property</em> alone.
-->
</section>
&nbsp;
<section>
<h2>Exploring by type and identifier</h2>
<!--<p>The most general way to identify an entity is by combining its type with the name of a property and a value for it, which altogether uniquely identifies the entity. For example, the equivalent of "describe the British administrative sector whose postcode is MK77" has the URI:

<h2>Exploring by type and identifier</h2>

<!--
The most general way to identify an entity is by combining its type with the name of a property and a value for it, which altogether uniquely identifies the entity. For example, the equivalent of "describe the British administrative sector whose postcode is MK77" has the URI:
-->
<p>Making requests to the entity-centric API is relatively simple, as long as you know the type and identifier of the entity about which information is required. For example, getting information about the geographic sector "MK77" is simply done by calling the URI:

<code>[insert_php] echo $opts['ecapi_url']; [/insert_php]sector/MK77</code>
</p>
Making requests to the entity-centric API is relatively simple, as long as you know the type and identifier of the entity about which information is required. For example, getting information about the geographic sector "MK77" is simply done by calling the URI: <code>[insert_php] echo $opts['ecapi_url']; [/insert_php]sector/MK77</code>

where:

<ul>
<ul>
<li><code>sector</code> here is the type of the entity. The <a href="https://datahub.beta.mksmart.org/entity-lookup/">Entity Lookup</a> service lists the types that are covered by the API, and the <a href="https://datahub.beta.mksmart.org/data-catalogue/">data catalogue</a> provides links to the types datasets provide. It might be <code>postcode</code>, <code>place</code> or <code>topic</code> for example.</li>
<li><code>MK77</code> here is the identifier of the entity to be retrieved. The format of the identifier is dependent on the type. A <code>postcode</code> for example might rather be <code>MK76AA</code>, a <code>place</code> or a <code>topic</code> are identified by their name (e.g. <code>walton_hall</code>, <code>computer</code>), while a <code>geo-point</code> is identified by its coordinate (e.g. <code>52.03333_-0.7</code>).</li>
</ul>
<li><code>sector</code> here is the type of the entity. The <a href="https://datahub.beta.mksmart.org/entity-lookup/">Entity Lookup</a> service lists the types that are covered by the API, and the <a href="https://datahub.beta.mksmart.org/data-catalogue/">data catalogue</a> provides links to the types datasets provide. It might be <code>postcode</code>, <code>place</code> or <code>topic</code> for example.</li>
</ul>
</ul>
<li><code>MK77</code> here is the identifier of the entity to be retrieved. The format of the identifier is dependent on the type. A <code>postcode</code> for example might rather be <code>MK76AA</code>, a <code>place</code> or a <code>topic</code> are identified by their name (e.g. <code>walton_hall</code>, <code>computer</code>), while a <code>geo-point</code> is identified by its coordinate (e.g. <code>52.03333_-0.7</code>).</li>
</section>
<section>
<!-- <h2>REST API specification</h2> -->
<div class="swagger-section">
<p>The following interactive API specification allows you to try out calls to the MK:Smart entity API right before you add them to your development environment. Click on the list items below to see the supported operations and parameters. <a href="http://swagger.io" target="_blank">Powered by Swagger</a>.</p>
<div id="swagger-ui-container" class="swagger-ui-wrap" style="display:inline"></div>
</div>
&nbsp;
<section><!--
<h2>REST API specification</h2>
-->

<div class="swagger-section">
The following interactive API specification allows you to try out calls to the MK:Smart entity API right before you add them to your development environment. Click on the list items below to see the supported operations and parameters. <a href="http://swagger.io" target="_blank">Powered by Swagger</a>.

&nbsp;

<div id="swagger-ui-container" class="swagger-ui-wrap" style="display: inline;"></div>
</div>

&nbsp;
</section>
&nbsp;
<section>
<h2>Response format</h2>
<p>All the services return bespoke, simple JSON, aggregating information from multiple sources.
The result of calls such as the ones of the examples above will return a simple JSON object with attributes coming from the original sources. </p>
<pre lang="json">
{

<h2>Response format</h2>

All the services return bespoke, simple JSON, aggregating information from multiple sources. The result of calls such as the ones of the examples above will return a simple JSON object with attributes coming from the original sources.

&nbsp;

<pre lang="json"> {
property1: [
{
"sub-property1": ["value1", "value2", ...],
"sub-property2": ["value3", "value4", ...].
...
},
...
...
],
property2: [...
}</pre>
</section>

<script type="text/javascript">
<script type="text/javascript">// <![CDATA[
(function($){$(function(){var url='[insert_php]
$opts = get_option('ecapi_options');
echo $opts['ecapi_swagger'];
[/insert_php]';window.swaggerUi=new SwaggerUi({url:url,dom_id:"swagger-ui-container",supportedSubmitMethods:['get','post','put','delete'],onComplete:function(swaggerApi,swaggerUi){if(typeof initOAuth=="function"){}
$('pre code').each(function(i,e){hljs.highlightBlock(e)});},onFailure:function(data){log("Unable to Load SwaggerUI");},docExpansion:"list",sorter:"alpha"});window.swaggerUi.load();});})(window.jQuery);
</script>
$('pre code').each(function(i,e){hljs.highlightBlock(e)})},onFailure:function(data){console.log(data)},docExpansion:"list",sorter:"alpha"});window.swaggerUi.load()});
})(window.jQuery);
// ]]></script>
82 changes: 32 additions & 50 deletions plugins/ecapi/ecapi.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
/*
Plugin Name: Data API management
Plugin URI: http://kmi.open.ac.uk/people/member/alessandro-adamou
Version: 0.0.2
Plugin Name: MKS Entity-Centric API Management
Description: Utilities for accessing, testing and configuring an Entity-Centric API from a WordPress installation
Plugin URI: http://github.com/mk-smart/ecapi-wordpress
Version: 0.1.0
Author: Alessandro Adamou
Author URI: http://kmi.open.ac.uk/people/member/alessandro-adamou
*/
Expand Down Expand Up @@ -220,12 +221,12 @@ function ecapi_setting_url() {
*/
function add_scripts(){
$plugdir = dirname(__FILE__) . '/ecapi'; // Stupid Wordpress function plugins_url going bananas
$script_table = array(
$scripts_head = array(
array( 'prism', 'vendor/bower/prism/prism.js', array() )
);
foreach( $script_table as $k => $v )
foreach( $scripts_head as $k => $v )
wp_register_script( $v[0], plugins_url($v[1], $plugdir), $v[2] );
foreach( $script_table as $k => $v )
foreach( $scripts_head as $k => $v )
wp_enqueue_script($v[0]);

wp_register_style('prism', plugins_url('vendor/bower/prism/themes/prism.css', $plugdir), array(), '20120208', 'all');
Expand All @@ -234,54 +235,35 @@ function add_scripts(){

function wptuts_scripts_with_the_lot() {
$plugdir = dirname(__FILE__) . '/ecapi'; // Stupid Wordpress function plugins_url going bananas
$vpa = 'vendor/bower';
$script_table = array(
array( 'jquery-blockui', 'vendor/bower/blockui/jquery.blockUI.js', array('jquery'), FALSE, TRUE ),
array( 'typeahead.js' , 'vendor/bower/typeahead.js/dist/typeahead.bundle.min.js', array('jquery'), FALSE, TRUE ),
array( 'jquery-slideto', 'vendor/bower/swagger-ui/dist/lib/jquery.slideto.min.js', array('jquery'), FALSE, TRUE ),
array( 'jquery-wiggle' , 'vendor/bower/swagger-ui/dist/lib/jquery.wiggle.min.js', array('jquery'), FALSE, TRUE ),
array( 'jquery-slideto', 'vendor/bower/swagger-ui/dist/lib/jquery.slideto.min.js', array('jquery'), FALSE, TRUE ),
array( 'jquery-ba-bbq' , 'vendor/bower/swagger-ui/dist/lib/jquery.ba-bbq.min.js', array('jquery'), FALSE, TRUE ),
// array( 'handlebars' , 'vendor/bower/swagger-ui/dist/lib/handlebars-2.0.0.js', array('jquery'), '2.0.0', TRUE ),
// array( 'marked' , 'vendor/bower/swagger-ui/dist/lib/marked.js', array('jquery'), FALSE, TRUE ),
// array( 'jsoneditor' , 'vendor/bower/swagger-ui/dist/lib/jsoneditor.min.js', array('jquery'), FALSE, TRUE ),
// array( 'swagger-client', 'vendor/bower/swagger-js/browser/swagger-client.min.js', array('jquery'), FALSE, TRUE ),
// array( 'swagger-ui' , 'vendor/bower/swagger-ui/dist/swagger-ui.min.js', array('swagger-client','handlebars','marked','jsoneditor'), FALSE, TRUE ),
array( 'highlight' , 'vendor/bower/swagger-ui/dist/lib/highlight.7.3.pack.js', array('jquery'), '7.3', TRUE ),
);
$bow = 'vendor/bower';

// wp_register_script('shred', plugins_url('vendor/bower/swagger-ui/dist/lib/shred.bundle.js', $plugdir), FALSE);
// wp_deregister_script('jquery'); // Foggin' noConflict crap
// wp_register_script('jquery', plugins_url('vendor/bower/jquery/jquery.min.js', $plugdir), FALSE);
// Underscore and Backbone need to be in the head.
// Underscore and Backbone need to be in the head for Swagger to work
wp_deregister_script('underscore');
wp_register_script('underscore', plugins_url('vendor/bower/swagger-ui/dist/lib/underscore-min.js', $plugdir), FALSE);
wp_deregister_script('backbone');
wp_register_script('backbone', plugins_url('vendor/bower/swagger-ui/dist/lib/backbone-min.js', $plugdir), FALSE);

foreach( $script_table as $k => $v )
wp_register_script( $v[0], plugins_url($v[1], $plugdir), $v[2] );

// wp_enqueue_script('shred');
// wp_enqueue_script('jquery');
wp_enqueue_script('underscore');
wp_enqueue_script('backbone');

foreach( $script_table as $k => $v )
wp_enqueue_script($v[0]);

wp_register_script('handlebars', plugins_url('vendor/bower/swagger-ui/dist/lib/handlebars-2.0.0.js', $plugdir), array('jquery'), FALSE, TRUE);
wp_register_script('marked', plugins_url('vendor/bower/swagger-ui/dist/lib/marked.js', $plugdir), array('jquery'), FALSE, TRUE);
wp_register_script('jsoneditor', plugins_url('vendor/bower/swagger-ui/dist/lib/jsoneditor.min.js', $plugdir), array('jquery'), FALSE, TRUE);

wp_register_script('swagger-client', plugins_url('vendor/bower/swagger-js/browser/swagger-client.min.js', $plugdir), array(), FALSE, TRUE);
wp_register_script('swagger-ui', plugins_url('vendor/bower/swagger-ui/dist/swagger-ui.min.js', $plugdir), array('swagger-client','handlebars','marked','jsoneditor'), FALSE, TRUE);
$scripts_head = array(
array( 'underscore' , "$bow/swagger-ui/dist/lib/underscore-min.js" , array() ),
array( 'backbone' , "$bow/swagger-ui/dist/lib/backbone-min.js" , array() ),
array( 'highlight' , "$bow/swagger-ui/dist/lib/highlight.7.3.pack.js", array() ),
array( 'jquery-blockui', "$bow/blockui/jquery.blockUI.js" , array('jquery') ),
array( 'typeahead.js' , "$bow/typeahead.js/dist/typeahead.bundle.min.js", array('jquery') ),
array( 'jquery-slideto', "$bow/swagger-ui/dist/lib/jquery.slideto.min.js", array('jquery') ),
array( 'jquery-wiggle' , "$bow/swagger-ui/dist/lib/jquery.wiggle.min.js" , array('jquery') ),
array( 'jquery-ba-bbq' , "$bow/swagger-ui/dist/lib/jquery.ba-bbq.min.js" , array('jquery') ),
);
$scripts_foot = array(
array( 'handlebars' , "$bow/swagger-ui/dist/lib/handlebars-2.0.0.js" , array('jquery'), '2.0.0' ),
array( 'marked' , "$bow/swagger-ui/dist/lib/marked.js" , array('jquery'), FALSE ),
array( 'jsoneditor' , "$bow/swagger-ui/dist/lib/jsoneditor.min.js" , array('jquery'), '7.3' ),
array( 'swagger-client', "$bow/swagger-js/browser/swagger-client.min.js", array(), '2.1' ),
array( 'swagger-ui' , "$bow/swagger-ui/dist/swagger-ui.min.js" , array('swagger-client','handlebars','marked','jsoneditor'), '2.1' ),
);

wp_enqueue_script('handlebars');
wp_enqueue_script('marked');
wp_enqueue_script('jsoneditor');
wp_enqueue_script('swagger-client');
wp_enqueue_script('swagger-ui');
foreach( $scripts_head as $k => $v )
wp_register_script( $v[0], plugins_url($v[1], $plugdir), $v[2] );
foreach( $scripts_foot as $k => $v )
wp_register_script( $v[0], plugins_url($v[1], $plugdir), $v[2], $v[3], TRUE );
foreach( $scripts_head as $k => $v ) wp_enqueue_script($v[0]);
foreach( $scripts_foot as $k => $v ) wp_enqueue_script($v[0]);
}

/**
Expand Down
Loading

0 comments on commit 78e5817

Please sign in to comment.