;ELC ;;; Compiled ;;; in Emacs version 28.0.50 ;;; with all optimizations. (byte-code "\300\301!\210\300\302!\210\300\303!\210\300\304!\207" [require url json sx sx-encoding] 2) #@56 When passed, this key provides a higher request quota. (defconst sx-request-api-key "0TE6s1tveCpP9K5r5JNDNQ((" (#$ . 190)) #@33 The current version of the API. (defconst sx-request-api-version "2.2" (#$ . 319)) #@37 The base URL to make requests from. (defconst sx-request-api-root (format "https://api.stackexchange.com/%s/" sx-request-api-version) (#$ . 408)) (byte-code "\300\301\302\303\304DD\305\306\307\310\311&\207" [custom-declare-variable sx-request-unzip-program funcall function #[0 "\300\207" [#1="gunzip"] 1 #1#] "Program used to unzip the response if it is compressed.\nThis program must accept compressed data on standard input.\n\nThis is only used (and necessary) if the function\n`zlib-decompress-region' is not defined, which is the case for\nEmacs versions < 24.4." :group sx :type string] 8) #@65 The number of API requests remaining. Set by `sx-request-make'. (defvar sx-request-remaining-api-requests nil (#$ . 1012)) (byte-code "\300\301\302\303\304DD\305\306\307\310\311&\207" [custom-declare-variable sx-request-remaining-api-requests-message-threshold funcall function #[0 "\300\207" [50] 1] "Lower bound for printed warnings of API usage limits.\nAfter `sx-request-remaining-api-requests' drops below this\nnumber, `sx-request-make' will begin printing out the\nnumber of requests left every time it finishes a call." :group sx :type integer] 8) #@123 Delay in seconds with each `sx-request-all-items' iteration. It is good to use a reasonable delay to avoid rate-limiting. (defvar sx-request-all-items-delay 0 (#$ . 1576)) (defvar sx--backoff-time nil) (defalias 'sx-request--wait-while-backoff #[0 "\2051\301\302\"\210\303 A@Z\304V\203\211\211\202/\211W\205/\301\305Z\"\210\306\307Z\\!\262\207" [sx--backoff-time message "Waiting for backoff time: %s" current-time 1000 "Backoff detected, waiting %s seconds" sleep-for 0.3] 5]) #@426 Call METHOD with ARGS until there are no more items. STOP-WHEN is a function that takes the entire response and returns non-nil if the process should stop. All other arguments are identical to `sx-request-make', but PROCESS-FUNCTION is given the default value of `identity' (rather than `sx-request-response-get-items') to allow STOP-WHEN to access the response wrapper. (fn METHOD &optional ARGS REQUEST-METHOD STOP-WHEN) (defalias 'sx-request-all-items #[1025 "\301\302\206\303\304\305\306\302B B\304$!\204C\211\307\236AT\262\244\262\266\310!\210\305 \306B\nB $\262\202\307\236A\244\207" [sx-request-all-items-delay nil 1 sx-request-all-stop-when-no-more identity sx-request-make page items sleep-for] 14 (#$ . 2077)]) (byte-code "\300\301\302\303#\300\207" [function-put sx-request-all-items lisp-indent-function 1] 4) #@1099 Make a request to the API, executing METHOD with ARGS. You should almost certainly be using `sx-method-call' instead of this function. REQUEST-METHOD is one of `get' (default) or `post'. Returns the entire response as processed by PROCESS-FUNCTION. This defaults to `sx-request-response-get-items'. The full set of arguments is built with `sx-request--build-keyword-arguments', prepending `sx-request-api-key' to receive a higher quota. It will also include user's `access_token` if it is avaialble. This call is then resolved with `url-retrieve-synchronously' to a temporary buffer that it returns. The headers are then stripped using a search a blank line ("\n\n"). The main body of the response is then tested with `sx-encoding-gzipped-buffer-p' for compression. If it is compressed, `sx-request-unzip-program' is called to uncompress the response. The uncompressed respons is then read with `json-read-from-string'. `sx-request-remaining-api-requests' is updated appropriately and the main content of the response is returned. (fn METHOD &optional ARGS REQUEST-METHOD PROCESS-FUNCTION) (defalias 'sx-request-make #[1025 "\306 \210\307\211\310\311\" P\205\312!\226\313\314!\211\204'\315\316!\202\363r\211q\210eb\210\317\320\311\307#\204<\315\321!\202Be`|\210\322 \323!\324\204N\202g\325\326!\203\\\326ed\"\210\202e\327ed/\311\307%\210\322 \330\331#\3321\311\333\334012\335!+0\202\207\336\337\"\210\311\262\340!\210\211\204\224\315\341\"\210\342!\210\211\343\236A\344\236A\345\236A\346\236A\347\236A\350\236A\203\302\315\351%\210\203\323\336\352\"\210\353 A@\\3\211\21145W\203\343\354\3554\"\210 \206\351\356!\266\206\262\266\204)-\207" [url-automatic-caching url-inhibit-uncompression url-request-data sx-request-api-root url-request-method url-request-extra-headers sx-request--wait-while-backoff t sx-request--build-keyword-arguments nil symbol-name (("Content-Type" . "application/x-www-form-urlencoded")) url-retrieve-synchronously error "Something went wrong in `url-retrieve-synchronously'" search-forward "\n\n" "Headers missing; response corrupt" buffer-string sx-encoding-gzipped-p decode-coding-string fboundp zlib-decompress-region shell-command-on-region utf-8 nocopy (debug error) list :null json-read-from-string message "`json' error: %S" kill-buffer "Invalid response to the url request: %s" sx--ensure-site error_id method error_name error_message backoff quota_remaining "Request failed: (%s) [%i %s] %S" "Backoff received %s" current-time sx-message "%d API requests remaining" sx-request-response-get-items sx-request-unzip-program json-null json-array-type json-false sx--backoff-time sx-request-remaining-api-requests sx-request-remaining-api-requests-message-threshold] 24 (#$ . 2940)]) (byte-code "\300\301\302\303#\300\207" [function-put sx-request-make lisp-indent-function 1] 4) #@224 Fallback method when authentication is not available. This is for UI generation when the associated API call would require authentication. Currently returns nil. (fn METHOD &optional ARGS REQUEST-METHOD PROCESS-FUNCTION) (defalias 'sx-request-fallback #[1025 "\300\207" [(nil)] 5 (#$ . 5832)]) #@58 Url of the "data" directory inside the SX `data' branch. (defconst sx-request--data-url-format "https://raw.githubusercontent.com/vermiculus/sx.el/data/data/%s.el" (#$ . 6134)) #@125 Return the buffer contents after any url headers. Error if url headers are absent or if they indicate something went wrong. (defalias 'sx-request--read-buffer-data #[0 "eb\210\300\301\302\303!\"\204\304\305!\210\306\307\310\311#\204\304\312!\207`d{\313p!\210\207" [string-match "200" thing-at-point line error "Page not found." search-forward "\n\n" nil t "Headers missing; response corrupt" kill-buffer] 4 (#$ . 6318)]) #@344 Fetch and return data stored online at URL. If CALLBACK is nil, fetching is done synchronously and the data (buffer contents sans headers) is returned as a string. Otherwise CALLBACK must be a function of a single argument. Then `url-retrieve' is called asynchronously and CALLBACK is passed the retrieved data. (fn URL &optional CALLBACK) (defalias 'sx-request-get-url #[513 "\304\211\305\306\211\205\307\310\"\203\311\312\313$\202 \314!?\2056\211\204/\315\316!\2026r\211q\210\317 ),\207" [url-automatic-caching url-inhibit-uncompression url-request-method url-request-extra-headers t "GET" (("Content-Type" . "application/x-www-form-urlencoded")) make-closure #[257 "\300\301 !\207" [V0 sx-request--read-buffer-data] 3 "\n\n(fn STATUS)"] url-retrieve nil silent url-retrieve-synchronously error "Something went wrong in `url-retrieve-synchronously'" sx-request--read-buffer-data] 9 (#$ . 6750)]) #@243 Fetch and return data stored online by SX. FILE is a string or symbol, the name of the file which holds the desired data, relative to `sx-request--data-url-format'. For instance, `tags/emacs' returns the list of tags on Emacs.SE. (fn FILE) (defalias 'sx-request-get-data #[257 "\301\302\303\"!!\207" [sx-request--data-url-format read sx-request-get-url format] 6 (#$ . 7676)]) #@437 Format ALIST as a key-value list joined with KV-SEP. If authentication is needed, include it also or error if it is not available. Build a "key=value&key=value&..."-style string with the elements of ALIST. If any value in the alist is nil, that pair will not be included in the return. If you wish to pass a notion of false, use the symbol `false'. Each element is processed with `sx--thing-as-string'. (fn ALIST &optional KV-SEP) (defalias 'sx-request--build-keyword-arguments #[513 "\301B\302\303!@B\262\211\203\211B\262\304\305\306\"\307\310\311\312 \"\"\313#\207" [sx-request-api-key "key" sx-cache-get auth mapconcat make-closure #[257 "\301@!\302\301A\300\303#Q\207" [V0 sx--thing-as-string "=" t] 7 "\n\n(fn PAIR)"] delq nil mapcar #[257 "\211A\205\211\207" [] 2 "\n\n(fn PAIR)"] "&"] 11 (#$ . 8064)]) #@49 Returns the items from RESPONSE. (fn RESPONSE) (defalias 'sx-request-response-get-items #[257 "\300!\210\211\301\236A\302!\207" [sx--ensure-site items sx-encoding-clean-content-deep] 5 (#$ . 8898)]) #@17 (fn RESPONSE) (defalias 'sx-request-all-stop-when-no-more #[257 "\211?\206\n\300\236A?\207" [has_more] 3 (#$ . 9107)]) (provide 'sx-request)