Browse Source

Use a new twister-rpc function to wrap all calls

This method encapsulates the connection and closes it too, so there
won't be processes left behind.
Performance wise, this is probably not the smartest thing to do, but
that is of no concern at this time.
master
Marcel van der Boom 11 years ago
parent
commit
6af728e725
  1. 25
      twister.el

25
twister.el

@ -67,20 +67,27 @@ twister.conf file" @@ -67,20 +67,27 @@ twister.conf file"
:type 'integer
:group 'twister)
;; Get a connection to the twister daemon
(setf twisterd (json-rpc-connect
twister-host twister-port
twister-rpcuser twister-rpcpassword))
;; Preliminary convention
;; tw-* methods -> sorta private for now, don't use directly
;; twister-* methods -> public API
(defun twister-rpc (method &rest params)
"Wrapper for the json-rpc method for twister use.
The connection is closed afer each use. This is not necessarily
the most effective. METHOD is the RPC method we are calling
while PARAMS contain the rest of the parameters."
(let* ((twisterd (json-rpc-connect
twister-host twister-port
twister-rpcuser twister-rpcpassword))
(result (apply 'json-rpc twisterd method params)))
(json-rpc-close twisterd)
result))
(defun tw-get-last-post(user)
"Get the last post of a user"
(let (obj (json-new-object))
(json-rpc twisterd "getposts" 1
(twister-rpc "getposts" 1
(vector (json-add-to-object obj "username" user)))))
(defun tw-get-next-k(user)
@ -95,12 +102,10 @@ twister.conf file" @@ -95,12 +102,10 @@ twister.conf file"
"Post msg to the configured twister daemon"
(interactive)
(json-rpc
twisterd "newpostmsg"
(twister-rpc "newpostmsg"
twister-user
(tw-get-next-k twister-user) msg))
(defun twister-post-region (begin end)
"Post the current region to twister"
(interactive "r")

Loading…
Cancel
Save