Last active
March 21, 2017 13:49
-
-
Save rayslava/8e6980664abecf9b436b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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