-
Notifications
You must be signed in to change notification settings - Fork 90
/
omnisharp-http-utils.el
57 lines (48 loc) · 2.51 KB
/
omnisharp-http-utils.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;; -*- lexical-binding: t; -*-
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(require 'dash)
(defun omnisharp--get-host ()
"Makes sure omnisharp-host is ended by / "
(if (string= (substring omnisharp-host -1 ) "/")
omnisharp-host
(concat omnisharp-host "/")))
(defun omnisharp--get-api-url (api-name)
(concat (omnisharp--get-host) api-name))
(defun omnisharp-post-http-message (url callback &optional params async)
"Post http request to server. Return result."
(omnisharp--submit-request (omnisharp--get-api-url url) callback params async))
(defun omnisharp--submit-request (url callback &optional params async)
(if (require 'request nil 'noerror)
(lexical-let* ((c callback))
(request url
:type "POST"
:parser 'json-read
:sync (not async)
:data (json-encode params)
:error (cl-function (lambda (&rest args &key error-thrown &allow-other-keys)
(message "Error from %s : %S" url error-thrown)))
:complete
(lambda (&rest _)
(when omnisharp-debug
(message "Request completed")))
:success (cl-function (lambda (&key data &allow-other-keys)
(progn
(when c
(funcall c data))
(when omnisharp-debug
(message "Request succeeded"))
)))
:status-code '((404 . (lambda (&rest _) (message (format "Endpoint %s does not exist." url))))
(500 . (lambda (&rest _) (message (format "Error from %s." url))))
)))
(message "ERROR: You must install 'request-deferred' package")))
(provide 'omnisharp-http-utils)