Table of Content

The API

This is the version 1 of the API.

Some introduction

Before getting into the hard definitions, here are some words to help you understand the rest better.

The basic idea is: each Linkode can have several revisions. When you create a linkode, and then you add a change, the linkode will be the same, different revisions. Specifically, you will have two nodes, with the same "linkode id", and different "revision numbers".

Every linkode has a root node. When you "create" a new linkode, you'll receive the revision number of that root. After that basic creation, you will be able to add children to the different nodes, specifying the parent revno in the process.

To create a new linkode

- type: POST
- url: /api/1/linkodes/
- data: 
    content: the content of the linkode (Unicode!)
    text_type: the type of the content (plain text, Python, diff, C, etc.) [optional]
- returns:
    linkode_id: the unique id of the new linkode
    revno: the revision number of its root node
  
>>> import json
>>> from urllib import parse, request
>>> data = {'content': 'The content for your linkode', 'text_type': 'python'}
>>> raw = parse.urlencode(data).encode("ascii")
>>> u = request.urlopen("http://linkode.org/api/1/linkodes/", data=raw)
>>> u.code
201
>>> raw = u.read()
>>> json.loads(raw.decode("utf8"))
{'revno': 'BEpK7XUDWluFuvFOmjdBQ2', 'linkode_id': 'RbWZRBGGV5kmmQFcpyX8i6'}
        
In [1]: import requests
In [2]: data = {'content': u'The content for your linkode', 'text_type': 'python'}
In [3]: r = requests.post("http://linkode.org/api/1/linkodes/", data=data)
In [4]: r.json()
Out[4]:
{u'linkode_id': u'557b9746-af4c-4131-aed3-7bdb2caed0d4',
 u'revno': u'e594500e-00d8-4a20-b2b8-92508099b0a6'}
In [5]: r.status_code
Out[5]: 201
        
$.post(
    'http://linkode.org/api/1/linkodes/',
    {
        'content': 'The content for your linkode',
        'text_type': 'javascript'
    },
    function(data) {
        console.log(data);
});
>> Object { linkode_id="etGrenFvoib6HLY2jnkQr4", revno="JNxQG6PIJyqlrcjHdYtgt3"}
          


To create a child of an existing linkode node

- type: POST
- url: /api/1/linkodes/<linkode_id>
- data: 
    content: the content of the new node (Unicode!)
    parent: the revision number of the node that is parent to this new one
- returns:
    revno: the revision number of the new node
  
>>> from urllib import parse, request
>>> import json
>>> update = {'content': 'new content', 'text_type': 'python', 'parent': 'BEpK7XUDWluFuvFOmjdBQ2'}
>>> raw = parse.urlencode(update).encode("ascii")
>>> u = request.urlopen("http://linkode.org/api/1/linkodes/RbWZRBGGV5kmmQFcpyX8i6", data=raw)
>>> u.code
201
>>> raw = u.read()
>>> json.loads(raw.decode("utf8"))
{'revno': 'QRHIfvoaGdflbI0bAr6zN4'}
        
In [1]: import requests
In [2]: update = {'content': u'new content', 'text_type': 'python', 'parent': '796d0e80-a178-44a3-8226-2046768cf6f7'}
In [3]: r = requests.post("http://linkode.org/api/1/linkodes/a5bdba03-82fd-4e89-a2db-1f4deb68d070", data=update)
In [4]: r.json()
Out[4]:
{u'revno': u'9dca0df5-3291-42a8-a78e-5dba5a516f51'}
In [5]: r.status_code
Out[5]: 201
        
$.post(
    'http://linkode.org/api/1/linkodes/etGrenFvoib6HLY2jnkQr4',
    {
        'content': 'New Content',
        'text_type': 'javascript',
        'parent': 'JNxQG6PIJyqlrcjHdYtgt3'
    },
    function(data) {
        console.log(data);
});
>> Object { revno="dB5VdK2n212ilyOr5tmFq7"}
          


To get a specific linkode node

- type: GET
- url: /api/1/linkodes/<linkode_id>/
- returns:
linkode_id: the unique id of the new linkode
revno: the revision number of its root node
  
>>> from urllib import request
>>> import json
>>> u = request.urlopen("http://linkode.org/api/1/linkodes/RbWZRBGGV5kmmQFcpyX8i6/QRHIfvoaGdflbI0bAr6zN4")
>>> u.code
200
>>> raw = u.read()
>>> json.loads(raw.decode("utf8"))
{'text_type': 'python', 'content': 'new content'}
        
In [1]: import requests
In [2]: r = requests.get("http://linkode.org/api/1/linkodes/a5bdba03-82fd-4e89-a2db-1f4deb68d070/ca8aa7a1-59e8-491c-9025-363f1fd7b908")
In [3]: r.json()
Out[3]:
{u'content': u'The content for this linkode node'}
In [4]: r.status_code
Out[4]: 200
        
$.get(
'http://linkode.org/api/1/linkodes/etGrenFvoib6HLY2jnkQr4/dB5VdK2n212ilyOr5tmFq7',
function(data) {
console.log(data);
}
);
>> Object { content="New Content", text_type="javascript"}
        


To get all the tree of a linkode

- type: GET
- url: /api/1/linkodes/<linkode_id>
  
As we don't know if the "get all the tree of a linkode" is going to be used, it has not been implemented yet, but it will have the API above ;-)