Skip to content

Instantly share code, notes, and snippets.

@rayslava
Last active March 21, 2017 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayslava/8e6980664abecf9b436b to your computer and use it in GitHub Desktop.
Save rayslava/8e6980664abecf9b436b to your computer and use it in GitHub Desktop.
(defvar alfa-currencies 'nil "Current value of currencies")
(defun alfa-currency-query ()
"HTTP request to AlfaBank currency API"
(let ((url "https://alfabank.ru/ext-json/0.2/exchange/cash/"))
(web-http-get
(lambda (httpc header my-data)
(with-temp-buffer
(insert my-data)
(goto-char (point-min))
(let ((json-object-type 'plist))
(setf alfa-currencies (json-read)))))
:url url)))
(cl-defun alfa-get-currency-exchange (&optional (currency "usd") (direction "sell"))
"Get (sell buy) value for following currencies: usd eur gbp from Alfa-Bank.
`currency' is currency code \"usd\", \"eur\"), `direction' is \"sell\" or \"buy\"."
(plist-get
(seq-find
(lambda (elt)
(string= (plist-get elt :type) direction))
(plist-get
(plist-get
(plist-get alfa-currencies :response)
:data)
(intern (concat ":" currency)))) :value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment