Browse files

* upload: add ability to upload from binary streams or octet sequences.

* create-folder: return folder-id.
  • Loading branch information...
1 parent 95465d2 commit a6130343f722819e69bda920409285034a921cd7 @stassats committed Dec 26, 2010
Showing with 43 additions and 23 deletions.
  1. +36 −20 cl-openbox.lisp
  2. +7 −3 packages.lisp
View
56 cl-openbox.lisp
@@ -70,25 +70,35 @@
(when files
(list :files (parse-files files))))))
-(defun list-files ()
+(defun list-files (&optional (folder-id "0"))
(parse-folders
(action "get_account_tree"
- '("folder_id" . "0")
+ `("folder_id" . ,folder-id)
'("params[]" . "nozip")
'("params[]" . "simple")
'("params[]" . "onelevel"))))
-(defun upload (file &key (folder "0") share)
- (parse-files
- (find-child "files"
- (get-response
- (drakma:http-request
- (format nil "https://upload.box.net/api/1.0/upload/~a/~a"
- *auth-token* folder)
- :method :post
- :content-length t
- :parameters `(("file" ,(pathname file))
- ,@(if share '(("share" . "1")))))))))
+(defun upload (content &key name (folder "0") share)
+ "content may be a file-name, a sequence of octets, a binary input stream."
+ (let* ((content (if (stringp content)
+ (pathname content)
+ content))
+ (name (or name
+ (typecase content
+ (pathname (file-namestring content))
+ (file-stream (pathname content))
+ (t (error "Unable to determine name for ~a"
+ (type-of content)))))))
+ (parse-files
+ (find-child "files"
+ (get-response
+ (drakma:http-request
+ (format nil "https://upload.box.net/api/1.0/upload/~a/~a"
+ *auth-token* folder)
+ :method :post
+ :content-length t
+ :parameters `(("file" ,content :filename ,name)
+ ,@(if share '(("share" . "1"))))))))))
(defun download (file-id save-into)
(let ((file (drakma:http-request
@@ -117,11 +127,17 @@
"folder"
"file"))))
+(defun parse-create-folder (xml)
+ (let ((id (find-child-path xml "folder" "folder_id")))
+ (when id
+ (stp:string-value id))))
+
(defun create-folder (name &key (parent-id "0") share)
- (action "create_folder"
- (cons "name" name)
- (cons "parent_id" parent-id)
- (cons "share"
- (if share
- "1"
- "0"))))
+ (parse-create-folder
+ (action "create_folder"
+ (cons "name" name)
+ (cons "parent_id" parent-id)
+ (cons "share"
+ (if share
+ "1"
+ "0")))))
View
10 packages.lisp
@@ -2,10 +2,14 @@
(defpackage #:cl-openbox
(:use #:cl)
+ (:shadow #:delete)
(:export
#:*api-key*
#:*auth-token*
#:authenticate
- #:list-directories
- #:upload-file
- #:download-file))
+ #:download
+ #:delete
+ #:rename
+ #:list-files
+ #:create-folder
+ #:upload))

0 comments on commit a613034

Please sign in to comment.