Wiki

Clone wiki

code.skobkin.ru / api

API v0.2

Пояснение

В [квадратных скобках] указываются необязательные параметры.

В (круглных скобках) - обязательные.

Список языков

GET-запрос:

/api/langlist/[%format%]

%format% - формат ответа

plain-file-title

text;Plaintext
actionscript;Actionscript
actionscript3;ActionScript3
apache;Apache
apt_sources;Apt sources.list
asm;x86 Assembler

plain-id-title

0;Plaintext
7;Actionscript
8;ActionScript3
11;Apache
13;Apt sources.list
14;x86 Assembler

plain-all

0;text;Plaintext
7;actionscript;Actionscript
8;actionscript3;ActionScript3
11;apache;Apache
13;apt_sources;Apt sources.list
14;asm;x86 Assembler

json

{"langs":[{"id":"0","name":"Plaintext","file":"text"},{"id":"7","name":"Actionscript","file":"actionscript"},{"id":"8","name":"ActionScript3","file":"actionscript3"},{"id":"11","name":"Apache","file":"apache"},{"id":"13","name":"Apt sources.list","file":"apt_sources"},{"id":"14","name":"x86 Assembler","file":"asm"}]}

xml

<?xml version="1.0"?>
<langs><lang id="0" name="Plaintext" file="text"/><lang id="7" name="Actionscript" file="actionscript"/><lang id="8" name="ActionScript3" file="actionscript3"/><lang id="11" name="Apache" file="apache"/><lang id="13" name="Apt sources.list" file="apt_sources"/><lang id="14" name="x86 Assembler" file="asm"/></langs>

Добавление копипасты

GET-запрос:

/api/add/(%format%)/[%lang_mode%]/

%lang_mode% - режим задания языка

id

Выбор языка по id. Установлен по умолчанию, если параметр не указан. Допустимые значения id языков можно получить, обратившись к методу /langlist/ с форматами "plain-id-title" или "plain-all".

file

Выбор языка по имени файла. Допустимые значения имён файлов языков можно получить, обратившись к методу /langlist/ с форматами "plain-file-title" или "plain-all".

%format% - формат запроса на добавление

plain

В POST-запросе могут быть переданы следующие переменные:

code - текст копипасты.

comment - комментарий к коду.

lang - id или имя файла языка, в соответствии с которым нужно подсвечивать код. Если переменная не задана, подсветка кода будет выключена.

filename - имя файла для копипасты.

author - автор копипасты.

expire - время в секундах, через которое копипаста будет признана устаревшей и будет удалена. Если переменная не установлена, копипаста хранится без ограничений по времени.

private - статус приватности копипасты. При любом установленном значении для просмотра копипасты будет сгенерирован ключ, который должен будет присутствовать в ссылке для просмотра копипасты. Если переменная не установлена, копипаста будет публичной и будет видна в списке последних копипаст.

Ответ

В ответ на запрос вернется ссылка на копипасту:

Публичная копипаста

http://cp.skobkin.ru/687

Приватная копипаста

http://cp.skobkin.ru/723/c2a13e61e1c85e61

json

xml

Получение копипасты

GET-запрос:

/api/get/(%format%)/(%id%)/[%secret%]

%id% - идентификатор копипасты

%secret% - ключ доступа к приватной копипасте

%format% - формат вывода:

html

test &quot;&amp;&quot;;
<br />test &quot;&gt;&quot;;

html-colored

<pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">on</span>
<span style="color: #00007f;">RewriteCond</span> $1 !^(index\.php|css|img|\.js|robots\.txt)
<span style="color: #00007f;">RewriteRule</span> ^(.*)$ /index.php/$1 [L]</pre>

html-colored-num

<pre class="apache" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">on</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #00007f;">RewriteCond</span> $1 !^(index\.php|css|img|\.js|robots\.txt)</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #00007f;">RewriteRule</span> ^(.*)$ /index.php/$1 [L]</div></li></ol></pre>

plain

test "&";
test ">";

json

{"paste":{"id":"549","code":"test \"&\";\r\ntest \">\";","comment":"test paste","filename":"test.txt","author":"skobkin","lang":{"id":"0","name":"Plaintext","file":"text"},"date":{"pub":"2012-10-31 09:47:20","exp":"0000-00-00 00:00:00"}}}

xml

<?xml version="1.0"?>
<pastes><paste id="549"><code>test "&";&#xD;
test "&gt;";</code><comment>test paste</comment><filename>test.txt</filename><author>skobkin</author><lang id="0" name="Plaintext" file="text"/><date pub="2012-10-31 09:47:20" exp="0000-00-00 00:00:00"/></paste></pastes>

Updated