Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move licenses API docs to opendefinition.org #206

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion _includes/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
<a href="/od/{{site.od_current_version}}/en/">The Definition</a>
</li>
<li>
<a href="/licenses/">Conformant Licenses</a>
<a>Licenses</a>
<ul>
<li><a href="/licenses/">Conformant Licenses</a></li>
<li><a href="/licenses/process">Approval Process</a></li>
<li><a href="/licenses/api">Licenses API</a></li>
</ul>
</li>
<li>
<a href="/participate/">Participate</a>
Expand Down
18 changes: 18 additions & 0 deletions _sass/_api.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.license-list {
margin-top: 1rem;
clear: both;
}

.license .icons .open-icon {
padding-right: 3px;
}

.license {
min-height:20px;
padding:19px;
margin-bottom:20px;
border:1px solid #e3e3e3;
-webkit-border-radius:4px;
-moz-border-radius:4px;
border-radius:4px;
}
61 changes: 61 additions & 0 deletions assets.okfn.org/js/api-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
jQuery(document).ready(function($) {
var template = $($('.template-license').html());
var $list = $('.license-list');
var $isOpenData = $('<a href="https://opendefinition.org/od/" title="Open Data" class="open-icon"><img src="https://assets.okfn.org/images/ok_buttons/od_80x15_blue.png" alt="Open Data" /></a>');
var $isOpenContent = $('<a href="https://opendefinition.org/od/" title="Open Data" class="open-icon"><img src="https://assets.okfn.org/images/ok_buttons/oc_80x15_red_green.png" alt="Open Data" /></a>');
$.each(all_licenses, function(id, data) {
var tmp = template.clone();
var jsonUrl = 'https://licenses.opendefinition.org/licenses/' + id + '.json';
$.each(data, function(key, value) {
tmp.find('.tmpl-' + key).html(value);
});
tmp.attr('data-license-id', data.id);
tmp.find('.tmpl-title').attr('href', jsonUrl);
tmp.find('.tmpl-url').attr('href', data.url);
if (data.od_conformance === "approved" && data.domain_data) {
tmp.find('.icons').append($isOpenData.clone());
}
if (data.od_conformance === "approved" && data.domain_content) {
tmp.find('.icons').append($isOpenContent.clone());
}
$list.append(tmp);
});

$('.license-filter').change(onFormChange);
$('.license-filter').submit(onFormChange);
$('.license-filter .search-query').keyup(onFormChange);
$('.license-filter').trigger('submit');

function onFormChange(e) {
e.preventDefault();
var $form = $(e.target).closest('form');
var data = {
q: '',
od_conformance: null,
osd_conformance: null
};
$($form.serializeArray()).each(function(idx, item) {
data[item.name] = item.value;
});
$('.license-list .license').each(function(idx, $el) {
$el = $($el);
var matched = false;
var _id = $el.attr('data-license-id');
var _lic = all_licenses[_id];
if (_lic.title.toLowerCase().match(RegExp(data.q))) {
matched = true;
}
if (data.osd_conformance === "approved") {
matched = matched && _lic.osd_conformance === "approved";
}
if (data.od_conformance === "approved") {
matched = matched && _lic.od_conformance === "approved";
}
if (matched) {
$el.show();
} else {
$el.hide();
}
});
}
});
3 changes: 2 additions & 1 deletion css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
'syntax',
'footer',
'body',
'ok-ribbon';
'ok-ribbon',
'api';
117 changes: 117 additions & 0 deletions licenses/api/index.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
layout: page
slug: licenses-api
title: Licenses API
---

<blockquote>
<h2>The <a href="https://opendefinition.org">Open Definition</a> states: &quot;A piece of content or data is open if anyone is free to use, reuse, and redistribute it — subject only, at most, to the requirement to attribute and share-alike.&quot;</h2>
</blockquote>

