|
|
@@ -85,11 +85,11 @@
|
|
|
:reply-markup (telegram-inline-keyboard-markup
|
|
|
(list (list (list :text "Авторизоваться!"
|
|
|
:url (gsheets-get-authorization-url token-id)))))))
|
|
|
-(defun google-api-call (token-id path base-url &key (method :get) parameters body is-retry)
|
|
|
+(defun google-api-call (token-id path base-url &key (method :get) parameters hash-body is-retry)
|
|
|
(alexandria:when-let (access-token (gsheets-get-tokens token-id))
|
|
|
- (let* ((content (when body
|
|
|
+ (let* ((content (when hash-body
|
|
|
(with-output-to-string (stream)
|
|
|
- (yason:encode (alexandria:plist-hash-table body) stream))))
|
|
|
+ (yason:encode hash-body stream))))
|
|
|
(response (json-request
|
|
|
(quri:render-uri (quri:merge-uris (quri:make-uri :path path) (quri:uri base-url)))
|
|
|
:method method :parameters parameters :content content
|
|
|
@@ -97,7 +97,7 @@
|
|
|
(err (aget "error" response)))
|
|
|
(if (and err (equal 401 (aget "code" err)) (not is-retry) (gsheets-refresh-access-token token-id))
|
|
|
;; Retry in case of auth error and successful token refresh
|
|
|
- (google-api-call token-id path base-url :method method :parameters parameters :body body :is-retry t)
|
|
|
+ (google-api-call token-id path base-url :method method :parameters parameters :hash-body hash-body :is-retry t)
|
|
|
response))))
|
|
|
|
|
|
(defun gsheets-find-files (token-id &optional next-page-token)
|
|
|
@@ -110,17 +110,19 @@
|
|
|
(google-api-call token-id
|
|
|
(format nil "files/~A/watch" file-id) +gdrive-base-uri+
|
|
|
:method :post
|
|
|
- :body (append
|
|
|
- (list "kind" "api#channel"
|
|
|
- "id" (princ-to-string (uuid:make-v4-uuid))
|
|
|
- "type" "web_hook"
|
|
|
- "address" (quri:render-uri
|
|
|
- (quri:merge-uris (quri:uri (format nil "/hook/~A" webhook))
|
|
|
- (quri:uri *web-path*))))
|
|
|
- (when token (list "token" token))
|
|
|
- (when expiration (list "expiration" expiration))
|
|
|
- (when payload (list "payload" "true"))
|
|
|
- (when params (list "params" params)))))
|
|
|
+ :hash-body
|
|
|
+ (alexandria:plist-hash-table
|
|
|
+ (append
|
|
|
+ (list "kind" "api#channel"
|
|
|
+ "id" (princ-to-string (uuid:make-v4-uuid))
|
|
|
+ "type" "web_hook"
|
|
|
+ "address" (quri:render-uri
|
|
|
+ (quri:merge-uris (quri:uri (format nil "/hook/~A" webhook))
|
|
|
+ (quri:uri *web-path*))))
|
|
|
+ (when token (list "token" token))
|
|
|
+ (when expiration (list "expiration" expiration))
|
|
|
+ (when payload (list "payload" "true"))
|
|
|
+ (when params (list "params" params))))))
|
|
|
|
|
|
(defun gsheets-get-sheet (token-id sheet-id &key fields ranges include-grid-data)
|
|
|
(google-api-call token-id
|
|
|
@@ -139,12 +141,20 @@
|
|
|
(when fields (list (cons "fields" fields)))
|
|
|
(when major-dimension (list (cons "majorDimension" major-dimension))))))
|
|
|
|
|
|
-(defun gsheets-put-sheet-values (token-id sheet-id range values &key raw)
|
|
|
+(defun gsheets-put-sheet-values (token-id sheet-id range-values &key raw major-dimension)
|
|
|
(google-api-call token-id
|
|
|
- (format nil "spreadsheets/~A/values/~A" sheet-id range) +gsheets-base-uri+
|
|
|
- :method :put
|
|
|
- :parameters (list (cons "valueInputOption" (if raw "RAW" "USER_ENTERED")))
|
|
|
- :body (list "values" values)))
|
|
|
+ (format nil "spreadsheets/~A/values:batchUpdate" sheet-id) +gsheets-base-uri+
|
|
|
+ :method :post
|
|
|
+ :hash-body
|
|
|
+ (alexandria:plist-hash-table
|
|
|
+ (list "valueInputOption" (if raw "RAW" "USER_ENTERED")
|
|
|
+ "data" (loop for (range . values) in range-values
|
|
|
+ collect (alexandria:plist-hash-table
|
|
|
+ (append
|
|
|
+ (list "range" range
|
|
|
+ "values" values)
|
|
|
+ (when major-dimension
|
|
|
+ (list "majorDimension" major-dimension)))))))))
|
|
|
|
|
|
(defvar *gsheets-chat-sheets* nil "ALIST of (chat-id . sheet-id)")
|
|
|
(defvar *gsheets-chat-sheet-sessions* nil "ALIST of (chat-id . (files . next)) for sheet selection")
|
|
|
@@ -213,7 +223,7 @@
|
|
|
(if sheet-id
|
|
|
(let* ((range (car args))
|
|
|
(values (list (cdr args)))
|
|
|
- (resp (gsheets-put-sheet-values from-id sheet-id range values)))
|
|
|
+ (resp (gsheets-put-sheet-values from-id sheet-id (list (cons range values)))))
|
|
|
(bot-send-message chat-id (format nil "Записал в ~A" (aget "updatedRange" resp))))
|
|
|
(bot-send-message chat-id "Выбери документ сначала: /sheets"))))
|
|
|
|