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 @@
Our Developers API allows you to make changes to your site remotely with programming languages!
@@ -16,7 +16,7 @@
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.
- +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 @@
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
-
+
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) })+ +
+ 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! +
+ ++ 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
+