Changeset 57 for lang/elisp/wassr-mode

Show
Ignore:
Timestamp:
07/21/08 03:12:25 (16 years ago)
Author:
tsuyoshi
Message:

fix normal get proces.

Location:
lang/elisp/wassr-mode/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/elisp/wassr-mode/trunk/ChangeLog

    r55 r57  
     12008-07-21  Tsuyoshi CHO  <Tsuyoshi.CHO+develop@Gmail.com> 
     2 
     3        * wassr-mode.el: コメント欄整理(一応) 
     4        (wassr-api-server): 新規定数 
     5        (wassr-http-get, wassr-http-post): 定数を利用するように調整、多い 
     6        改行削除、Connection: Keep-Aliveを追加 
     7        (wassr-status-format): 新フォーマット用に調整(未完) 
     8        (wassr-format-status): 同上 
     9        (wassr-status-to-status-datum): 同上 
     10        (wassr-get-status-url): URL文字列を調整 
     11 
    1122008-07-09  Tsuyoshi CHO  <Tsuyoshi.CHO+develop@Gmail.com> 
    213 
  • lang/elisp/wassr-mode/trunk/wassr-mode.el

    r54 r57  
    33;; Copyright (C) 2008 Tsuyoshi CHO 
    44 
    5 ;; Author: Y. Hayamizu <y.hayamizu@gmail.com> 
    6 ;;         Tsuyoshi CHO <Tsuyoshi.CHO+develop@Gmail.com> 
     5;; Author: Tsuyoshi CHO <Tsuyoshi.CHO+develop@Gmail.com> 
    76;; Created: Sep 4, 2007 
    87;; Version: 0.4 
    98;; Keywords: wassr web 
    10 ;; URL:  
     9;; URL: http://lambdarepos.svnrepository.com/svn/share/lang/elisp/wassr-mode/trunk 
    1110 
    1211;; This file is free software; you can redistribute it and/or modify 
     
    3837(require 'parse-time) 
    3938 
    40 (defconst wassr-mode-version "0.1") 
     39(defconst wassr-mode-version "0.2") 
    4140 
    4241(defun wassr-mode-version () 
     
    6867 
    6968(defvar wassr-status-format nil) 
    70 (setq wassr-status-format "%i %s,  %@:\n  %t // from %f%L") 
     69(setq wassr-status-format "%i %s,  %@:\n  %t // from %A") 
    7170;; %s - screen_name 
    72 ;; %S - name 
     71;; %S - user_login_id 
    7372;; %i - profile_image 
    74 ;; %d - description 
    75 ;; %l - location 
    76 ;; %L - " [location]" 
    77 ;; %u - url 
    78 ;; %j - user.id 
    79 ;; %p - protected? 
    80 ;; %c - created_at (raw UTC string) 
    81 ;; %C{time-format-str} - created_at (formatted with time-format-str) 
     73;; %a - areacode 
     74;; %A - areaname 
     75;; %u - link 
     76;; %p - photo-thumbnail-url 
     77;; %P - photo-url 
     78;; %x - protected? 
     79;; %c - epoch 
     80;; %C{time-format-str} - epoch (formatted with time-format-str) 
    8281;; %@ - X seconds ago 
    8382;; %t - text 
    84 ;; %' - truncated 
    85 ;; %f - source 
     83;; %T - html 
    8684;; %# - id 
    8785 
    8886(defvar wassr-buffer "*wassr*") 
     87(defconst wassr-api-server "api.wassr.jp") 
    8988(defun wassr-buffer () 
    9089  (wassr-get-or-generate-buffer wassr-buffer)) 
     
    334333                             (int-to-string wassr-proxy-port) 
    335334                           wassr-proxy-port)) 
    336             (setq server "api.wassr.jp" 
     335            (setq server wassr-api-server 
    337336                  port "80")) 
    338337          (setq proc 
     
    346345                 request) 
    347346             (setq request 
    348                    (concat "GET http://api.wassr.jp/" method-class "/" method ".xml HTTP/1.1" nl 
    349                            "Host: api.wassr.jp" nl 
     347                   (concat "GET http://" wassr-api-server "/" method-class "/" method ".xml HTTP/1.1" nl 
     348                           "Host: " wassr-api-server nl 
    350349                           "User-Agent: " (wassr-user-agent) nl 
    351350                           "Authorization: Basic " 
     
    360359                           ",image/png,*/*;q=0.5" nl 
    361360                           "Accept-Charset: utf-8;q=0.7,*;q=0.7" nl 
     361                           "Connection: Keep-Alive" nl 
    362362                           (when wassr-proxy-use 
    363363                             "Proxy-Connection: Keep-Alive" nl 
     
    369369                                         proxy-password)) 
    370370                                nl))) 
    371                            nl nl)) 
     371                           nl)) 
    372372             (debug-print (concat "GET Request\n" request)) 
    373373             request))) 
     
    458458           (list-push (attr 'user-screen-name) result)) 
    459459          ((?S)                         ; %S - name 
    460            (list-push (attr 'user-name) result)) 
     460           (list-push (attr 'user-login-id) result)) 
    461461          ((?i)                         ; %i - profile_image 
    462462           (list-push (profile-image) result)) 
    463           ((?d)                         ; %d - description 
    464            (list-push (attr 'user-description) result)) 
    465           ((?l)                         ; %l - location 
    466            (list-push (attr 'user-location) result)) 
    467           ((?L)                         ; %L - " [location]" 
    468            (let ((location (attr 'user-location))) 
    469              (unless (or (null location) (string= "" location)) 
    470                (list-push (concat " [" location "]") result)) )) 
    471           ((?u)                         ; %u - url 
    472            (list-push (attr 'user-url) result)) 
    473           ((?j)                         ; %j - user.id 
    474            (list-push (format "%d" (attr 'user-id)) result)) 
    475           ((?p)                         ; %p - protected? 
     463          ((?a)                         ; 
     464           (list-push (attr 'areacode) result)) 
     465          ((?A)                         ; 
     466           (list-push (attr 'areaname) result)) 
     467          ((?u)                         ; %u - link 
     468           (list-push (attr 'link) result)) 
     469          ((?p)                         ; %u - link 
     470           (list-push (attr 'photo-thumbnail-url) result)) 
     471          ((?P)                         ; %u - link 
     472           (list-push (attr 'photo-url) result)) 
     473          ((?x)                         ; %p - protected? 
    476474           (let ((protected (attr 'user-protected))) 
    477475             (when (string= "true" protected) 
    478476               (list-push "[x]" result)))) 
    479           ((?c)                     ; %c - created_at (raw UTC string) 
    480            (list-push (attr 'created-at) result)) 
    481           ((?C) ; %C{time-format-str} - created_at (formatted with time-format-str) 
    482            (list-push (wassr-local-strftime 
    483                        (or (match-string-no-properties 2 format-str) "%H:%M:%S") 
    484                        (attr 'created-at)) 
    485                       result)) 
     477          ((?c)                     ; %c - epoch (raw UTC string) 
     478           (list-push (attr 'epoch) result)) 
     479          ((?C) ; %C{time-format-str} - epoch (formatted with time-format-str) 
     480           (list-push (attr 'epoch) result));;FIXME 
    486481          ((?@)                         ; %@ - X seconds ago 
    487            (let ((created-at 
    488                   (apply 
    489                    'encode-time 
    490                    (parse-time-string (attr 'created-at)))) 
    491                  (now (current-time))) 
    492              (let ((secs (+ (* (- (car now) (car created-at)) 65536) 
    493                             (- (cadr now) (cadr created-at)))) 
    494                    time-string url) 
    495                (setq time-string 
    496                      (cond ((< secs 5) "less than 5 seconds ago") 
    497                            ((< secs 10) "less than 10 seconds ago") 
    498                            ((< secs 20) "less than 20 seconds ago") 
    499                            ((< secs 30) "half a minute ago") 
    500                            ((< secs 60) "less than a minute ago") 
    501                            ((< secs 150) "1 minute ago") 
    502                            ((< secs 2400) (format "%d minutes ago" 
    503                                                   (/ (+ secs 30) 60))) 
    504                            ((< secs 5400) "about 1 hour ago") 
    505                            ((< secs 84600) (format "about %d hours ago" 
    506                                                    (/ (+ secs 1800) 3600))) 
    507                            (t (format-time-string "%I:%M %p %B %d, %Y" created-at)))) 
    508                (setq url (wassr-get-status-url (attr 'user-screen-name) (attr 'id))) 
    509                ;; make status url clickable 
    510                (add-text-properties 
    511                 0 (length time-string) 
    512                 `(mouse-face highlight 
    513                              face wassr-uri-face 
    514                              uri ,url) 
    515                 time-string) 
    516                (list-push time-string result)))) 
     482           (list-push (attr 'epoch) result));;FIXME 
    517483          ((?t)                         ; %t - text 
    518484           (list-push                   ;(clickable-text) 
    519485            (attr 'text) 
    520486            result)) 
    521           ((?')                         ; %' - truncated 
    522            (let ((truncated (attr 'truncated))) 
    523              (when (string= "true" truncated) 
    524                (list-push "..." result)))) 
    525           ((?f)                         ; %f - source 
    526            (list-push (attr 'source) result)) 
     487          ((?T)                         ; %T - html 
     488           (list-push                   ;(clickable-text) 
     489            (attr 'html) 
     490            result)) 
    527491          ((?#)                         ; %# - id 
    528            (list-push (format "%d" (attr 'id)) result)) 
     492           (list-push (attr 'id) result)) 
    529493          (t 
    530494           (list-push (char-to-string c) result))) 
     
    540504(defun wassr-http-post 
    541505  (method-class method &optional parameters contents sentinel) 
    542   "Send HTTP POST request to api.wassr.jp 
     506  "Send HTTP POST request to `wassr-api-server' 
    543507 
    544508METHOD-CLASS must be one of Wassr API method classes(statuses, users or direct_messages). 
     
    561525                         (int-to-string wassr-proxy-port) 
    562526                       wassr-proxy-port)) 
    563         (setq server "api.wassr.jp" 
     527        (setq server wassr-api-server 
    564528              port "80")) 
    565529      (setq proc 
     
    573537             request) 
    574538         (setq  request 
    575                 (concat "POST http://api.wassr.jp/" method-class "/" method ".xml?" 
     539                (concat "POST http://" wassr-api-server  "/" method-class "/" method ".xml?" 
    576540                        (if parameters 
    577541                            (mapconcat 
     
    583547                             "&")) 
    584548                        " HTTP/1.1" nl 
    585                         "Host: api.wassr.jp" nl 
     549                        "Host: " wassr-api-server nl 
    586550                        "User-Agent: " (wassr-user-agent) nl 
    587551                        "Authorization: Basic " 
     
    591555                        "Content-Type: text/plain" nl 
    592556                        "Content-Length: 0" nl 
     557                        "Connection: Keep-Alive" nl 
    593558                        (when wassr-proxy-use 
    594559                          "Proxy-Connection: Keep-Alive" nl 
     
    600565                                      proxy-password)) 
    601566                             nl))) 
    602                         nl nl)) 
     567                        nl)) 
    603568         (debug-print (concat "POST Request\n" request)) 
    604569         request))))) 
     
    669634                   (car (cddr (assq item seq))))) 
    670635    (let* ((status-data (cddr status)) 
    671            id text source created-at truncated 
     636           html 
     637           text 
     638           epoch 
     639           rid 
     640           id 
     641           user-login-id ;; user_login_id 
     642           link 
     643           photo-url ;; photo_url 
     644           areacode 
     645           areaname 
     646           photo-thumbnail-url ;; photo_thumbnail_url 
     647           reply-status-url ;; reply_status_url 
     648           reply-user-login-id ;; reply_user_login_id 
     649           reply-message ;; reply_message 
     650           reply-user-nick ;; reply_user_nick 
     651           slurl 
    672652           (user-data (cddr (assq 'user status-data))) 
    673            user-id user-name 
    674            user-screen-name 
    675            user-location 
    676            user-description 
    677            user-profile-image-url 
    678            user-url 
    679            user-protected 
     653           user-protected  ;; protected 
     654           user-profile-image-url ;; profile_image_url 
     655           user-screen-name ;; screen_name 
    680656           regex-index) 
    681657 
    682       (setq id (string-to-number (assq-get 'id status-data))) 
    683658      (setq text (wassr-decode-html-entities 
    684659                  (assq-get 'text status-data))) 
    685       (setq source (wassr-decode-html-entities 
    686                     (assq-get 'source status-data))) 
    687       (setq created-at (assq-get 'created_at status-data)) 
    688       (setq truncated (assq-get 'truncated status-data)) 
    689       (setq user-id (string-to-number (assq-get 'id user-data))) 
    690       (setq user-name (wassr-decode-html-entities 
    691                        (assq-get 'name user-data))) 
     660      (setq html (wassr-decode-html-entities 
     661                  (assq-get 'html status-data))) 
     662      (setq epoch (assq-get 'epoch status-data)) 
     663      (setq rid (assq-get 'rid status-data)) 
     664      (setq id (assq-get 'id status-data)) 
     665      (setq user-login-id (assq-get 'user_login_id status-data)) 
     666      (setq link (assq-get 'link status-data)) 
     667      (setq photo-url (assq-get 'photo_url status-data)) 
     668      (setq areacode (assq-get 'areacode status-data)) 
     669      (setq areaname (assq-get 'areaname status-data)) 
     670      (setq photo-thumbnail-url (assq-get 'photo_thumbnail_url status-data)) 
     671      (setq reply-status-url (assq-get 'reply_status_url status-data)) 
     672      (setq reply-user-login-id (assq-get 'reply_user_login_id status-data)) 
     673      (setq reply-message (assq-get 'reply_message status-data)) 
     674      (setq reply-user-nick (assq-get 'reply_user_nick status-data)) 
     675      (setq slurl (assq-get 'slurl status-data)) 
    692676      (setq user-screen-name (wassr-decode-html-entities 
    693677                              (assq-get 'screen_name user-data))) 
    694       (setq user-location (wassr-decode-html-entities 
    695                            (assq-get 'location user-data))) 
    696       (setq user-description (wassr-decode-html-entities 
    697                               (assq-get 'description user-data))) 
    698678      (setq user-profile-image-url (assq-get 'profile_image_url user-data)) 
    699       (setq user-url (assq-get 'url user-data)) 
    700679      (setq user-protected (assq-get 'protected user-data)) 
    701680 
    702681      ;; make username clickable 
    703682      (add-text-properties 
    704        0 (length user-name) 
     683       0 (length user-login-id) 
    705684       `(mouse-face highlight 
    706                     uri ,(concat "http://api.wassr.jp/" user-screen-name) 
     685                    uri ,(concat "http://wassr.jp/user/" user-screen-name) 
    707686                    face wassr-username-face) 
    708        user-name) 
     687       user-login-id) 
    709688 
    710689      ;; make screen-name clickable 
     
    713692       `(mouse-face highlight 
    714693                    face wassr-username-face 
    715                     uri ,(concat "http://api.wassr.jp/" user-screen-name) 
     694                    uri ,(concat "http://wassr.jp/user/" user-screen-name) 
    716695                    face wassr-username-face) 
    717696       user-screen-name) 
     
    737716                   highlight 
    738717                   face wassr-uri-face 
    739                    uri ,(concat "http://api.wassr.jp/" screen-name)) 
     718                   uri ,(concat "http://wassr.jp/user/" screen-name)) 
    740719               `(mouse-face highlight 
    741720                            face wassr-uri-face 
     
    744723          (setq regex-index (match-end 0)) )) 
    745724 
    746  
    747       ;; make source pretty and clickable 
    748       (if (string-match "<a href=\"\\(.*\\)\">\\(.*\\)</a>" source) 
    749           (let ((uri (match-string-no-properties 1 source)) 
    750                 (caption (match-string-no-properties 2 source))) 
    751             (setq source caption) 
    752             (add-text-properties 
    753              0 (length source) 
    754              `(mouse-face highlight 
    755                           uri ,uri 
    756                           face wassr-uri-face 
    757                           source ,source) 
    758              source) 
    759             )) 
    760  
    761725      (mapcar 
    762726       (lambda (sym) 
    763727         `(,sym . ,(symbol-value sym))) 
    764        '(id text source created-at truncated 
    765             user-id user-name user-screen-name user-location 
    766             user-description 
    767             user-profile-image-url 
    768             user-url 
    769             user-protected))))) 
     728       '(html text epoch rid id user-login-id 
     729              link photo-url areacode areaname 
     730              photo-thumbnail-url 
     731              reply-status-url 
     732              reply-user-login-id 
     733              reply-message 
     734              reply-user-nick 
     735              slurl 
     736              user-protected 
     737              user-profile-image-url 
     738              user-screen-name 
     739              ))))) 
    770740 
    771741(defun wassr-xmltree-to-status (xmltree) 
     
    10371007(defun wassr-get-status-url (username id) 
    10381008  "Generate status URL." 
    1039   (format "http://api.wassr.jp/%s/statuses/%d" username id)) 
     1009  (format "http://wassr.jp/user/%s/statuses/%" username id)) 
    10401010 
    10411011;;;###autoload