Skip to content

Commit b40e706

Browse files
committed
Refactor
1 parent af05392 commit b40e706

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

helm-qiita.el

+21-10
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,16 @@ _EVENT is a string describing the type of event."
180180
PROCESS is a http-request process.
181181
If the response is invalid, A error occurs.
182182
If next-link is exist, continue to request it."
183-
(let (response next-link stock)
183+
(let (response-body next-link)
184184
(with-current-buffer (get-buffer helm-qiita-http-buffer-name)
185185
(unless (helm-qiita-valid-http-responsep process)
186186
(error "Invalid http response"))
187187
(setq next-link (helm-qiita-next-link))
188-
(setq response (json-read-from-string
189-
(buffer-substring-no-properties
190-
(+ (helm-qiita-point-of-separator) 1) (point-max)))))
188+
(setq response-body (helm-qiita-response-body)))
191189
(kill-buffer helm-qiita-http-buffer-name)
192190
(with-current-buffer (get-buffer helm-qiita-work-buffer-name)
193191
(goto-char (point-max))
194-
(dotimes (i (length response))
195-
(setq stock (aref response i))
196-
(insert (format "%s %s [href:%s]\n"
197-
(helm-qiita-stock-title stock)
198-
(helm-qiita-stock-format-tags stock)
199-
(helm-qiita-stock-url stock))))
192+
(helm-qiita-insert-stocks response-body)
200193
(if next-link
201194
(helm-qiita-http-request next-link)
202195
(write-region (point-min) (point-max) helm-qiita-file)))))
@@ -232,6 +225,24 @@ Should to call in `helm-qiita-http-buffer-name'."
232225
(goto-char (point-min))
233226
(re-search-forward "^?$" nil t)))
234227

228+
(defun helm-qiita-response-body ()
229+
"Read http response body as a json.
230+
Should to call in `helm-qiita-http-buffer-name'."
231+
(json-read-from-string
232+
(buffer-substring-no-properties
233+
(+ (helm-qiita-point-of-separator) 1) (point-max))))
234+
235+
(defun helm-qiita-insert-stocks (response-body)
236+
"Insert Qiita stock as the format of `helm-qiita-file'.
237+
Argument RESPONSE-BODY is http response body as a json"
238+
(let ((stock))
239+
(dotimes (i (length response-body))
240+
(setq stock (aref response-body i))
241+
(insert (format "%s %s [href:%s]\n"
242+
(helm-qiita-stock-title stock)
243+
(helm-qiita-stock-format-tags stock)
244+
(helm-qiita-stock-url stock))))))
245+
235246
(defun helm-qiita-stock-title (stock)
236247
"Return a title of STOCK."
237248
(cdr (assoc 'title stock)))

0 commit comments

Comments
 (0)