From d162fb128460c2b5c6ec10107390ea29caa6b829 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Apr 2012 08:42:40 +0200 Subject: [PATCH 1/6] +api --- htdocs/application/controllers/api.php | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 htdocs/application/controllers/api.php diff --git a/htdocs/application/controllers/api.php b/htdocs/application/controllers/api.php new file mode 100755 index 0000000..3e181ee --- /dev/null +++ b/htdocs/application/controllers/api.php @@ -0,0 +1,33 @@ +load->model('pastes'); + + if (!$this->input->post('text')) + { + echo 'missing paste text'; + } + else + { + echo $this->pastes->createPaste(); + } + } +} From 2e82df600a59b17a3f5436b5f10fb7dce2976ca6 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Apr 2012 09:27:03 +0200 Subject: [PATCH 2/6] api with json return --- htdocs/application/controllers/api.php | 17 +++++++++++++++-- htdocs/application/views/view/api.php | 3 +++ htdocs/application/views/view/raw.php | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100755 htdocs/application/views/view/api.php diff --git a/htdocs/application/controllers/api.php b/htdocs/application/controllers/api.php index 3e181ee..87435d3 100755 --- a/htdocs/application/controllers/api.php +++ b/htdocs/application/controllers/api.php @@ -23,11 +23,24 @@ class Api extends Main if (!$this->input->post('text')) { - echo 'missing paste text'; + $data['data'] = array( + 'error' => 'missing paste text', + ); + $this->load->view('view/api', $data); } else { - echo $this->pastes->createPaste(); + + if (!$this->input->post('lang')) + { + $_POST['lang'] = 'text'; + } + $_POST['code'] = $this->input->post('text'); + $paste_url = $this->pastes->createPaste(); + $data['data'] = array( + 'url' => base_url() . $paste_url, + ); + $this->load->view('view/api', $data); } } } diff --git a/htdocs/application/views/view/api.php b/htdocs/application/views/view/api.php new file mode 100755 index 0000000..07689db --- /dev/null +++ b/htdocs/application/views/view/api.php @@ -0,0 +1,3 @@ + Date: Thu, 19 Apr 2012 09:55:03 +0200 Subject: [PATCH 3/6] todo: api doc --- htdocs/application/controllers/api.php | 6 ++++++ htdocs/application/views/api_help.php | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100755 htdocs/application/views/api_help.php diff --git a/htdocs/application/controllers/api.php b/htdocs/application/controllers/api.php index 87435d3..19adbd8 100755 --- a/htdocs/application/controllers/api.php +++ b/htdocs/application/controllers/api.php @@ -3,6 +3,7 @@ * Class and Function List: * Function list: * - __construct() + * - index() * - create() * Classes list: * - Api extends Main @@ -17,6 +18,11 @@ class Api extends Main parent::__construct(); } + function index() + { + $this->load->view('api_help'); + } + function create() { $this->load->model('pastes'); diff --git a/htdocs/application/views/api_help.php b/htdocs/application/views/api_help.php new file mode 100755 index 0000000..1198d56 --- /dev/null +++ b/htdocs/application/views/api_help.php @@ -0,0 +1,8 @@ +load->view("defaults/header");?> + +
+

API

+ Todo. +
+ +load->view("defaults/footer");?> From 5bd2af53823b2bc6b594c5f8c52cd1031efdf25a Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Apr 2012 11:02:07 +0200 Subject: [PATCH 4/6] api docs --- htdocs/application/views/api_help.php | 36 ++++++++++++++++++-- htdocs/application/views/defaults/header.php | 1 + 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/htdocs/application/views/api_help.php b/htdocs/application/views/api_help.php index 1198d56..78fe038 100755 --- a/htdocs/application/views/api_help.php +++ b/htdocs/application/views/api_help.php @@ -1,8 +1,40 @@ load->view("defaults/header");?> -
+

API

- Todo. +

Create pastes from the commandline

+ +

API URL

+

+ +

POST parameters

+ + text=[your paste text] +

The paste content. Required.

+ + name=[name] +

The author's name.

+ + private=1 +

Make paste private.

+ +

Return values

+

+ On success, the API returns the paste URL in JSON format: {"url":""}
+ On error, the API returns the error message in JSON format: {"error":"missing paste text"} +

+ +

Examples

+

 

+ +

Create paste

+ curl -d text='this is my text' +

Create a paste with the text 'this is my text'.

+ +

Create paste from a file

+ curl -d private=1 -d name=Herbert --data-urlencode text@/etc/passwd +

Create a private paste with the author 'Herbert' and the contents of '/etc/passwd'.

+
load->view("defaults/footer");?> diff --git a/htdocs/application/views/defaults/header.php b/htdocs/application/views/defaults/header.php index 38ffb3e..015d5bd 100755 --- a/htdocs/application/views/defaults/header.php +++ b/htdocs/application/views/defaults/header.php @@ -35,6 +35,7 @@ $this->carabiner->display('css'); uri->segment(1)?>
  • href="" title="Create A New Paste">Create
  • uri->segment(2) != "options"){ echo 'class="active"'; }?> href="" title="Recent Pastes">Recent
  • +
  • href="" title="API">API
  • href="" title="About">About
  • From 04db74191ead8d2d0f84c37f92238b979676fde4 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Apr 2012 11:13:58 +0200 Subject: [PATCH 5/6] docs --- htdocs/application/controllers/api.php | 6 +++++- htdocs/application/views/api_help.php | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/htdocs/application/controllers/api.php b/htdocs/application/controllers/api.php index 19adbd8..3ecee9a 100755 --- a/htdocs/application/controllers/api.php +++ b/htdocs/application/controllers/api.php @@ -20,7 +20,11 @@ class Api extends Main function index() { - $this->load->view('api_help'); + $languages = $this->languages->get_languages(); + $languages = array_keys($languages); + $languages = implode(', ', $languages); + $data['languages'] = $languages; + $this->load->view('api_help', $data); } function create() diff --git a/htdocs/application/views/api_help.php b/htdocs/application/views/api_help.php index 78fe038..9cd5274 100755 --- a/htdocs/application/views/api_help.php +++ b/htdocs/application/views/api_help.php @@ -7,7 +7,14 @@

    API URL

    +

    Return values

    +

    + On success, the API returns the paste URL in JSON format: {"url":""}
    + On error, the API returns the error message in JSON format: {"error":"missing paste text"} +

    +

    POST parameters

    +

     

    text=[your paste text]

    The paste content. Required.

    @@ -18,10 +25,10 @@ private=1

    Make paste private.

    -

    Return values

    + lang=[language]

    - On success, the API returns the paste URL in JSON format: {"url":""}
    - On error, the API returns the error message in JSON format: {"error":"missing paste text"} + Use alternative syntax highlighting.
    + Possible values:

    Examples

    @@ -35,6 +42,10 @@ curl -d private=1 -d name=Herbert --data-urlencode text@/etc/passwd

    Create a private paste with the author 'Herbert' and the contents of '/etc/passwd'.

    +

    Create paste from a php file

    + curl -d lang=php --data-urlencode text@main.php +

    Create a paste with PHP syntax highlighting.

    + load->view("defaults/footer");?> From e164f69b01fe5ed79e14d1576928338c118040f7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Apr 2012 11:41:01 +0200 Subject: [PATCH 6/6] api docs --- htdocs/application/views/api_help.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/htdocs/application/views/api_help.php b/htdocs/application/views/api_help.php index 9cd5274..8a6c33c 100755 --- a/htdocs/application/views/api_help.php +++ b/htdocs/application/views/api_help.php @@ -9,7 +9,7 @@

    Return values

    - On success, the API returns the paste URL in JSON format: {"url":""}
    + On success, the API returns the paste URL in JSON format: {"url":""}
    On error, the API returns the error message in JSON format: {"error":"missing paste text"}

    @@ -31,6 +31,12 @@ Possible values:

    + expire=[minutes] +

    Set paste expiration.

    + + reply=[pasteid] +

    Reply to existing paste.

    +

    Examples

     

    @@ -46,6 +52,10 @@ curl -d lang=php --data-urlencode text@main.php

    Create a paste with PHP syntax highlighting.

    +

    Get paste ;-)

    + curl +

    Display paste.

    + load->view("defaults/footer");?>