From ee4874bb82ea733535aed6a1100f8ff3fcca349a Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Fri, 11 Apr 2014 13:22:00 -0700 Subject: [PATCH] lil' fixes, and reference to neocities-node --- app.rb | 2 +- views/_header.erb | 3 +++ views/api.erb | 27 +++++++++++++++++++++++---- views/index.erb | 3 +++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app.rb b/app.rb index c0686d1a..43c623c8 100644 --- a/app.rb +++ b/app.rb @@ -565,7 +565,7 @@ post '/api/upload' do files = [] params.each do |k,v| - next unless v[:tempfile] + next unless v.is_a?(Hash) && v[:tempfile] files << {filename: k.to_s, tempfile: v[:tempfile]} end diff --git a/views/_header.erb b/views/_header.erb index 36e60853..72598eaf 100644 --- a/views/_header.erb +++ b/views/_header.erb @@ -16,6 +16,9 @@
  • Tutorials
  • +
  • + API +
  • About
  • diff --git a/views/api.erb b/views/api.erb index 57560660..4d3e3124 100644 --- a/views/api.erb +++ b/views/api.erb @@ -21,8 +21,8 @@

    @@ -41,7 +41,26 @@

    Examples

    -

    Using cURL to upload a single local file (local.html), which will be index.html on the server:

    - $ curl -F index.html=@local.html https://USER:PASS@neocities.org/api/upload +
    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.

    +
    +var NeoCities = require('neocities')
    +
    +var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
    +
    +// Upload a file called local.html from your computer,
    +// which will be named newfile.html on the site.
    +
    +api.uploadFile('newfile.html', './local.html', function(resp) {
    +  if(resp.result == 'error')
    +    throw new Error(resp.error_type+' - '+resp.message)
    +
    +  // Display response from API
    +  console.log(resp)
    +})
    +  
    diff --git a/views/index.erb b/views/index.erb index c25e655e..3efc7933 100644 --- a/views/index.erb +++ b/views/index.erb @@ -66,6 +66,9 @@
  • Tutorials
  • +
  • + API +
  • About