flickr-method-info.ss
#lang scheme
(require "method.ss"
         "flickr-reflection.ss")

(provide (all-defined-out))

;; This is the Scheme API key -- you shouldn't use
;; it for your own applications.
(current-api-key "138427ce2d97d6a2d0c4a2f045a59bfa")

;; [Listof String]
(define all-method-names 
  (match (flickr.reflection.getMethods)
    [(list (list-rest 'methods _ (list (list 'method _ name) ...))) name]))

;; String -> MethodInfo
(define (get-method-info method-name)  
  (match (flickr.reflection.getMethodInfo #:method_name method-name)
    [(list (list-rest 'method (list (list 'name name) 
                                    (list 'needslogin needs-login) 
                                    (list 'needssigning needs-signing) 
                                    (list 'requiredperms required-perms))
                      (list-rest 'description '() description)
                      method-spec)
           (list-rest 'arguments '() argument-specs)
           (list-rest 'errors '() error-specs))       
     (make-method-info 
      name
      (flickr-true? needs-login)
      (flickr-true? needs-signing)
      required-perms ;; ignored for now.
      (apply string-append description)
      (match method-spec 
        [(list-no-order (list-rest 'response '() response) _ ...)            
         (apply string-append response)]
        [_ #f])
      (match method-spec 
        [(list-no-order (list-rest 'explanation '() explan) _ ...)            
         (apply string-append explan)]
        [_ #f])
      
      (map (match-lambda
             [(list-rest 'argument (list (list 'name name) (list 'optional opt)) description)
              (make-argument-info name (flickr-true? opt) (apply string-append description))])
           argument-specs)
      
      (map (match-lambda 
             [(list-rest 'error (list (list 'code code) (list 'message msg)) explan)
              (make-error-info code msg (apply string-append explan))])
           error-specs))]));)

(define all-method-infos
  (delay (map get-method-info all-method-names)))

#;
(append (list "flickr.photos.search"
              "flickr.test.echo"
              "flickr.reflection.getMethods"
              "flickr.groups.members.getList")
        (take all-method-names 10))