growi-client 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/growi/client/apireq/api_request_attachments.rb +9 -9
- data/lib/growi/client/apireq/api_request_base.rb +5 -4
- data/lib/growi/client/apireq/api_request_pages.rb +179 -57
- data/lib/growi/client/client.rb +4 -4
- data/lib/growi/client/logger.rb +19 -0
- data/lib/growi/client/model/growi_attachment.rb +4 -5
- data/lib/growi/client/model/growi_page.rb +12 -11
- data/lib/growi/client/model/growi_page_revision.rb +3 -4
- data/lib/growi/client/model/growi_user.rb +3 -4
- data/lib/growi/client/version.rb +1 -1
- data/wercker.yml +89 -89
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1be36d8f24f482a6ef4619cdd24e2cb0eb9864c8942ca73460041afa7c4bda6e
|
4
|
+
data.tar.gz: 1313b309deaad58f062c61c71c1277e34c0b1f1b355bb3f9995946993befec13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 129f361ed75e5787dd3e16ae6160a7a5bf65c32cf710531ba380087ec9bcc9334f61d2186fa2c10c647fd8e1187a5a342b67124fe113a12be790f5a58b507750
|
7
|
+
data.tar.gz: 0b7639ced1c08bda7d00fb1de4329658bbf73f7b3e1bdb2d3febbffcef8b7cab03d7a86ed4f543816f49576f3c808ecaaffa75d5174c1313b34b30e9f6ece84c
|
data/README.md
CHANGED
@@ -10,6 +10,7 @@ growi-client is passed the test of these Growi versions.
|
|
10
10
|
|
11
11
|
|growi-client|Growi|
|
12
12
|
| --- | --- |
|
13
|
+
|1.0.0|3.3.3|
|
13
14
|
|0.9.0|3.1.12|
|
14
15
|
|
15
16
|
## Installation
|
@@ -219,3 +220,7 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
219
220
|
## Code of Conduct
|
220
221
|
|
221
222
|
Everyone interacting in the Growi::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ryu-satgrowiwi-client/blob/master/CODE_OF_CONDUCT.md).
|
223
|
+
|
224
|
+
## TODO
|
225
|
+
|
226
|
+
- [ ] pagenation に対応する
|
@@ -23,7 +23,7 @@ class GApiRequestAttachmentsList < GApiRequestBase
|
|
23
23
|
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
24
24
|
ret = JSON.parse RestClient::Request.execute params
|
25
25
|
if (ret['ok'] == false)
|
26
|
-
return
|
26
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
27
27
|
end
|
28
28
|
attachments = []
|
29
29
|
ret['attachments'].each do |attachment|
|
@@ -35,10 +35,10 @@ class GApiRequestAttachmentsList < GApiRequestBase
|
|
35
35
|
protected
|
36
36
|
|
37
37
|
# バリデーションエラーを取得する
|
38
|
-
# @return [nil/
|
38
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
39
39
|
def _invalid
|
40
40
|
if ! (@param[:page_id])
|
41
|
-
|
41
|
+
GCInvalidRequest.new 'Parameter page_id is required.'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -76,7 +76,7 @@ class GApiRequestAttachmentsAdd < GApiRequestBase
|
|
76
76
|
}.merge(rest_client_param)
|
77
77
|
ret = JSON.parse RestClient::Request.execute params
|
78
78
|
if (ret['ok'] == false)
|
79
|
-
return
|
79
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
80
80
|
end
|
81
81
|
return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
|
82
82
|
end
|
@@ -84,10 +84,10 @@ class GApiRequestAttachmentsAdd < GApiRequestBase
|
|
84
84
|
protected
|
85
85
|
|
86
86
|
# バリデーションエラーを取得する
|
87
|
-
# @return [nil/
|
87
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
88
88
|
def _invalid
|
89
89
|
if ! (@param[:file] && @param[:page_id])
|
90
|
-
|
90
|
+
GCInvalidRequest.new 'Parameters file and page_id are required.'
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -121,7 +121,7 @@ class GApiRequestAttachmentsRemove < GApiRequestBase
|
|
121
121
|
}.merge(rest_client_param)
|
122
122
|
ret = JSON.parse RestClient::Request.execute params
|
123
123
|
if (ret['ok'] == false)
|
124
|
-
return
|
124
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
125
125
|
end
|
126
126
|
return GApiReturn.new(ok: ret['ok'], data: nil)
|
127
127
|
end
|
@@ -129,10 +129,10 @@ class GApiRequestAttachmentsRemove < GApiRequestBase
|
|
129
129
|
protected
|
130
130
|
|
131
131
|
# バリデーションエラーを取得する
|
132
|
-
# @return [nil/
|
132
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
133
133
|
def _invalid
|
134
134
|
if ! (@param[:attachment_id])
|
135
|
-
|
135
|
+
GCInvalidRequest.new 'Parameter attachment_id is required.'
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# APIリクエストのバリデーションエラー
|
2
2
|
# @note rescue する必要はないので Exception クラスは継承しない
|
3
|
-
class
|
4
|
-
attr_reader :msg
|
3
|
+
class GCInvalidRequest
|
4
|
+
attr_reader :ok, :msg
|
5
5
|
|
6
6
|
# コンストラクタ
|
7
7
|
# @param [String] msg エラーメッセージ(原因と対策が分かるとよい)
|
8
8
|
def initialize(msg)
|
9
|
+
@ok = false
|
9
10
|
@msg = msg
|
10
11
|
end
|
11
12
|
|
@@ -97,9 +98,9 @@ class GApiRequestBase
|
|
97
98
|
protected
|
98
99
|
|
99
100
|
# バリデーションエラーを取得する
|
100
|
-
# @return [nil/
|
101
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
101
102
|
def _invalid
|
102
|
-
return
|
103
|
+
return GCInvalidRequest "Invalid API request.";
|
103
104
|
end
|
104
105
|
|
105
106
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require_relative 'api_request_base'
|
2
2
|
require 'growi/client/model/growi_page'
|
3
|
+
require 'growi/client/logger'
|
3
4
|
|
4
5
|
# ページ一覧リクエスト用クラス
|
5
|
-
# @ref https://github.com/
|
6
|
+
# @ref https://github.com/weseek/growi/blob/master/src/server/routes/page.js
|
6
7
|
class GApiRequestPagesList < GApiRequestBase
|
7
8
|
|
8
9
|
# コンストラクタ
|
@@ -14,6 +15,7 @@ class GApiRequestPagesList < GApiRequestBase
|
|
14
15
|
end
|
15
16
|
|
16
17
|
# リクエストを実行する
|
18
|
+
# [TODO] pagination に対応する
|
17
19
|
# @override
|
18
20
|
# @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
|
19
21
|
# @param [Hash] rest_client_param RestClientのパラメータ
|
@@ -25,28 +27,44 @@ class GApiRequestPagesList < GApiRequestBase
|
|
25
27
|
end
|
26
28
|
|
27
29
|
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
GCLogger.logger.debug('Request: ' + params.to_s)
|
31
|
+
|
32
|
+
begin
|
33
|
+
raw_ret = RestClient::Request.execute params
|
34
|
+
GCLogger.logger.debug('Return: ' + raw_ret.to_s)
|
35
|
+
ret = JSON.parse raw_ret
|
36
|
+
rescue Exception => e
|
37
|
+
GCLogger.logger.error(e)
|
38
|
+
return GCInvalidRequest.new "Unknown error occured: #{e}"
|
39
|
+
end
|
40
|
+
|
41
|
+
if (!ret['ok'].nil? && ret['ok'] == false)
|
42
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
31
43
|
end
|
32
|
-
|
33
|
-
|
34
|
-
pages
|
44
|
+
|
45
|
+
begin
|
46
|
+
pages = []
|
47
|
+
ret['pages'].each do |page|
|
48
|
+
pages.push(GrowiPage.new(page))
|
49
|
+
end
|
50
|
+
return GApiReturn.new(ok: ret['ok'], data: pages)
|
51
|
+
rescue Exception => e
|
52
|
+
GCLogger.logger.error(e)
|
53
|
+
return GCInvalidRequest.new "Fail to parse: #{e}"
|
35
54
|
end
|
36
|
-
return GApiReturn.new(ok: ret['ok'], data: pages)
|
37
55
|
end
|
38
56
|
|
39
57
|
protected
|
40
58
|
|
41
59
|
# バリデーションエラーを取得する
|
42
60
|
# @override
|
43
|
-
# @return [nil/
|
61
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
44
62
|
def _invalid
|
45
63
|
if ! (@param[:path] || @param[:user])
|
46
|
-
return
|
64
|
+
return GCInvalidRequest.new 'Parameter path or user is required.'
|
47
65
|
end
|
48
66
|
if (@param[:path] && @param[:user])
|
49
|
-
return
|
67
|
+
return GCInvalidRequest.new 'Parameter path and user can not be specified both.'
|
50
68
|
end
|
51
69
|
end
|
52
70
|
|
@@ -76,11 +94,23 @@ class GApiRequestPagesGet < GApiRequestBase
|
|
76
94
|
if invalid?
|
77
95
|
return validation_msg
|
78
96
|
end
|
97
|
+
|
79
98
|
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
80
|
-
|
81
|
-
|
82
|
-
|
99
|
+
GCLogger.logger.debug('Request: ' + params.to_s)
|
100
|
+
|
101
|
+
begin
|
102
|
+
raw_ret = RestClient::Request.execute params
|
103
|
+
GCLogger.logger.debug('Return: ' + raw_ret.to_s)
|
104
|
+
ret = JSON.parse raw_ret
|
105
|
+
rescue Exception => e
|
106
|
+
GCLogger.logger.error(e)
|
107
|
+
return GCInvalidRequest.new "Unknown error occured: #{e}"
|
108
|
+
end
|
109
|
+
|
110
|
+
if (!ret['ok'].nil? && ret['ok'] == false)
|
111
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
83
112
|
end
|
113
|
+
|
84
114
|
return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
|
85
115
|
end
|
86
116
|
|
@@ -88,10 +118,10 @@ protected
|
|
88
118
|
|
89
119
|
# バリデーションエラーを取得する
|
90
120
|
# @override
|
91
|
-
# @return [nil/
|
121
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
92
122
|
def _invalid
|
93
123
|
if ! (@param[:path] || @param[:page_id])
|
94
|
-
return
|
124
|
+
return GCInvalidRequest.new 'Parameter path or page_id is required.'
|
95
125
|
end
|
96
126
|
end
|
97
127
|
|
@@ -125,10 +155,21 @@ class GApiRequestPagesCreate < GApiRequestBase
|
|
125
155
|
payload: @param.to_json,
|
126
156
|
headers: { content_type: :json, accept: :json }
|
127
157
|
}.merge(rest_client_param)
|
128
|
-
|
129
|
-
|
130
|
-
|
158
|
+
GCLogger.logger.debug('Request: ' + params.to_s)
|
159
|
+
|
160
|
+
begin
|
161
|
+
raw_ret = RestClient::Request.execute params
|
162
|
+
GCLogger.logger.debug('Return: ' + raw_ret.to_s)
|
163
|
+
ret = JSON.parse raw_ret
|
164
|
+
rescue Exception => e
|
165
|
+
GCLogger.logger.error(e)
|
166
|
+
return GCInvalidRequest.new "Unknown error occured: #{e}"
|
131
167
|
end
|
168
|
+
|
169
|
+
if (!ret['ok'].nil? && ret['ok'] == false)
|
170
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
171
|
+
end
|
172
|
+
|
132
173
|
return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
|
133
174
|
end
|
134
175
|
|
@@ -136,10 +177,10 @@ protected
|
|
136
177
|
|
137
178
|
# バリデーションエラーを取得する
|
138
179
|
# @override
|
139
|
-
# @return [nil/
|
180
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
140
181
|
def _invalid
|
141
182
|
if ! (@param[:body] && @param[:path])
|
142
|
-
return
|
183
|
+
return GCInvalidRequest.new 'Parameters body and path are required.'
|
143
184
|
end
|
144
185
|
end
|
145
186
|
|
@@ -172,10 +213,21 @@ class GApiRequestPagesUpdate < GApiRequestBase
|
|
172
213
|
payload: @param.to_json,
|
173
214
|
headers: { content_type: :json, accept: :json }
|
174
215
|
}.merge(rest_client_param)
|
175
|
-
|
176
|
-
|
177
|
-
|
216
|
+
GCLogger.logger.debug('Request: ' + params.to_s)
|
217
|
+
|
218
|
+
begin
|
219
|
+
raw_ret = RestClient::Request.execute params
|
220
|
+
GCLogger.logger.debug('Return: ' + raw_ret.to_s)
|
221
|
+
ret = JSON.parse raw_ret
|
222
|
+
rescue Exception => e
|
223
|
+
GCLogger.logger.error(e)
|
224
|
+
return GCInvalidRequest.new "Unknown error occured: #{e}"
|
225
|
+
end
|
226
|
+
|
227
|
+
if (!ret['ok'].nil? && ret['ok'] == false)
|
228
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
178
229
|
end
|
230
|
+
|
179
231
|
return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
|
180
232
|
end
|
181
233
|
|
@@ -183,10 +235,10 @@ protected
|
|
183
235
|
|
184
236
|
# バリデーションエラーを取得する
|
185
237
|
# @override
|
186
|
-
# @return [nil/
|
238
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
187
239
|
def _invalid
|
188
|
-
if ! (@param[:page_id] && @param[:body])
|
189
|
-
return
|
240
|
+
if ! (@param[:page_id] && @param[:revision_id] && @param[:body])
|
241
|
+
return GCInvalidRequest.new 'Parameters page_id, revision_id and body are required.'
|
190
242
|
end
|
191
243
|
end
|
192
244
|
|
@@ -218,21 +270,40 @@ class GApiRequestPagesSeen < GApiRequestBase
|
|
218
270
|
payload: @param.to_json,
|
219
271
|
headers: { content_type: :json, accept: :json }
|
220
272
|
}.merge(rest_client_param)
|
221
|
-
|
222
|
-
|
223
|
-
|
273
|
+
GCLogger.logger.debug('Request: ' + params.to_s)
|
274
|
+
|
275
|
+
begin
|
276
|
+
raw_ret = RestClient::Request.execute params
|
277
|
+
GCLogger.logger.debug('Return: ' + raw_ret.to_s)
|
278
|
+
ret = JSON.parse raw_ret
|
279
|
+
rescue Exception => e
|
280
|
+
GCLogger.logger.error(e)
|
281
|
+
return GCInvalidRequest.new "Unknown error occured: #{e}"
|
282
|
+
end
|
283
|
+
|
284
|
+
if (!ret['ok'].nil? && ret['ok'] == false)
|
285
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
286
|
+
end
|
287
|
+
|
288
|
+
begin
|
289
|
+
users = ret['seenUser'].map do |user|
|
290
|
+
user.is_a?(String) ? user : GrowiUser.new(user)
|
291
|
+
end
|
292
|
+
return GApiReturn.new(ok: ret['ok'], data: users)
|
293
|
+
rescue Exception => e
|
294
|
+
GCLogger.logger.error(e)
|
295
|
+
return GCInvalidRequest.new "Fail to parse: #{e}"
|
224
296
|
end
|
225
|
-
return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['seenUser']))
|
226
297
|
end
|
227
298
|
|
228
299
|
protected
|
229
300
|
|
230
301
|
# バリデーションエラーを取得する
|
231
302
|
# @override
|
232
|
-
# @return [nil/
|
303
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
233
304
|
def _invalid
|
234
305
|
if ! (@param[:page_id])
|
235
|
-
return
|
306
|
+
return GCInvalidRequest.new 'Parameter page_id required.'
|
236
307
|
end
|
237
308
|
end
|
238
309
|
|
@@ -259,14 +330,26 @@ class GApiRequestLikesAdd < GApiRequestBase
|
|
259
330
|
if invalid?
|
260
331
|
return validation_msg
|
261
332
|
end
|
333
|
+
|
262
334
|
params = { method: :post, url: entry_point,
|
263
335
|
payload: @param.to_json,
|
264
336
|
headers: { content_type: :json, accept: :json }
|
265
337
|
}.merge(rest_client_param)
|
266
|
-
|
267
|
-
|
268
|
-
|
338
|
+
GCLogger.logger.debug('Request: ' + params.to_s)
|
339
|
+
|
340
|
+
begin
|
341
|
+
raw_ret = RestClient::Request.execute params
|
342
|
+
GCLogger.logger.debug('Return: ' + raw_ret.to_s)
|
343
|
+
ret = JSON.parse raw_ret
|
344
|
+
rescue Exception => e
|
345
|
+
GCLogger.logger.error(e)
|
346
|
+
return GCInvalidRequest.new "Unknown error occured: #{e}"
|
347
|
+
end
|
348
|
+
|
349
|
+
if (!ret['ok'].nil? && ret['ok'] == false)
|
350
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
269
351
|
end
|
352
|
+
|
270
353
|
return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
|
271
354
|
end
|
272
355
|
|
@@ -274,10 +357,10 @@ protected
|
|
274
357
|
|
275
358
|
# バリデーションエラーを取得する
|
276
359
|
# @override
|
277
|
-
# @return [nil/
|
360
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
278
361
|
def _invalid
|
279
362
|
if ! (@param[:page_id])
|
280
|
-
return
|
363
|
+
return GCInvalidRequest.new 'Parameter page_id required.'
|
281
364
|
end
|
282
365
|
end
|
283
366
|
|
@@ -308,10 +391,21 @@ class GApiRequestLikesRemove < GApiRequestBase
|
|
308
391
|
payload: @param.to_json,
|
309
392
|
headers: { content_type: :json, accept: :json }
|
310
393
|
}.merge(rest_client_param)
|
311
|
-
|
312
|
-
|
313
|
-
|
394
|
+
GCLogger.logger.debug('Request: ' + params.to_s)
|
395
|
+
|
396
|
+
begin
|
397
|
+
raw_ret = RestClient::Request.execute params
|
398
|
+
GCLogger.logger.debug('Return: ' + raw_ret.to_s)
|
399
|
+
ret = JSON.parse raw_ret
|
400
|
+
rescue Exception => e
|
401
|
+
GCLogger.logger.error(e)
|
402
|
+
return GCInvalidRequest.new "Unknown error occured: #{e}"
|
403
|
+
end
|
404
|
+
|
405
|
+
if (!ret['ok'].nil? && ret['ok'] == false)
|
406
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
314
407
|
end
|
408
|
+
|
315
409
|
return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
|
316
410
|
end
|
317
411
|
|
@@ -319,10 +413,10 @@ protected
|
|
319
413
|
|
320
414
|
# バリデーションエラーを取得する
|
321
415
|
# @override
|
322
|
-
# @return [nil/
|
416
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
323
417
|
def _invalid
|
324
418
|
if ! (@param[:page_id])
|
325
|
-
return
|
419
|
+
return GCInvalidRequest.new 'Parameter page_id required.'
|
326
420
|
end
|
327
421
|
end
|
328
422
|
|
@@ -351,25 +445,41 @@ class GApiRequestPagesUpdatePost < GApiRequestBase
|
|
351
445
|
return validation_msg
|
352
446
|
end
|
353
447
|
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
354
|
-
|
355
|
-
|
356
|
-
|
448
|
+
GCLogger.logger.debug('Request: ' + params.to_s)
|
449
|
+
|
450
|
+
begin
|
451
|
+
raw_ret = RestClient::Request.execute params
|
452
|
+
GCLogger.logger.debug('Return: ' + raw_ret.to_s)
|
453
|
+
ret = JSON.parse raw_ret
|
454
|
+
rescue Exception => e
|
455
|
+
GCLogger.logger.error(e)
|
456
|
+
return GCInvalidRequest.new "Unknown error occured: #{e}"
|
457
|
+
end
|
458
|
+
|
459
|
+
if (!ret['ok'].nil? && ret['ok'] == false)
|
460
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
357
461
|
end
|
358
|
-
|
359
|
-
|
360
|
-
|
462
|
+
|
463
|
+
begin
|
464
|
+
posts = []
|
465
|
+
ret['updatePost'].each do |post|
|
466
|
+
pages.push(GrowiPage.new(post))
|
467
|
+
end
|
468
|
+
return GApiReturn.new(ok: ret['ok'], data: posts)
|
469
|
+
rescue Exception => e
|
470
|
+
GCLogger.logger.error(e)
|
471
|
+
return GCInvalidRequest.new "Fail to parse: #{e}"
|
361
472
|
end
|
362
|
-
return GApiReturn.new(ok: ret['ok'], data: posts)
|
363
473
|
end
|
364
474
|
|
365
475
|
protected
|
366
476
|
|
367
477
|
# バリデーションエラーを取得する
|
368
478
|
# @override
|
369
|
-
# @return [nil/
|
479
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
370
480
|
def _invalid
|
371
481
|
if ! (@param[:path])
|
372
|
-
return
|
482
|
+
return GCInvalidRequest.new 'Parameter path required.'
|
373
483
|
end
|
374
484
|
end
|
375
485
|
|
@@ -398,11 +508,23 @@ class GApiRequestPagesRemove < GApiRequestBase
|
|
398
508
|
if invalid?
|
399
509
|
return validation_msg
|
400
510
|
end
|
511
|
+
|
401
512
|
param = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
|
402
|
-
|
403
|
-
|
404
|
-
|
513
|
+
GCLogger.logger.debug('Request: ' + params.to_s)
|
514
|
+
|
515
|
+
begin
|
516
|
+
raw_ret = RestClient::Request.execute params
|
517
|
+
GCLogger.logger.debug('Return: ' + raw_ret.to_s)
|
518
|
+
ret = JSON.parse raw_ret
|
519
|
+
rescue Exception => e
|
520
|
+
GCLogger.logger.error(e)
|
521
|
+
return GCInvalidRequest.new "Unknown error occured: #{e}"
|
522
|
+
end
|
523
|
+
|
524
|
+
if (!ret['ok'].nil? && ret['ok'] == false)
|
525
|
+
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
|
405
526
|
end
|
527
|
+
|
406
528
|
return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
|
407
529
|
end
|
408
530
|
|
@@ -410,10 +532,10 @@ protected
|
|
410
532
|
|
411
533
|
# バリデーションエラーを取得する
|
412
534
|
# @override
|
413
|
-
# @return [nil/
|
535
|
+
# @return [nil/GCInvalidRequest] バリデーションエラー結果
|
414
536
|
def _invalid
|
415
537
|
if ! (@param[:page_id] || @param[:revision_id])
|
416
|
-
return
|
538
|
+
return GCInvalidRequest.new 'Parameter page_id or revision_id is required.'
|
417
539
|
end
|
418
540
|
end
|
419
541
|
|
data/lib/growi/client/client.rb
CHANGED
@@ -11,8 +11,8 @@ class GrowiClient
|
|
11
11
|
|
12
12
|
# コンストラクタ
|
13
13
|
def initialize(growi_url: '', access_token: '', rest_client_param: {})
|
14
|
-
raise ArgumentError, 'Config `growi_url` is required.' if growi_url.
|
15
|
-
raise ArgumentError, 'Config `access_token` is required.' if access_token.
|
14
|
+
raise ArgumentError, 'Config `growi_url` is required.' if growi_url.nil?
|
15
|
+
raise ArgumentError, 'Config `access_token` is required.' if access_token.nil?
|
16
16
|
|
17
17
|
@growi_url = growi_url
|
18
18
|
@access_token = access_token
|
@@ -34,8 +34,8 @@ class GrowiClient
|
|
34
34
|
# @return [String] ページID
|
35
35
|
def page_id(path_exp: nil)
|
36
36
|
ret = request(GApiRequestPagesList.new path_exp: path_exp)
|
37
|
-
return nil if (ret.kind_of?
|
38
|
-
return ret.data.find { |page| URI.unescape(page.path) == path_exp }&.
|
37
|
+
return nil if (ret.kind_of? GCInvalidRequest || ret.data.nil?)
|
38
|
+
return ret.data.find { |page| URI.unescape(page.path) == path_exp }&._id
|
39
39
|
end
|
40
40
|
|
41
41
|
# ページが存在するか調べる
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
# Logger
|
5
|
+
class GCLogger
|
6
|
+
include Singleton
|
7
|
+
attr_reader :logger
|
8
|
+
|
9
|
+
# Constractor
|
10
|
+
def initialize(logdev = STDOUT, shift_age = 0, shift_size = 1048576, params = {})
|
11
|
+
init_params = { level: ENV['GC_LOG_LEVEL'] || Logger::Severity::ERROR }
|
12
|
+
@logger = Logger.new(logdev, init_params.merge(params).compact)
|
13
|
+
end
|
14
|
+
|
15
|
+
# instance of Logger
|
16
|
+
def self.logger
|
17
|
+
instance.logger
|
18
|
+
end
|
19
|
+
end
|
@@ -15,14 +15,13 @@ class GrowiAttachment < GrowiModelBase
|
|
15
15
|
}
|
16
16
|
|
17
17
|
params = init_params.merge(params.map { |k,v| [k.to_sym, v] }.to_h)
|
18
|
-
if (params[:_id]
|
19
|
-
raise ArgumentError.new('
|
18
|
+
if (params[:_id].nil?)
|
19
|
+
raise ArgumentError.new('Parameter _id is required.')
|
20
20
|
end
|
21
21
|
|
22
22
|
GrowiModelFactory.instance.register({
|
23
|
-
attachment_creator: Proc.new { |param| param
|
24
|
-
attachment_createdAt: Proc.new { |date_str|
|
25
|
-
date_str != nil && DateTime.parse(date_str) },
|
23
|
+
attachment_creator: Proc.new { |param| !param.nil? && param.is_a?(String) ? param : GrowiUser.new(param) },
|
24
|
+
attachment_createdAt: Proc.new { |date_str| !date_str.nil? && date_str != "" ? DateTime.parse(date_str) : "" },
|
26
25
|
})
|
27
26
|
maked_params = {}
|
28
27
|
params.each do |k,v|
|
@@ -15,7 +15,8 @@ class GrowiPage < GrowiModelBase
|
|
15
15
|
attr_reader :_id, :redirectTo, :updatedAt, :lastUpdateUser,
|
16
16
|
:creator, :path, :__v, :revision, :createdAt,
|
17
17
|
:commentCount, :seenUsers, :liker, :grantedUsers,
|
18
|
-
:grant, :status, :
|
18
|
+
:grant, :status, :extended,
|
19
|
+
:pageIdOnHackmd, :revisionHackmdSynced, :hasDraftOnHackmd
|
19
20
|
|
20
21
|
# Constract
|
21
22
|
# @param [Hash] params Prameters data show as Hash
|
@@ -25,21 +26,22 @@ class GrowiPage < GrowiModelBase
|
|
25
26
|
_id: '', redirectTo: nil, updatedAt: '', lastUpdateUser: '',
|
26
27
|
creator: nil, path: nil, __v: 0, revision: nil, createdAt: '',
|
27
28
|
commentCount: 0, seenUsers: [], liker: [], grantedUsers: [],
|
28
|
-
grant: 0, status: ''
|
29
|
+
grant: 0, status: ''
|
29
30
|
}
|
30
|
-
|
31
31
|
params = init_params.merge(params.map { |k,v| [k.to_sym, v] }.to_h)
|
32
|
-
if (params[:_id]
|
33
|
-
raise ArgumentError.new('
|
32
|
+
if (params[:_id].nil?)
|
33
|
+
raise ArgumentError.new('Parameter _id is required.')
|
34
34
|
end
|
35
35
|
|
36
36
|
# @note Parameters lastUpdateUser and creator have two patterns ID only or Object.
|
37
37
|
GrowiModelFactory.instance.register({
|
38
|
-
page_updatedAt: Proc.new { |str| str !=
|
39
|
-
page_lastUpdateUser: Proc.new { |param| param
|
40
|
-
page_creator: Proc.new { |param| param
|
41
|
-
page_createdAt: Proc.new { |str| str !=
|
42
|
-
|
38
|
+
page_updatedAt: Proc.new { |str| !str.nil? && str != "" ? DateTime.parse(str) : "" },
|
39
|
+
page_lastUpdateUser: Proc.new { |param| !param.nil? && param.is_a?(String) ? param : GrowiUser.new(param) },
|
40
|
+
page_creator: Proc.new { |param| !param.nil? && param.is_a?(String) ? param : GrowiUser.new(param) },
|
41
|
+
page_createdAt: Proc.new { |str| !str.nil? && str != "" ? DateTime.parse(str) : "" },
|
42
|
+
|
43
|
+
# revision が文字列のみ(IDだけの場合)であれば _id のみを格納し、ハッシュ化されていればすべて読み込む
|
44
|
+
page_revision: Proc.new { |param| !param.nil? && GrowiPageRevision.new(param.is_a?(String) ? { _id: param } : param) },
|
43
45
|
})
|
44
46
|
maked_params = {}
|
45
47
|
params.each do |k,v|
|
@@ -50,4 +52,3 @@ class GrowiPage < GrowiModelBase
|
|
50
52
|
end
|
51
53
|
|
52
54
|
end
|
53
|
-
|
@@ -14,13 +14,12 @@ class GrowiPageRevision < GrowiModelBase
|
|
14
14
|
}
|
15
15
|
|
16
16
|
params = init_params.merge(params.map { |k,v| [k.to_sym, v] }.to_h)
|
17
|
-
if (params[:_id]
|
18
|
-
raise ArgumentError.new('
|
17
|
+
if (params[:_id].nil?)
|
18
|
+
raise ArgumentError.new('Parameter _id is required.')
|
19
19
|
end
|
20
20
|
|
21
21
|
GrowiModelFactory.instance.register({
|
22
|
-
page_revision_createdAt: Proc.new { |date_str|
|
23
|
-
date_str != nil && DateTime.parse(date_str) },
|
22
|
+
page_revision_createdAt: Proc.new { |date_str| !date_str.nil? && date_str != "" ? DateTime.parse(date_str) : "" },
|
24
23
|
})
|
25
24
|
maked_params = {}
|
26
25
|
params.each do |k,v|
|
@@ -15,13 +15,12 @@ class GrowiUser < GrowiModelBase
|
|
15
15
|
}
|
16
16
|
|
17
17
|
params = init_params.merge(params.map { |k,v| [k.to_sym, v] }.to_h)
|
18
|
-
if (params[:_id]
|
19
|
-
raise ArgumentError.new('
|
18
|
+
if (params[:_id].nil?)
|
19
|
+
raise ArgumentError.new('Parameter _id is required.')
|
20
20
|
end
|
21
21
|
|
22
22
|
GrowiModelFactory.instance.register({
|
23
|
-
user_createdAt: Proc.new { |date_str|
|
24
|
-
date_str != nil && DateTime.parse(date_str) },
|
23
|
+
user_createdAt: Proc.new { |date_str| !date_str.nil? && date_str != "" ? DateTime.parse(date_str) : "" },
|
25
24
|
})
|
26
25
|
maked_params = {}
|
27
26
|
params.each do |k,v|
|
data/lib/growi/client/version.rb
CHANGED
data/wercker.yml
CHANGED
@@ -1,89 +1,89 @@
|
|
1
|
-
box: ruby:2.5.1
|
2
|
-
|
3
|
-
# Run weseek/growi, mongo, elasticsearch
|
4
|
-
services:
|
5
|
-
- name: mongo
|
6
|
-
id: mongo:3.4
|
7
|
-
|
8
|
-
build:
|
9
|
-
# Steps make up the actions in your pipeline
|
10
|
-
# Read more about steps on our dev center:
|
11
|
-
# http://devcenter.wercker.com/docs/steps/index.html
|
12
|
-
steps:
|
13
|
-
- bundle-install
|
14
|
-
|
15
|
-
- script:
|
16
|
-
name: "Install utility tools"
|
17
|
-
code: |
|
18
|
-
apt-get update
|
19
|
-
apt-get install -y netcat
|
20
|
-
|
21
|
-
- script:
|
22
|
-
name: "Wait for MongoDB connection"
|
23
|
-
code: |
|
24
|
-
echo Wait for connect to $MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT
|
25
|
-
while ! nc -q 1 $MONGO_PORT_27017_TCP_ADDR $MONGO_PORT_27017_TCP_PORT </dev/null; do
|
26
|
-
echo "...waiting 3s"; sleep 3;
|
27
|
-
done
|
28
|
-
|
29
|
-
- internal/docker-run:
|
30
|
-
image: weseek/growi:3.
|
31
|
-
name: growi
|
32
|
-
env: >
|
33
|
-
MONGO_URI=mongodb://$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/growi
|
34
|
-
PASSWORD_SEED=empty
|
35
|
-
FILE_UPLOAD=local
|
36
|
-
|
37
|
-
- script:
|
38
|
-
name: "Wait for GROWI connection"
|
39
|
-
code: |
|
40
|
-
echo Wait for connect to growi:3000
|
41
|
-
while ! nc -q 1 growi 3000 < /dev/null; do
|
42
|
-
echo "...waiting 3s"; sleep 3;
|
43
|
-
done
|
44
|
-
export GROWI_URL=http://growi:3000
|
45
|
-
|
46
|
-
- script:
|
47
|
-
name: "Create admin user"
|
48
|
-
code: |
|
49
|
-
export ADMIN_USER_NAME=admin1
|
50
|
-
export ADMIN_USER_PASS=admin1pass
|
51
|
-
LOGIN_COOKIE=login.cookie
|
52
|
-
OUTPUT_PAGE_NAME=installer.html
|
53
|
-
curl $GROWI_URL/installer -c ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
54
|
-
CSRF=`grep data-csrftoken ${OUTPUT_PAGE_NAME} | awk -F'=' '{ print $2 }' | sed -e s/\"//g`
|
55
|
-
curl $GROWI_URL/installer/createAdmin -b ${LOGIN_COOKIE} -X POST \
|
56
|
-
-d "registerForm[name]=${ADMIN_USER_NAME}®isterForm[username]=${ADMIN_USER_NAME}®isterForm[email]=${ADMIN_USER_NAME}@localhost®isterForm[password]=${ADMIN_USER_PASS}&_csrf=${CSRF}"
|
57
|
-
|
58
|
-
- script:
|
59
|
-
name: "Login as admin1"
|
60
|
-
code: |
|
61
|
-
OUTPUT_PAGE_NAME=login.html
|
62
|
-
curl $GROWI_URL/login -c ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
63
|
-
CSRF=`grep data-csrftoken ${OUTPUT_PAGE_NAME} | awk -F'=' '{ print $2 }' | sed -e s/\"//g`
|
64
|
-
curl $GROWI_URL/login -b ${LOGIN_COOKIE} -X POST -d "loginForm[username]=${ADMIN_USER_NAME}&loginForm[password]=${ADMIN_USER_PASS}&_csrf=${CSRF}"
|
65
|
-
|
66
|
-
- script:
|
67
|
-
name: "Generate API token"
|
68
|
-
code: |
|
69
|
-
OUTPUT_PAGE_NAME=apiToken.html
|
70
|
-
curl $GROWI_URL/me/apiToken -b ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
71
|
-
CSRF=`grep data-csrftoken ${OUTPUT_PAGE_NAME} | awk -F'=' '{ print $2 }' | sed -e s/\"//g`
|
72
|
-
curl $GROWI_URL/me/apiToken -b ${LOGIN_COOKIE} -X POST -d "apiTokenForm[confirm]=1&_csrf=${CSRF}"
|
73
|
-
curl $GROWI_URL/me/apiToken -b ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
74
|
-
export APITOKEN=`grep -A 10 'Current API Token' ${OUTPUT_PAGE_NAME} | grep '<input' | awk -F'value=' '{ print $2 }' | awk -F'"' '{ print $2 }'`
|
75
|
-
|
76
|
-
- script:
|
77
|
-
name: "Export environment variables"
|
78
|
-
code: |
|
79
|
-
export GROWI_URL=$GROWI_URL
|
80
|
-
export GROWI_ACCESS_TOKEN=$APITOKEN
|
81
|
-
|
82
|
-
- script:
|
83
|
-
name: "View environment variables"
|
84
|
-
code: |
|
85
|
-
env
|
86
|
-
|
87
|
-
- script:
|
88
|
-
name: rspec
|
89
|
-
code: bundle exec rspec
|
1
|
+
box: ruby:2.5.1
|
2
|
+
|
3
|
+
# Run weseek/growi, mongo, elasticsearch
|
4
|
+
services:
|
5
|
+
- name: mongo
|
6
|
+
id: mongo:3.4
|
7
|
+
|
8
|
+
build:
|
9
|
+
# Steps make up the actions in your pipeline
|
10
|
+
# Read more about steps on our dev center:
|
11
|
+
# http://devcenter.wercker.com/docs/steps/index.html
|
12
|
+
steps:
|
13
|
+
- bundle-install
|
14
|
+
|
15
|
+
- script:
|
16
|
+
name: "Install utility tools"
|
17
|
+
code: |
|
18
|
+
apt-get update
|
19
|
+
apt-get install -y netcat
|
20
|
+
|
21
|
+
- script:
|
22
|
+
name: "Wait for MongoDB connection"
|
23
|
+
code: |
|
24
|
+
echo Wait for connect to $MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT
|
25
|
+
while ! nc -q 1 $MONGO_PORT_27017_TCP_ADDR $MONGO_PORT_27017_TCP_PORT </dev/null; do
|
26
|
+
echo "...waiting 3s"; sleep 3;
|
27
|
+
done
|
28
|
+
|
29
|
+
- internal/docker-run:
|
30
|
+
image: weseek/growi:3.3.3
|
31
|
+
name: growi
|
32
|
+
env: >
|
33
|
+
MONGO_URI=mongodb://$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/growi
|
34
|
+
PASSWORD_SEED=empty
|
35
|
+
FILE_UPLOAD=local
|
36
|
+
|
37
|
+
- script:
|
38
|
+
name: "Wait for GROWI connection"
|
39
|
+
code: |
|
40
|
+
echo Wait for connect to growi:3000
|
41
|
+
while ! nc -q 1 growi 3000 < /dev/null; do
|
42
|
+
echo "...waiting 3s"; sleep 3;
|
43
|
+
done
|
44
|
+
export GROWI_URL=http://growi:3000
|
45
|
+
|
46
|
+
- script:
|
47
|
+
name: "Create admin user"
|
48
|
+
code: |
|
49
|
+
export ADMIN_USER_NAME=admin1
|
50
|
+
export ADMIN_USER_PASS=admin1pass
|
51
|
+
LOGIN_COOKIE=login.cookie
|
52
|
+
OUTPUT_PAGE_NAME=installer.html
|
53
|
+
curl $GROWI_URL/installer -c ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
54
|
+
CSRF=`grep data-csrftoken ${OUTPUT_PAGE_NAME} | awk -F'=' '{ print $2 }' | sed -e s/\"//g`
|
55
|
+
curl $GROWI_URL/installer/createAdmin -b ${LOGIN_COOKIE} -X POST \
|
56
|
+
-d "registerForm[name]=${ADMIN_USER_NAME}®isterForm[username]=${ADMIN_USER_NAME}®isterForm[email]=${ADMIN_USER_NAME}@localhost®isterForm[password]=${ADMIN_USER_PASS}&_csrf=${CSRF}"
|
57
|
+
|
58
|
+
- script:
|
59
|
+
name: "Login as admin1"
|
60
|
+
code: |
|
61
|
+
OUTPUT_PAGE_NAME=login.html
|
62
|
+
curl $GROWI_URL/login -c ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
63
|
+
CSRF=`grep data-csrftoken ${OUTPUT_PAGE_NAME} | awk -F'=' '{ print $2 }' | sed -e s/\"//g`
|
64
|
+
curl $GROWI_URL/login -b ${LOGIN_COOKIE} -X POST -d "loginForm[username]=${ADMIN_USER_NAME}&loginForm[password]=${ADMIN_USER_PASS}&_csrf=${CSRF}"
|
65
|
+
|
66
|
+
- script:
|
67
|
+
name: "Generate API token"
|
68
|
+
code: |
|
69
|
+
OUTPUT_PAGE_NAME=apiToken.html
|
70
|
+
curl $GROWI_URL/me/apiToken -b ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
71
|
+
CSRF=`grep data-csrftoken ${OUTPUT_PAGE_NAME} | awk -F'=' '{ print $2 }' | sed -e s/\"//g`
|
72
|
+
curl $GROWI_URL/me/apiToken -b ${LOGIN_COOKIE} -X POST -d "apiTokenForm[confirm]=1&_csrf=${CSRF}"
|
73
|
+
curl $GROWI_URL/me/apiToken -b ${LOGIN_COOKIE} -o ${OUTPUT_PAGE_NAME}
|
74
|
+
export APITOKEN=`grep -A 10 'Current API Token' ${OUTPUT_PAGE_NAME} | grep '<input' | awk -F'value=' '{ print $2 }' | awk -F'"' '{ print $2 }'`
|
75
|
+
|
76
|
+
- script:
|
77
|
+
name: "Export environment variables"
|
78
|
+
code: |
|
79
|
+
export GROWI_URL=$GROWI_URL
|
80
|
+
export GROWI_ACCESS_TOKEN=$APITOKEN
|
81
|
+
|
82
|
+
- script:
|
83
|
+
name: "View environment variables"
|
84
|
+
code: |
|
85
|
+
env
|
86
|
+
|
87
|
+
- script:
|
88
|
+
name: rspec
|
89
|
+
code: bundle exec rspec
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: growi-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryu Sato
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/growi/client/apireq/api_request_base.rb
|
119
119
|
- lib/growi/client/apireq/api_request_pages.rb
|
120
120
|
- lib/growi/client/client.rb
|
121
|
+
- lib/growi/client/logger.rb
|
121
122
|
- lib/growi/client/model/growi_attachment.rb
|
122
123
|
- lib/growi/client/model/growi_model.rb
|
123
124
|
- lib/growi/client/model/growi_model_base.rb
|