From 7cd79731444b5753105748c7dfe8d58a8bfdc23c Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Fri, 11 Apr 2014 14:17:27 -0700 Subject: [PATCH] /api/delete --- tests/api_tests.rb | 10 +++++++--- views/api.erb | 27 ++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/tests/api_tests.rb b/tests/api_tests.rb index 696500df..d6b5e04f 100644 --- a/tests/api_tests.rb +++ b/tests/api_tests.rb @@ -23,7 +23,7 @@ describe 'api delete' do post '/api/delete', filenames: ['hi.html'] res[:error_type].must_equal 'invalid_auth' end - + it 'fails with missing filename argument' do create_site basic_authorize @user, @pass @@ -44,6 +44,11 @@ describe 'api delete' do @site.store_file 't$st.jpg', Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') post '/api/delete', filenames: ['t$st.jpg'] res[:error_type].must_equal 'bad_filename' + + create_site + basic_authorize @user, @pass + post '/api/delete', filenames: ['./config.yml'] + res[:error_type].must_equal 'bad_filename' end it 'fails with missing files' do @@ -67,7 +72,6 @@ describe 'api delete' do end describe 'api upload' do - it 'fails with no auth' do post '/api/upload' res[:result].must_equal 'error' @@ -115,7 +119,7 @@ describe 'api upload' do res[:result].must_equal 'success' site_file_exists?('test.jpg').must_equal true end - + it 'succeeds with two files' do create_site basic_authorize @user, @pass diff --git a/views/api.erb b/views/api.erb index 4d3e3124..4794ba21 100644 --- a/views/api.erb +++ b/views/api.erb @@ -3,7 +3,7 @@

NeoCities Developers API

- +

Our Developers API allows you to make changes to your site remotely with programming languages!

@@ -16,7 +16,7 @@
  • Conduct regular backups of your site.
  • - +

    Rules

    - +

    API Documentation

    The NeoCities API is a REST API, which uses query parameters for input, and returns data in the JSON format (except for file downloads). It uses client-side HTTP AUTH to authenticate, using your user/site name and password as the credentials. It is designed to play nicely with the most common HTTP libraries available in programming languages, and can be easily used with cURL (a command-line tool for making HTTP requests you can use by opening a terminal on your computer). @@ -34,7 +34,7 @@

    That's a lot of buzz words if you're new to programming. Don't worry, it's easier than it sounds! We'll walk you through some working examples you can get started with.

    - +

    POST /api/upload

    Uploads files to your site. You can upload as many files as you want with a single query, as long as the entire request stays within the disk space limit. The parameter name should be the name of the file, with the extension so we know what kind of file it is (index.html). @@ -44,7 +44,7 @@

    Using cURL

    Upload a single local file (local.html), which will be named hello.html on your site:

    $ curl -F hello.html=@local.html https://USER:PASS@neocities.org/api/upload - +
    Using Node.js / Web Browser

    This example uses the neocities module, which works for node.js and web browsers (via browserify). You can install it by running npm install neocities --global in your terminal.

    @@ -63,4 +63,21 @@ api.uploadFile('newfile.html', './local.html', function(resp) {
       console.log(resp)
     })
       
    + +

    POST /api/delete

    +

    + Deletes files from your site. Provide a filenames argument with an array of filenames you wish to delete. You can delete any files except index.html. +

    +

    + Be careful with this API call. There is no way to undo a delete! +

    + +

    Examples

    +
    Using cURL
    +

    + Delete img1.jpg and img2.jpg from your site: +

    + + curl -d "filenames[]=img1.jpg" -d "filenames[]=img2.jpg" \
    https://YOURUSER:YOURPASS@neocities.org/api/delete +