/api/delete

This commit is contained in:
Kyle Drake 2014-04-11 14:17:27 -07:00
parent 2c2ef2d015
commit 7cd7973144
2 changed files with 29 additions and 8 deletions

View file

@ -23,7 +23,7 @@ describe 'api delete' do
post '/api/delete', filenames: ['hi.html'] post '/api/delete', filenames: ['hi.html']
res[:error_type].must_equal 'invalid_auth' res[:error_type].must_equal 'invalid_auth'
end end
it 'fails with missing filename argument' do it 'fails with missing filename argument' do
create_site create_site
basic_authorize @user, @pass 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') @site.store_file 't$st.jpg', Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
post '/api/delete', filenames: ['t$st.jpg'] post '/api/delete', filenames: ['t$st.jpg']
res[:error_type].must_equal 'bad_filename' 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 end
it 'fails with missing files' do it 'fails with missing files' do
@ -67,7 +72,6 @@ describe 'api delete' do
end end
describe 'api upload' do describe 'api upload' do
it 'fails with no auth' do it 'fails with no auth' do
post '/api/upload' post '/api/upload'
res[:result].must_equal 'error' res[:result].must_equal 'error'
@ -115,7 +119,7 @@ describe 'api upload' do
res[:result].must_equal 'success' res[:result].must_equal 'success'
site_file_exists?('test.jpg').must_equal true site_file_exists?('test.jpg').must_equal true
end end
it 'succeeds with two files' do it 'succeeds with two files' do
create_site create_site
basic_authorize @user, @pass basic_authorize @user, @pass

View file

@ -3,7 +3,7 @@
<h2 class="alpha">NeoCities Developers API</h2> <h2 class="alpha">NeoCities Developers API</h2>
<p><img src="/assets/img/cat-larger.png"></p> <p><img src="/assets/img/cat-larger.png"></p>
<p> <p>
<strong>Our Developers API allows you to make changes to your site remotely with programming languages!</strong> <strong>Our Developers API allows you to make changes to your site remotely with programming languages!</strong>
</p> </p>
@ -16,7 +16,7 @@
<li>Conduct regular backups of your site.</li> <li>Conduct regular backups of your site.</li>
</ul> </ul>
</p> </p>
<h3>Rules</h3> <h3>Rules</h3>
<p> <p>
<ul> <ul>
@ -26,7 +26,7 @@
<li>Do not use the API to data mine / rip all of the sites.</li> <li>Do not use the API to data mine / rip all of the sites.</li>
</ul> </ul>
</p> </p>
<h2>API Documentation</h2> <h2>API Documentation</h2>
<p> <p>
The NeoCities API is a <a href="http://en.wikipedia.org/wiki/Representational_state_transfer" target="_blank">REST</a> API, which uses query parameters for input, and returns data in the <a href="http://en.wikipedia.org/wiki/JSON" target="_blank">JSON</a> format (except for file downloads). It uses client-side <a href="http://en.wikipedia.org/wiki/Basic_access_authentication" target="_blank">HTTP AUTH</a> 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 <strong>cURL</strong> (a command-line tool for making HTTP requests you can use by opening a terminal on your computer). The NeoCities API is a <a href="http://en.wikipedia.org/wiki/Representational_state_transfer" target="_blank">REST</a> API, which uses query parameters for input, and returns data in the <a href="http://en.wikipedia.org/wiki/JSON" target="_blank">JSON</a> format (except for file downloads). It uses client-side <a href="http://en.wikipedia.org/wiki/Basic_access_authentication" target="_blank">HTTP AUTH</a> 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 <strong>cURL</strong> (a command-line tool for making HTTP requests you can use by opening a terminal on your computer).
@ -34,7 +34,7 @@
<p> <p>
<strong>That's a lot of buzz words if you're new to programming.</strong> Don't worry, it's easier than it sounds! We'll walk you through some working examples you can get started with. <strong>That's a lot of buzz words if you're new to programming.</strong> Don't worry, it's easier than it sounds! We'll walk you through some working examples you can get started with.
</p> </p>
<h3>POST /api/upload</h3> <h3>POST /api/upload</h3>
<p> <p>
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<strong>.html</strong>). 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<strong>.html</strong>).
@ -44,7 +44,7 @@
<h6>Using cURL</h6> <h6>Using cURL</h6>
<p>Upload a single local file (<strong>local.html</strong>), which will be named <strong>hello.html</strong> on your site:</p> <p>Upload a single local file (<strong>local.html</strong>), which will be named <strong>hello.html</strong> on your site:</p>
<code>$ curl -F hello.html=@local.html https://USER:PASS@neocities.org/api/upload</code> <code>$ curl -F hello.html=@local.html https://USER:PASS@neocities.org/api/upload</code>
<h6>Using Node.js / Web Browser</h6> <h6>Using Node.js / Web Browser</h6>
<p>This example uses the <a href="https://github.com/neocities/neocities-node" target="_blank">neocities</a> module, which works for node.js and web browsers (via <a href="http://browserify.org" target="_blank">browserify</a>). You can install it by running <strong>npm install neocities --global</strong> in your terminal.</p> <p>This example uses the <a href="https://github.com/neocities/neocities-node" target="_blank">neocities</a> module, which works for node.js and web browsers (via <a href="http://browserify.org" target="_blank">browserify</a>). You can install it by running <strong>npm install neocities --global</strong> in your terminal.</p>
<pre> <pre>
@ -63,4 +63,21 @@ api.uploadFile('newfile.html', './local.html', function(resp) {
console.log(resp) console.log(resp)
}) })
</pre> </pre>
<h3>POST /api/delete</h3>
<p>
Deletes files from your site. Provide a <strong>filenames</strong> argument with an array of filenames you wish to delete. You can delete any files except index.html.
</p>
<p>
<strong>Be careful with this API call.</strong> There is no way to undo a delete!
</p>
<h4>Examples</h4>
<h6>Using cURL</h6>
<p>
Delete <strong>img1.jpg</strong> and <strong>img2.jpg</strong> from your site:
</p>
<code>
curl -d "filenames[]=img1.jpg" -d "filenames[]=img2.jpg" \<br> https://YOURUSER:YOURPASS@neocities.org/api/delete
</code>
</div> <!-- end .content --> </div> <!-- end .content -->