<h2>Data on more than 100 open licenses</h2>
<p>Including all <a href="https://opensource.org/licenses">OSI-approved open source
licenses</a> and all <a href="https://opendefinition.org/licenses">Open
Definition conformant open data and content licenses</a>. Provided in easy to use, <a href="#format">machine readable JSON</a> -- perfect if you need to drop a license chooser into your app.</p>
<p><a href="#all-licenses" class="btn primary">View the licenses available</a></p>
<h3>License Groups</h3>
<p>In addition various generic groups are provided that are useful when constructing license choice lists, including non-commercial options, generic Public Domain and more. Pre-packaged groups include:</p>
<ul>
<li><a href="https://licenses.opendefinition.org/licenses/groups/all.json">All licenses</a></li>
<li><a href="https://licenses.opendefinition.org/licenses/groups/osi.json">OSI compliant</a></li>
<li><a href="https://licenses.opendefinition.org/licenses/groups/od.json">Open Definition compliant</a></li>
<li><a href="https://licenses.opendefinition.org/licenses/groups/ckan.json">Specially selected set</a> developed for <a href="https://ckan.org/">CKAN</a> that is perfect for data and content site license choosers.</li>
</ul>

<h2 id="format">Format</h2>
<p>JSON hashes with the following keys:</p>
<pre>{
"id": "ODC-BY-1.0",
"domain_content": false,
"domain_data": true,
"domain_software": false,
"od_conformance": "approved",
"osd_conformance": "not reviewed",
"status": "active",
"title": "Open Data Commons Attribution License 1.0",
"url": "https://opendatacommons.org/licenses/by"
}</pre>
<p>Spot an error, think we should have more info? Please file an <a href="https://github.com/okfn/licenses/issues">issue</a> or submit a patch.</p>

<hr />

<h2 id="how-to">How do I use it?</h2>

<h3>Get the data</h3>
<p>Download the licenses, either <a href="https://licenses.opendefinition.org/licenses/groups/all.json">all in one</a>, individually (see below) or in specific groups (see above).</p>
<p>For example, here's how to use curl to access an individual license:</p>
<p><pre>curl https://licenses.opendefinition.org/licenses/ODC-BY-1.0.json</pre></p>

<p>And here's how to use curl to access the CKAN license group:</p>
<p><pre>curl https://licenses.opendefinition.org/licenses/groups/ckan.json</pre></p>

<h3>Git Access</h3>
<p>You can also get the material as a git repo:</p>
<p><pre>git clone https://github.com/okfn/licenses</pre></p>


<h3>Javascript Access (JSONP)</h3>
<p>We also provide a simple way to get direct access from javascript in the browser using JSONP, by providing versions of the all of the data in the jsonp subdirectory wrapped in a callback function named <pre>license_callback</pre></p>
<p>Thus, the JSONP version of a file named:
<p><pre>xyz.json</pre></p>
<p>whether it is a license group or an individual license, will be located at:</p>
<p><pre>licenses/jsonp/xyz.json</pre></p>

<p>For example from jQuery:</p>
<pre>$.ajax({
url:'https://licenses.opendefinition.org/groups/jsonp/ODC-BY-1.0.js',
dataType: 'jsonp',
// you *must* set the callback function to be license_callback
jsonpCallback: 'license_callback',
success: function(data) {
console.log('License title is ' + data.title);
}
});</pre>

<p>Because our JSONP data is served from a static files, it has a hardcoded callback function and therefore <strong>must</strong> name your callback function for the JSONP request <pre>license_callback</pre></p>

<hr />

<h2 id="all-licenses">Licenses List</h2>
<form class="form-horizontal form-search license-filter">
<p><input type="text" name="q" placeholder="Filter" class="search-query span5" /></p>

<label class="checkbox">
<input type="checkbox" name="od_conformance" value="approved" checked="" />
Approved as conforming to the Open Definition
</label>
<br />
<label class="checkbox">
<input type="checkbox" name="osd_conformance" value="approved" />
Approved as conforming to the Open Source Definition
</label>
</form>

<div class="license-list"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script type="text/javascript">
// GLOBAL
var all_licenses = null;
// Setup callback for jsonp to use
function license_callback(data) {
all_licenses = data;
}
</script>
<script src="https://licenses.opendefinition.org/licenses/jsonp/all.js"></script>
<script src="/assets.okfn.org/js/api-docs.js" type="text/javascript"></script>
<script type="x-template" class="template-license">
<div class="license" data-license-id="">
<div class="">
<h3>
<a href="" class="tmpl-title"></a>
<div class="icons"></div>
</h3>
<p><a href="" class="tmpl-url"></a></p>
<p>Status: <span class="tmpl-status"></span></p>
</div>
</div>
</script>