From 48ec9741955f32fb0e2eed17b474733dd6bcbe6e Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Sat, 12 Apr 2014 02:41:47 -0700 Subject: [PATCH] update API with better examples, complete node.js versions --- views/api.erb | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/views/api.erb b/views/api.erb index fcd482f4..96d3d110 100644 --- a/views/api.erb +++ b/views/api.erb @@ -45,27 +45,17 @@

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.

+
Using Node.js
+

This example uses the neocities module. You can install it by running npm install neocities --global in your terminal.

 var NeoCities = require('neocities')
-
 var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
 
-api.uploadFiles([{
-  name: 'newfileonsite.html'
-  path: './local.html'
-}], function(resp) {
-  if(resp.result == 'error')
-    throw new Error(resp.error_type+' - '+resp.message)
-
-  // Display response from API
+api.upload([
+  {name: 'hello.html', path: './local.html'}
+], function(resp) {
   console.log(resp)
 })
- -

- -

POST /api/delete

@@ -84,6 +74,14 @@ api.uploadFiles([{ curl -d "filenames[]=img1.jpg" -d "filenames[]=img2.jpg" \
https://YOURUSER:YOURPASS@neocities.org/api/delete +

Using Node.js
+
+var NeoCities = require('neocities')
+var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
+
+api.delete(['img1.jpg', 'img2.jpg'], function(resp) {
+  console.log(resp)
+})

GET /api/info

This call lets you retreive information about a web site. This call does not require site authorization if you provide a sitename argument. Note that the sitename is the same as a username. If you provide auth credentials, you will receive the info for the auth user's site. Dates conform to RFC2822 format, and there are helpers for parsing it into a time object for most programming languages. @@ -103,8 +101,28 @@ $ curl https://neocities.org/api/info?sitename=youpi "tags": [] } } - +

Getting your own site's info:

$ curl https://YOURUSER:YOURPASS@neocities.org/api/info +
Using Node.js
+

Your site:

+
+var NeoCities = require('neocities')
+var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
+
+api.info(function(resp) {
+  console.log(resp)
+})
+ +

+ Getting data for a different site - such as the Madam FRP Manual: +

+
+var NeoCities = require('neocities')
+var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
+
+api.info('madamfrp', function(resp) {
+  console.log(resp)
+})