@@ -180,23 +180,16 @@ _EVENT is a string describing the type of event."
180
180
PROCESS is a http-request process.
181
181
If the response is invalid, A error occurs.
182
182
If next-link is exist, continue to request it."
183
- (let (response next-link stock )
183
+ (let (response-body next-link)
184
184
(with-current-buffer (get-buffer helm-qiita-http-buffer-name)
185
185
(unless (helm-qiita-valid-http-responsep process)
186
186
(error " Invalid http response " ))
187
187
(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)))
191
189
(kill-buffer helm-qiita-http-buffer-name)
192
190
(with-current-buffer (get-buffer helm-qiita-work-buffer-name)
193
191
(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)
200
193
(if next-link
201
194
(helm-qiita-http-request next-link)
202
195
(write-region (point-min ) (point-max ) helm-qiita-file)))))
@@ -232,6 +225,24 @@ Should to call in `helm-qiita-http-buffer-name'."
232
225
(goto-char (point-min ))
233
226
(re-search-forward " ^ ?$" nil t )))
234
227
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
+
235
246
(defun helm-qiita-stock-title (stock )
236
247
" Return a title of STOCK."
237
248
(cdr (assoc 'title stock)))
0 commit comments